protected void SendConfrimMessage() { var appointmentInfo = new BookAppointmentInfo(); if (Session["OrderID"] != null) { int storeID = GetStoreID; int portalID = GetPortalID; string userName = GetUsername; int customerID = GetCustomerID; var orderdata = new OrderDetailsCollection(); if (HttpContext.Current.Session["OrderCollection"] != null) { orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; } string invoice = orderdata.ObjOrderDetails.InvoiceNumber; lblInvoice.Text = invoice; var random = new Random(); string transID = (random.Next(99999, 111111)).ToString(); lblTransaction.Text = transID.Trim(); if (Session["PaymentMethodName"] != null) { if (HttpContext.Current.Session["PaymentMethodName"].ToString() == "paypal") { var pw = new PayPalWCFService(); int j = orderdata.ObjOrderDetails.PaymentGatewayTypeID; List <PayPalSettingInfo> setting = pw.GetAllPayPalSetting(j, storeID, portalID); _authToken = setting[0].AuthToken; _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"; const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; const string strLive = "https://www.paypal.com/cgi-bin/webscr"; string test = string.Empty; if (Session["IsTestPayPal"] != null) { test = bool.Parse(Session["IsTestPayPal"].ToString()) ? strSandbox : strLive; } var 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 var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(_query); stOut.Close(); // Do the request to PayPal and get the response var 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; //for localhost // PayPalHandler pdt = PayPalHandler.Parse(strResponse, storeID, portalID, userName, customerID, sessionCode); //for live site try { PayPalHandler pdtt = ParseAfterIPN(_strResponse, storeID, portalID, userName, customerID, sessionCode, TemplateName, _addressPath); } catch (Exception) { lblerror.Text = GetSageMessage("Payment", "PaymentParsingIPNError"); } String[] stringArray = _strResponse.Split('\n'); int i; string status = string.Empty; for (i = 1; i < stringArray.Length - 1; i++) { String[] stringArray1 = stringArray[i].Split('='); String sKey = stringArray1[0]; String 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.Trim(); lblInvoice.Text = _invoice; lblPaymentMethod.Text = "Paypal"; if (status.ToLower().Trim() == "completed") { lblerror.Text = GetSageMessage("Payment", "PaymentProcessed"); } else if (status.ToLower().Trim() == "pending") { lblerror.Text = GetSageMessage("Payment", "PaymentPending"); } } else { lblerror.Text = GetSageMessage("Payment", "PaymentError"); } } else if (HttpContext.Current.Session["PaymentMethodName"].ToString().ToLower() == "cashondelivery") { const int responseCode = 1; // response code, defaulted to Invalid const string responsereasontext = "Transaction occured successfully"; const int responsereasonCode = 1; string purchaseorderNo = (random.Next(0, 1000)).ToString(); // string userName = GetUsername; // int customerID = GetCustomerID; string sessionCode = HttpContext.Current.Session.SessionID; string result = Parse(transID, invoice, purchaseorderNo, responseCode, responsereasonCode, responsereasontext, storeID, portalID, userName, customerID, sessionCode); lblerror.Text = result; lblerror.Text = GetSageMessage("Payment", "PaymentProcessed"); var tinfo = new TransactionLogInfo(); var tlog = new TransactionLog(); } } else { Response.Redirect(_sageRedirectPath, false); } if (HttpContext.Current.Session["AppointmentCollection"] != null) { appointmentInfo = (BookAppointmentInfo)HttpContext.Current.Session["AppointmentCollection"]; } lblServiceName.Text = appointmentInfo.ServiceCategoryName.Trim(); lblServiceProduct.Text = appointmentInfo.ServiceProductName; lblServiceDuration.Text = appointmentInfo.ServiceDuration; lblStoreLocation.Text = appointmentInfo.StoreLocationName; lblServiceProviderName.Text = appointmentInfo.EmployeeName; lblProductPrice.Text = appointmentInfo.ServiceProductPrice.Trim(); lblPaymentMethod.Text = appointmentInfo.PaymentMethodName; lblDate.Text = appointmentInfo.PreferredDate.ToString("MM/dd/yyyy"); lblTime.Text = appointmentInfo.PreferredTimeInterval.Trim(); } }
public void LoadSetting() { var pw = new PayPalWCFService(); var orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; try { List <PayPalSettingInfo> sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID, portalID); string postUrl; if (bool.Parse(sf[0].IsTestPaypal)) { postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr"; HttpContext.Current.Session["IsTestPayPal"] = true; } else { postUrl = "https://www.paypal.com/us/cgi-bin/webscr"; HttpContext.Current.Session["IsTestPayPal"] = false; } string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + UserName + "#" + customerID + "#" + SessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" + Session["GateWay"].ToString(); var url = new StringBuilder(); url.Append(postUrl + "?cmd=_cart&business=" + HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim())); string serviceType = string.Empty; if (Session["ServiceType"] != null) { serviceType = Session["ServiceType"].ToString(); } if (serviceType.ToLower() == "true") { var appointmentInfo = new BookAppointmentInfo(); if (HttpContext.Current.Session["AppointmentCollection"] != null) { appointmentInfo = (BookAppointmentInfo)HttpContext.Current.Session["AppointmentCollection"]; } int nCount = 1; double itemPrice = Convert.ToDouble(appointmentInfo.ServiceProductPrice) * Rate; url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(appointmentInfo.ServiceProductName)); url.AppendFormat("&amount_" + nCount + "={0}", HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString())); // url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString())); double discountAll = 0.00; double couponDiscount = 0.00; double taxAll = 0.00; double shippingCostAll = 0.00; url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString())); url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString())); url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString())); url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString())); url.AppendFormat("¤cy_code={0}", HttpUtility.UrlEncode(MainCurrency)); if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "") { // url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString())); //var successPage = sf[0].ReturnUrl.Split('/'); var serviceSuccessPage = "Appointment-Success.aspx"; var successPageURL = sf[0].ReturnUrl.Substring(0, sf[0].ReturnUrl.LastIndexOf("/")) + "/" + serviceSuccessPage; url.AppendFormat("&return={0}", HttpUtility.UrlEncode(successPageURL.ToString())); } if (!string.IsNullOrEmpty(sf[0].VerificationUrl)) { url.AppendFormat("¬ify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl)); } if (!string.IsNullOrEmpty(sf[0].CancelUrl)) { url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl)); } url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids)); Response.Redirect(url.ToString(), false); } else { List <CartInfoforPaypal> cd = pw.GetCartDetails(storeID, portalID, customerID, UserName, GetCurrentCultureName, SessionCode); int nCount = 1; foreach (CartInfoforPaypal oItem in cd) { double itemPrice = Convert.ToDouble(oItem.Price) * Rate; url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.ItemName)); url.AppendFormat("&amount_" + nCount + "={0}", HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString())); url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString())); nCount++; } nCount--; double discountAll = Convert.ToDouble(Session["DiscountAll"].ToString()) * Rate; double couponDiscount = (double)orderdata2.ObjOrderDetails.CouponDiscountAmount * Rate; double taxAll = Convert.ToDouble(Session["TaxAll"].ToString()) * Rate; double shippingCostAll = Convert.ToDouble(Session["ShippingCostAll"].ToString()) * Rate; url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString())); url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString())); url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString())); url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString())); url.AppendFormat("¤cy_code={0}", HttpUtility.UrlEncode(MainCurrency)); if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "") { url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString())); } if (!string.IsNullOrEmpty(sf[0].VerificationUrl)) { url.AppendFormat("¬ify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl)); } if (!string.IsNullOrEmpty(sf[0].CancelUrl)) { url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl)); } url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1")); url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids)); Response.Redirect(url.ToString(), false); } } catch (Exception ex) { lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout"; clickhere.Visible = false; ProcessException(ex); } }