protected void SendConfrimMessage() { try { if (Session["OrderID"] != null) { string transID = string.Empty; // transaction ID from Relay Response int responseCode = 1; // response code, defaulted to Invalid string responsereasontext = string.Empty; responsereasontext = "Transaction occured Successfully"; int responsereasonCode = 1; string purchaseorderNo = string.Empty; string invoice = string.Empty; string paymentmethod = string.Empty; OrderDetailsCollection orderdata2 = new OrderDetailsCollection(); if (HttpContext.Current.Session["OrderCollection"] != null) { orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; } invoice = orderdata2.ObjOrderDetails.InvoiceNumber.ToString(); Random random = new Random(); purchaseorderNo = (random.Next(0, 1000)).ToString(); string timeStamp = ((int)(DateTime.UtcNow - new DateTime(2011, 1, 1)).TotalSeconds).ToString(); transID = (random.Next(99999, 111111)).ToString(); lblTransaction.Text = transID; lblInvoice.Text = invoice; lblPaymentMethod.Text = "Cash On Delivery"; lblDateTime.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy "); int storeID = int.Parse(GetStoreID.ToString()); int portalID = int.Parse(GetPortalID.ToString()); string userName = GetUsername.ToString(); int customerID = int.Parse(GetCustomerID.ToString()); string sessionCode = HttpContext.Current.Session.SessionID.ToString(); string result = CashOnDelivery.Parse(transID, invoice, purchaseorderNo, responseCode, responsereasonCode, responsereasontext, storeID, portalID, userName, customerID, sessionCode); lblerror.Text = result.ToString(); lblerror.Text = GetSageMessage("Payment", "PaymentProcessed"); TransactionLogInfo tinfo = new TransactionLogInfo(); TransactionLog Tlog = new TransactionLog(); tinfo.TransactionID = transID; tinfo.AuthCode = ""; tinfo.TotalAmount = decimal.Parse(orderdata2.ObjOrderDetails.GrandTotal.ToString()); tinfo.ResponseCode = responseCode.ToString(); tinfo.ResponseReasonText = responsereasontext; tinfo.OrderID = orderdata2.ObjOrderDetails.OrderID; tinfo.StoreID = orderdata2.ObjCommonInfo.StoreID; tinfo.PortalID = orderdata2.ObjCommonInfo.PortalID; tinfo.AddedBy = orderdata2.ObjCommonInfo.AddedBy; tinfo.CustomerID = orderdata2.ObjOrderDetails.CustomerID; tinfo.SessionCode = orderdata2.ObjOrderDetails.SessionCode; tinfo.PaymentGatewayID = orderdata2.ObjOrderDetails.PaymentGatewayTypeID; tinfo.PaymentStatus = "Processed"; tinfo.CreditCard = ""; Tlog.SaveTransactionLog(tinfo); AspxCommerceWebService clSes = new AspxCommerceWebService(); if (Session["IsFreeShipping"] != null) { HttpContext.Current.Session.Remove("IsFreeShipping"); } if (Session["DiscountAmount"] != null) { HttpContext.Current.Session.Remove("DiscountAmount"); } if (Session["CouponCode"] != null) { HttpContext.Current.Session.Remove("CouponCode"); } if (Session["CouponApplied"] != null) { HttpContext.Current.Session.Remove("CouponApplied"); } if (Session["DiscountAll"] != null) { HttpContext.Current.Session.Remove("DiscountAll"); } if (Session["TaxAll"] != null) { HttpContext.Current.Session.Remove("TaxAll"); } if (Session["ShippingCostAll"] != null) { HttpContext.Current.Session.Remove("ShippingCostAll"); } if (Session["GrandTotalAll"] != null) { HttpContext.Current.Session.Remove("GrandTotalAll"); } if (Session["Gateway"] != null) { HttpContext.Current.Session.Remove("Gateway"); } //invoice transID if (Session["OrderCollection"] != null) { OrderDetailsCollection orderdata = new OrderDetailsCollection(); orderdata = (OrderDetailsCollection)Session["OrderCollection"]; try { EmailTemplate.SendEmailForOrder(GetPortalID, orderdata, addressPath, TemplateName, transID); } catch { lblerror.Text = ""; lblerror.Text = GetSageMessage("Payment", "EmailSendOrderProblem"); } clSes.ClearSessionVariable("OrderCollection"); } } else { Response.Redirect(sageRedirectPath, false); } } catch (Exception ex) { ProcessException(ex); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { SageFrameConfig sfConfig = new SageFrameConfig(); IsUseFriendlyUrls = sfConfig.GetSettingBollByKey(SageFrameSettingKeys.UseFriendlyUrls); string sageRedirectPath = string.Empty; if (IsUseFriendlyUrls) { if (GetPortalID > 1) { sageRedirectPath = ResolveUrl("~/portal/" + GetPortalSEOName + "/" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx"); addressPath = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/portal/" + GetPortalSEOName + "/"; } else { sageRedirectPath = ResolveUrl("~/" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx"); addressPath = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/"; } } else { sageRedirectPath = ResolveUrl("{~/Default.aspx?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage)); } Image imgProgress = (Image)UpdateProgress1.FindControl("imgPrgress"); if (imgProgress != null) { imgProgress.ImageUrl = GetTemplateImageUrl("ajax-loader.gif", true); } hlnkHomePage.NavigateUrl = sageRedirectPath; OrderDetailsCollection orderdata = new OrderDetailsCollection(); AspxCommonInfo aspxCommonObj = new AspxCommonInfo(); aspxCommonObj.CustomerID = GetCustomerID; aspxCommonObj.SessionCode = HttpContext.Current.Session.SessionID; aspxCommonObj.StoreID = GetStoreID; aspxCommonObj.PortalID = GetPortalID; aspxCommonObj.CultureName = GetCurrentCultureName; aspxCommonObj.UserName = GetUsername; if (Session["OrderID"] != null) { orderID = int.Parse(Session["OrderID"].ToString()); int storeID = int.Parse(GetStoreID.ToString()); int portalID = int.Parse(GetPortalID.ToString()); string userName = GetUsername.ToString(); int customerID = int.Parse(GetCustomerID.ToString()); transID = GetTransactionDetailById(int.Parse(Session["OrderID"].ToString())); if (HttpContext.Current.Session["OrderCollection"] != null) { orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; AspxGiftCardController.IssueGiftCard(orderdata.LstOrderItemsInfo, false, aspxCommonObj); if (orderdata.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null) { //updating giftcard used in chekout AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID, orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy, orderdata.ObjCommonInfo.CultureName); HttpContext.Current.Session.Remove("UsedGiftCard"); } invoice = orderdata.ObjOrderDetails.InvoiceNumber; orderdata.ObjOrderDetails.OrderStatus = "Successful"; EmailTemplate.SendEmailForOrder(portalID, orderdata, addressPath, TemplateName, transID); } lblTransaction.Text = transID; lblPaymentMethod.Text = "GoogleCheckOut"; lblDateTime.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy "); lblInvoice.Text = invoice; ClearAllSession(); } else { Response.Redirect(sageRedirectPath, false); } IncludeLanguageJS(); } catch (Exception ex) { ProcessException(ex); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { SageFrameConfig sfConfig = new SageFrameConfig(); IsUseFriendlyUrls = sfConfig.GetSettingBollByKey(SageFrameSettingKeys.UseFriendlyUrls); string sageRedirectPath = string.Empty; if (IsUseFriendlyUrls) { if (GetPortalID > 1) { sageRedirectPath = ResolveUrl("~/portal/" + GetPortalSEOName + "/" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx"); addressPath = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/portal/" + GetPortalSEOName + "/"; } else { sageRedirectPath = ResolveUrl("~/" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx"); addressPath = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/"; } } else { sageRedirectPath = ResolveUrl("{~/Default.aspx?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage)); } Image imgProgress = (Image)UpdateProgress1.FindControl("imgPrgress"); if (imgProgress != null) { imgProgress.ImageUrl = GetTemplateImageUrl("ajax-loader.gif", true); } hlnkHomePage.NavigateUrl = sageRedirectPath; if (Session["OrderID"] != null) { int storeID = int.Parse(GetStoreID.ToString()); int portalID = int.Parse(GetPortalID.ToString()); string userName = GetUsername.ToString(); int customerID = int.Parse(GetCustomerID.ToString()); OrderDetailsCollection orderdata = new OrderDetailsCollection(); List <PayPalSettingInfo> setting; if (HttpContext.Current.Session["OrderCollection"] != null) { orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; invoice = orderdata.ObjOrderDetails.InvoiceNumber.ToString(); PayPalWCFService pw = new PayPalWCFService(); int i = int.Parse(orderdata.ObjOrderDetails.PaymentGatewayTypeID.ToString()); setting = pw.GetAllPayPalSetting(i, storeID, portalID); authToken = setting[0].AuthToken.ToString(); } // authToken = "QMtOC54_YHYUkoggkMZ81ivNWSxPXduIqS5oMynafeUGRL1Rv5OTtUd4rvq"; //read in txn token from querystring txToken = Request.QueryString.Get("tx"); query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken); // Create the request back // string url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; string strLive = "https://www.paypal.com/cgi-bin/webscr"; string test = string.Empty; if (Session["IsTestPayPal"] != null) { if (bool.Parse(Session["IsTestPayPal"].ToString())) { test = strSandbox; } else { test = strLive; } } HttpWebRequest req = (HttpWebRequest)WebRequest.Create(test); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = query.Length; // Write the request back IPN strings StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(query); stOut.Close(); // Do the request to PayPal and get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); // If response was SUCCESS, parse response string and output details if (strResponse.StartsWith("SUCCESS")) { string sessionCode = HttpContext.Current.Session.SessionID.ToString(); //for localhost // PayPalHandler pdt = PayPalHandler.Parse(strResponse, storeID, portalID, userName, customerID, sessionCode); //for live site try { PayPalHandler pdtt = PayPalHandler.ParseAfterIPN(strResponse, storeID, portalID, userName, customerID, sessionCode, TemplateName, addressPath); } catch (Exception) { lblerror.Text = GetSageMessage("Payment", "PaymentParsingIPNError"); } AspxCommerceWebService clSes = new AspxCommerceWebService(); String sKey, sValue; String[] StringArray = strResponse.Split('\n'); int i; string status = string.Empty; for (i = 1; i < StringArray.Length - 1; i++) { String[] StringArray1 = StringArray[i].Split('='); sKey = StringArray1[0]; sValue = HttpUtility.UrlDecode(StringArray1[1]); // set string vars to hold variable names using a switch switch (sKey) { case "txn_id": transID = Convert.ToString(sValue); break; case "payment_status": status = Convert.ToString(sValue); break; } } lblTransaction.Text = transID; lblInvoice.Text = invoice; lblPaymentMethod.Text = "Paypal"; lblDateTime.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy "); if (status.ToLower().Trim() == "completed") { lblerror.Text = GetSageMessage("Payment", "PaymentProcessed"); } else if (status.ToLower().Trim() == "pending") { lblerror.Text = GetSageMessage("Payment", "PaymentPending"); } if (Session["IsFreeShipping"] != null) { clSes.ClearSessionVariable("IsFreeShipping"); } if (Session["DiscountAmount"] != null) { clSes.ClearSessionVariable("DiscountAmount"); } if (Session["CouponCode"] != null) { clSes.ClearSessionVariable("CouponCode"); } if (Session["CouponApplied"] != null) { HttpContext.Current.Session.Remove("CouponApplied"); } Session.Remove("IsTestPayPal"); if (Session["DiscountAll"] != null) { HttpContext.Current.Session.Remove("DiscountAll"); } if (Session["TaxAll"] != null) { HttpContext.Current.Session.Remove("TaxAll"); } if (Session["ShippingCostAll"] != null) { HttpContext.Current.Session.Remove("ShippingCostAll"); } if (Session["GrandTotalAll"] != null) { HttpContext.Current.Session.Remove("GrandTotalAll"); } if (Session["Gateway"] != null) { HttpContext.Current.Session.Remove("Gateway"); } } else { lblerror.Text = GetSageMessage("Payment", "PaymentError"); } } else { Response.Redirect(sageRedirectPath, false); } } catch (Exception ex) { ProcessException(ex); } } }