コード例 #1
0
        public void ParseIPN(int orderId, string transId, string status, int storeId, int portalId, string userName, int customerId, string sessionCode)
        {
            var ph = new PayPalHandler();
            try
            {

                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo {StoreID = storeId, PortalID = portalId, AddedBy = userName};
                // UpdateOrderDetails
            
                var sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                // WcfSession ws = new WcfSession();
                odinfo.OrderID = orderId;//ws.GetSessionVariable("OrderID");
                odinfo.ResponseReasonText = status;
                odinfo.TransactionID = transId;
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                AspxOrderController.UpdateOrderDetails(ot);

               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        BodyArchitect.Logger.Log.Write("PayPalOrderProcessing started", TraceEventType.Information, "PayPal");
        var           session = NHibernateFactory.OpenSession();
        PayPalHandler payPal  = new PayPalHandler(InternalBodyArchitectService.PaymentsManager);

        try
        {
            payPal.ProcessOrderRequest(session, Request.Form, Request);
        }
        catch (Exception ex)
        {
            ExceptionHandler.Default.Process(ex);
        }
    }
コード例 #3
0
    private void MobileSuccess(string sageRedirectPath)
    {
        try
        {
            if (Session["mb_OrderDetail"] != null)
            {
                var    orderInfo       = (OrderInfo)Session["mb_OrderDetail"];
                var    giftCardUsage   = (List <GiftCardUsage>)Session["mb_GiftCardUsage"];
                var    coupons         = (List <CouponSession>)Session["mb_CouponSession"];
                var    billingAddress  = (UserAddressInfo)Session["mb_BillingAddress"];
                var    shippingAddress = (UserAddressInfo)Session["mb_ShippingAddress"];
                var    itemsInfo       = (List <OrderItem>)Session["mb_ItemDetails"];
                int    storeId         = orderInfo.StoreId;
                int    portalId        = orderInfo.PortalId;
                string userName        = orderInfo.AddedBy;
                int    customerId      = orderInfo.CustomerId;
                bool   isTestPaypal    = false;



                _invoice = orderInfo.InvoiceNumber;
                if (!string.IsNullOrEmpty(orderInfo.TransactionId) && orderInfo.TransactionId.Trim() != "0")
                {
                    lblTransaction.Text   = orderInfo.TransactionId;
                    lblInvoice.Text       = orderInfo.InvoiceNumber;
                    lblPaymentMethod.Text = orderInfo.PaymentMethodName;
                    lblDateTime.Text      = orderInfo.AddedOn.ToString("dddd, dd MMMM yyyy ");
                    lblOrderNo.Text       = "#" + orderInfo.OrderId;
                }
                else
                {
                    var pw = new PayPalWCFService();
                    List <PayPalSettingInfo> setting = pw.GetAllPayPalSetting(orderInfo.PaymentGatewayTypeId, storeId,
                                                                              portalId);
                    _authToken   = setting[0].AuthToken;
                    isTestPaypal = bool.Parse(setting[0].IsTestPaypal);

                    if (giftCardUsage != null && giftCardUsage.Count > 0)
                    {
                        AspxGiftCardController.UpdateGiftCardUsage(giftCardUsage, storeId,
                                                                   portalId,
                                                                   orderInfo.OrderId,
                                                                   userName,
                                                                   orderInfo.CultureName);
                    }



                    _txToken = Request.QueryString.Get("tx");
                    _query   = string.Format("cmd=_notify-synch&tx={0}&at={1}", _txToken, _authToken);
                    const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                    const string strLive    = "https://www.paypal.com/cgi-bin/webscr";
                    string       test;
                    if (Session["IsTestPayPal"] != null)
                    {
                        test = bool.Parse(Session["IsTestPayPal"].ToString()) ? strSandbox : strLive;
                    }
                    else
                    {
                        test = isTestPaypal ? strSandbox : strLive;
                    }
                    var req = (HttpWebRequest)WebRequest.Create(test);

                    req.Method        = "POST";
                    req.ContentType   = "application/x-www-form-urlencoded";
                    req.ContentLength = _query.Length;

                    var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                    stOut.Write(_query);
                    stOut.Close();

                    var stIn = new StreamReader(req.GetResponse().GetResponseStream());
                    _strResponse = stIn.ReadToEnd();
                    stIn.Close();

                    if (_strResponse.StartsWith("SUCCESS"))
                    {
                        string sessionCode = orderInfo.SessionCode;
                        try
                        {
                            var paypalHandler = new PayPalHandler();

                            paypalHandler.ParseAfterIPNMobile(orderInfo, coupons, itemsInfo, _strResponse,
                                                              billingAddress,
                                                              shippingAddress,
                                                              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]);

                            switch (sKey)
                            {
                            case "txn_id":
                                _transID = Convert.ToString(sValue);
                                break;

                            case "payment_status":
                                status = Convert.ToString(sValue);
                                break;
                            }
                        }
                        lblOrderNo.Text       = "#" + orderInfo.OrderId;
                        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");
                        }
                        Session.Clear();
                    }
                }
                Session.Clear();
            }
            else
            {
                Response.Redirect(sageRedirectPath);
            }
        }
        catch (Exception ex)
        {
            ProcessException(ex);
        }
    }
コード例 #4
0
    private void WebSuccess(string sageRedirectPath)
    {
        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"];
                _invoice  = orderdata.ObjOrderDetails.InvoiceNumber;
                var pw = new PayPalWCFService();
                int i  = orderdata.ObjOrderDetails.PaymentGatewayTypeID;
                List <PayPalSettingInfo> setting = pw.GetAllPayPalSetting(i, storeID, portalID);
                _authToken = setting[0].AuthToken;
                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");
                }
            }


            // 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";
            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
                {
                    var paypalHandler = new PayPalHandler();
                    var aspxCommonObj = new AspxCommonInfo();
                    aspxCommonObj.StoreID     = storeID;
                    aspxCommonObj.PortalID    = portalID;
                    aspxCommonObj.UserName    = userName;
                    aspxCommonObj.CustomerID  = customerID;
                    aspxCommonObj.SessionCode = sessionCode;
                    paypalHandler.ParseAfterIPN(_strResponse, aspxCommonObj, TemplateName, _addressPath);

                    AspxGiftCardController.IssueGiftCard(orderdata.LstOrderItemsInfo, false, aspxCommonObj);
                    if (orderdata.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null)
                    {
                        AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID,
                                                                   orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy,
                                                                   orderdata.ObjCommonInfo.CultureName);
                        HttpContext.Current.Session.Remove("UsedGiftCard");
                    }
                }
                catch (Exception)
                {
                    lblerror.Text = GetSageMessage("Payment", "PaymentParsingIPNError");
                }
                var clSes = new AspxCommerceWebService();

                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;
                    }
                }
                lblOrderNo.Text       = "#" + Session["OrderID"].ToString();
                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)
                {
                    HttpContext.Current.Session.Remove("IsFreeShipping");
                }
                if (Session["OrderID"] != null)
                {
                    HttpContext.Current.Session.Remove("OrderID");
                }
                if (Session["DiscountAmount"] != null)
                {
                    HttpContext.Current.Session.Remove("DiscountAmount");
                }
                if (Session["IsCouponInPercent"] != null)
                {
                    HttpContext.Current.Session.Remove("IsCouponInPercent");
                }
                if (Session["CouponPercentValue"] != null)
                {
                    HttpContext.Current.Session.Remove("CouponPercentValue");
                }
                if (Session["CouponSessionPercentAmount"] != null)
                {
                    HttpContext.Current.Session.Remove("CouponSessionPercentAmount");
                }
                if (Session["CouponSessionAmount"] != null)
                {
                    HttpContext.Current.Session.Remove("CouponSessionAmount");
                }
                if (Session["CouponCode"] != null)
                {
                    HttpContext.Current.Session.Remove("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);
        }
    }
コード例 #5
0
        public void ParseAfterIPN(string postData, AspxCommonInfo aspxCommonObj, string templateName, string addressPath)
        {
            var ph = new PayPalHandler();
            string transId = string.Empty;
            string orderStatus = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] stringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */
                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo {StoreID = aspxCommonObj.StoreID, PortalID = aspxCommonObj.PortalID, AddedBy = aspxCommonObj.UserName};
                // UpdateOrderDetails
            
                var sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
             
                int i;
                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 "payment_status":
                            odinfo.ResponseReasonText = Convert.ToString(sValue);
                            orderStatus = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            odinfo.TransactionID = Convert.ToString(sValue);
                            transId = Convert.ToString(sValue);
                            break;

                    }
                }
             
                ot.ObjCommonInfo = cf;
                //odinfo.OrderStatusID = 8;
                //objad.UpdateOrderDetails(ot);
                if (odinfo.ResponseReasonText.ToLower().Trim() == "completed")
                {
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                        var orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        AspxOrderController.UpdateItemQuantity(orderdata2);
                    }
                }
                cms.ClearCartAfterPayment(aspxCommonObj);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    var orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    orderdata.ObjOrderDetails.OrderStatus = orderStatus;
                    EmailTemplate.SendEmailForOrder(aspxCommonObj.PortalID, orderdata, addressPath, templateName, transId);
                }
                HttpContext.Current.Session.Remove("OrderCollection");
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
        public ActionResult BookTickets(TicketViewModel model)
        {
            ViewBag.Title = "Book Tickets";
            PopulateUIEventsView();

            int eventId = -1;

            if (!int.TryParse(model.EventName, out eventId) || model.NumberOfTickets < 1 || model.Price <= (decimal)0.0 || model.TotalPrice <= (decimal)0.00)
            {
                ModelState.AddModelError("transactionVoid", "Price, Number of tickets required");
            }
            try
            {
                if (ModelState.IsValid)
                {
                    eventId = -1;
                    if (int.TryParse(model.EventName, out eventId))
                    {
                        var evnt = _repositoryTicketServices.GetEventById(eventId);
                        var user = _repositoryTicketServices.GetUserByName(User.Identity.Name);
                        if (evnt == null || eventId == 1)
                        {
                            ModelState.AddModelError("chooseEvent", "Event needs to be chosen");
                            return(View("BookTickets", model));
                        }
                        var ticket = new Ticket
                        {
                            EventId    = eventId,
                            Price      = model.Price,
                            TicketGUID = Guid.NewGuid()
                        };

                        var bookingId     = _repositoryTicketServices.BookTickets(ticket, model.NumberOfTickets, user.UserId);
                        var paypalBaseUrl = ConfigurationManager.AppSettings["PaypalBaseUrl"];
                        var cancelUrl     = ConfigurationManager.AppSettings["CancelUrl"];
                        var successUrl    = ConfigurationManager.AppSettings["SuccessUrl"];
                        var notifyUrl     = ConfigurationManager.AppSettings["NotifyUrl"];
                        var businessEmail = ConfigurationManager.AppSettings["BusinessEmail"];
                        var customer      = _repositoryTicketServices.GetUserByName(User.Identity.Name);

                        var buyerEmail = customer.Email;
                        var product    = new Product
                        {
                            Ammount            = model.Price,
                            ProductDescription = evnt.EventDescription,
                            ProductName        = evnt.EventName,
                            Quantity           = model.NumberOfTickets,
                            VATAmmount         = 0
                        };
                        var products = new List <Product> {
                            product
                        };
                        Session["ShoppingBasket"] = products;
                        var upaProducts = products;

                        Session["InvoiceNo"]   = bookingId;
                        Session["ProductsUPA"] = upaProducts;
                        Session["buyerEmail"]  = buyerEmail;

                        var context = HttpContext;
                        //Process Payment
                        var paypal = new PayPalHandler(context.ApplicationInstance.Context.Session,
                                                       paypalBaseUrl, businessEmail, successUrl, cancelUrl, notifyUrl);

                        paypal.Response = context.ApplicationInstance.Context.Response;


                        paypal.RedirectToPayPal();
                        return(View("BookedSuccess"));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception e)
            {
            }
            return(View("BookTickets", model));
        }
コード例 #7
0
    protected void SendConfrimMessage()
    {
        AspxCommerce.ServiceItem.BookAnAppointmentInfo appointmentInfo = new AspxCommerce.ServiceItem.BookAnAppointmentInfo();
        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);
                    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);

                    req.Method        = "POST";
                    req.ContentType   = "application/x-www-form-urlencoded";
                    req.ContentLength = _query.Length;

                    var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                    stOut.Write(_query);
                    stOut.Close();

                    var stIn = new StreamReader(req.GetResponse().GetResponseStream());
                    _strResponse = stIn.ReadToEnd();
                    stIn.Close();

                    if (_strResponse.StartsWith("SUCCESS"))
                    {
                        string sessionCode = HttpContext.Current.Session.SessionID;
                        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]);

                            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;                    const string responsereasontext = "Transaction occured successfully";
                    const int responsereasonCode = 1;

                    string purchaseorderNo = (random.Next(0, 1000)).ToString();
                    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 = (AspxCommerce.ServiceItem.BookAnAppointmentInfo)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();
        }
    }
コード例 #8
0
        public ActionResult PostToPaypal(FormCollection forms)
        {
            var emailRegEx = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";

            if (forms["buyerEmail"] == null || !Regex.IsMatch(forms["buyerEmail"], emailRegEx))
            {
                ModelState.AddModelError("", "Your email is not in correct format");
            }
            if (System.Web.HttpContext.Current.Session["ShoppingBasket"] == null)
            {
                return(RedirectToAction("Basket", "Shopping"));
            }
            var shoppingBasket = (IList <SHOP_PRODS>)System.Web.HttpContext.Current.Session["ShoppingBasket"];

            var upaProducts = shoppingBasket.Select(item => new { ProductPrice = item.prodPrice, ProductDescription = item.prodDesc, ProductName = item.prodName }).ToList();
            var totalAmount = shoppingBasket.Sum(item => item.prodPrice);

            if (!(totalAmount > 0))
            {
                ModelState.AddModelError("", "Gross total should be more than $0.00");
            }

            if (!ModelState.IsValid)
            {
                return(View("Payment"));
            }
            var order = new Order();

            order.email       = forms["email"];
            order.order_date  = DateTime.Now;
            order.username    = User.Identity.Name;
            order.status      = "Unpaid";
            order.order_gross = totalAmount;

            _repositoryServices.SaveOrUpdateOrders(order);

            System.Web.HttpContext.Current.Session["InvoiceNo"]   = order.orderId;
            System.Web.HttpContext.Current.Session["ProductsUPA"] = upaProducts.Select(p => new UPAEventsPayPal.Product {
                ProductDescription = p.ProductDescription, ProductName = p.ProductName, Ammount = p.ProductPrice, Quantity = 1
            }).ToList();
            System.Web.HttpContext.Current.Session["buyerEmail"] = order.email;

            foreach (var product in shoppingBasket)
            {
                _repositoryServices.SaveOrUpdateItemOrders(new ItemOrder {
                    numberOrdered = 1, order_id_fk = order.orderId, product_name = product.prodName, username = User.Identity.Name
                });
            }
            var context = HttpContext;
            //Process Payment
            var paypal = new PayPalHandler(context.ApplicationInstance.Context.Session, System.Configuration.ConfigurationManager.AppSettings["PaypalBaseUrl"],
                                           System.Configuration.ConfigurationManager.AppSettings["BusinessEmail"],
                                           System.Configuration.ConfigurationManager.AppSettings["SuccessUrl"],
                                           System.Configuration.ConfigurationManager.AppSettings["CancelUrl"],
                                           System.Configuration.ConfigurationManager.AppSettings["NotifyUrl"]);

            paypal.Response = context.ApplicationInstance.Context.Response;


            paypal.RedirectToPayPal();
            return(View("PaymentMade"));
        }
コード例 #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string selectedCurrency = string.Empty;
        string MainCurrency     = string.Empty;

        try
        {
            StoreSettingConfig ssc = new StoreSettingConfig();
            MainCurrency = ssc.GetStoreSettingsByKey(StoreSetting.MainCurrency, GetStoreID, GetPortalID, GetCurrentCultureName);
            if (Session["SelectedCurrency"] != null && Session["SelectedCurrency"] != "")
            {
                selectedCurrency = Session["SelectedCurrency"].ToString();
            }
            else
            {
                selectedCurrency = MainCurrency;
            }

            string       islive     = Request.Form["custom"];
            string       test       = string.Empty;
            const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            const string strLive    = "https://www.paypal.com/cgi-bin/webscr";
            test = bool.Parse(islive.Split('#')[6]) ? strSandbox : strLive;

            var req = (HttpWebRequest)WebRequest.Create(test);
            //Set values for the request back
            req.Method      = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param      = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest       += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
            //Send the request to PayPal and get the response
            var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            var    streamIn    = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
            //string appPath = Request.PhysicalApplicationPath;
            //string filePath = appPath + "IPN.txt";
            //StreamWriter w;
            //w = File.CreateText(filePath);
            //w.WriteLine("This is a test line.");
            //w.WriteLine(islive.Split('#')[6] + "," + islive.Split('#')[1]);
            //w.Flush();
            //w.Close();
            if (strResponse == "VERIFIED")
            {
                string payerEmail     = Request.Form["payer_email"];
                string paymentStatus  = Request.Form["payment_status"];
                string receiverEmail  = Request.Form["receiver_email"];
                string amount         = Request.Form["mc_gross"];
                string invoice        = Request.Form["invoice"];
                string addressName    = Request.Form["address_name"];
                string addressStreet  = Request.Form["address_street"];
                string addressCity    = Request.Form["address_city"];
                string addressZip     = Request.Form["address_zip"];
                string addressCountry = Request.Form["address_country"];
                string transID        = Request.Form["txn_id"];
                string custom         = Request.Form["custom"];

                string[] ids         = custom.Split('#');
                int      orderID     = int.Parse(ids[0]);
                int      storeID     = int.Parse(ids[1]);
                int      portalID    = int.Parse(ids[2]);
                string   userName    = ids[3];
                int      customerID  = int.Parse(ids[4]);
                string   sessionCode = ids[5];
                string   pgid        = ids[7];

                var tinfo = new TransactionLogInfo();
                var tlog  = new TransactionLog();

                tinfo.TransactionID      = transID;
                tinfo.AuthCode           = "";
                tinfo.TotalAmount        = decimal.Parse(amount);
                tinfo.ResponseCode       = "1";
                tinfo.ResponseReasonText = "";
                tinfo.OrderID            = orderID;
                tinfo.StoreID            = storeID;
                tinfo.PortalID           = portalID;
                tinfo.AddedBy            = userName;
                tinfo.CustomerID         = customerID;
                tinfo.SessionCode        = sessionCode;
                tinfo.PaymentGatewayID   = int.Parse(pgid);
                tinfo.PaymentStatus      = paymentStatus;
                tinfo.PayerEmail         = payerEmail;
                tinfo.CreditCard         = "";
                tinfo.RecieverEmail      = receiverEmail;
                tinfo.CurrencyCode       = selectedCurrency;
                tlog.SaveTransactionLog(tinfo);


                if (paymentStatus.Equals("Completed"))
                {
                    //string appPath = Request.PhysicalApplicationPath;
                    //string filePath = appPath + "IPN.txt";
                    //StreamWriter w;
                    //w = File.CreateText(filePath);
                    //w.WriteLine("This is a test line.");
                    //w.WriteLine(payerEmail + " " + paymentStatus + " " + amount);
                    //w.WriteLine("This 2nd.");
                    //w.Flush();
                    //w.Close();
                    var paypalobj = new PayPalHandler();
                    paypalobj.ParseIPN(orderID, transID, paymentStatus, storeID, portalID, userName, customerID, sessionCode);
                    // PayPalHandler.UpdateItemQuantity(itemReduce, coupon, storeID, portalID, userName);
                }
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
            // }
        }
        catch (Exception ex)
        {
            ProcessException(ex);
            //  throw new Exception("This Page is not accessible!");
        }
    }
コード例 #10
0
    public static PayPalHandler ParseAfterIPN(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode, string TemplateName, string addressPath)
    {
        String sKey, sValue;
        PayPalHandler ph = new PayPalHandler();
        string transID = string.Empty;
        try
        {
                       String[] StringArray = postData.Split('\n');

                       /*
            * loop is set to start at 1 rather than 0 because first
            string in array will be single word SUCCESS or FAIL
            Only used to verify post data
            */
            OrderDetailsCollection ot = new OrderDetailsCollection();
            OrderDetailsInfo odinfo = new OrderDetailsInfo();
            CartManageSQLProvider cms = new CartManageSQLProvider();
            CommonInfo cf = new CommonInfo();
            cf.StoreID = storeID;
            cf.PortalID = portalID;
            cf.AddedBy = userName;
                       AspxOrderDetails objad = new AspxOrderDetails();
            SQLHandler sqlH = new SQLHandler();
                       odinfo.OrderID = int.Parse(HttpContext.Current.Session["OrderID"].ToString());
            int i;
            for (i = 1; i < StringArray.Length - 1; i++)
            {
                String[] StringArray1 = StringArray[i].Split('=');

                sKey = StringArray1[0];
                sValue = HttpUtility.UrlDecode(StringArray1[1]);

                               switch (sKey)
                {
                    case "payment_status":
                        odinfo.ResponseReasonText = Convert.ToString(sValue);
                        break;

                    case "mc_fee":
                                               break;

                    case "payer_email":
                                               break;

                    case "Tx Token":
                                               break;

                    case "txn_id":
                        odinfo.TransactionID = Convert.ToString(sValue);
                        transID = Convert.ToString(sValue);
                        break;

                }
            }

            ot.ObjOrderDetails = odinfo;
            ot.ObjCommonInfo = cf;
            HttpContext.Current.Session.Remove("OrderID");
            HttpContext.Current.Session.Remove("OrderCollection");

            return ph;
        }
        catch (Exception ex)
        {
            
            throw ex;
        }

    }
コード例 #11
0
    private void WebSuccess(string sageRedirectPath)
    {
        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"];
                _invoice = orderdata.ObjOrderDetails.InvoiceNumber;
                var pw = new PayPalWCFService();
                int i = orderdata.ObjOrderDetails.PaymentGatewayTypeID;
                List<PayPalSettingInfo> setting = pw.GetAllPayPalSetting(i, storeID, portalID);
                _authToken = setting[0].AuthToken;
                if (orderdata.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null)
                {                      AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID,
                                         orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy,
                                         orderdata.ObjCommonInfo.CultureName);
                    HttpContext.Current.Session.Remove("UsedGiftCard");
                }
            }


           
                       _txToken = Request.QueryString.Get("tx");
            _query = string.Format("cmd=_notify-synch&tx={0}&at={1}", _txToken, _authToken);
                                  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);

                       req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = _query.Length;

                       var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(_query);
            stOut.Close();

                       var stIn = new StreamReader(req.GetResponse().GetResponseStream());
            _strResponse = stIn.ReadToEnd();
            stIn.Close();

                       if (_strResponse.StartsWith("SUCCESS"))
            {
                string sessionCode = HttpContext.Current.Session.SessionID;
                                                             try
                {
                    var paypalHandler = new PayPalHandler();
                    var aspxCommonObj = new AspxCommonInfo();
                    aspxCommonObj.StoreID = storeID;
                    aspxCommonObj.PortalID = portalID;
                    aspxCommonObj.UserName = userName;
                    aspxCommonObj.CustomerID = customerID;
                    aspxCommonObj.SessionCode = sessionCode;
                    int orderID = orderdata.ObjOrderDetails.OrderID;
                    paypalHandler.ParseAfterIPN(_strResponse, aspxCommonObj, TemplateName, _addressPath);

                    AspxGiftCardController.IssueGiftCard(orderdata.LstOrderItemsInfo,orderID, true, aspxCommonObj);
                    if (orderdata.GiftCardDetail != null && CheckOutSessions.Get<List<GiftCardUsage>>("UsedGiftCard").Count > 0)
                    {
                        AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID,
                                             orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy,
                                             orderdata.ObjCommonInfo.CultureName);

                    }
                }
                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]);

                                       switch (sKey)
                    {
                        case "txn_id":
                            _transID = Convert.ToString(sValue);
                            break;
                        case "payment_status":
                            status = Convert.ToString(sValue);
                            break;

                    }
                }
                lblOrderNo.Text = "#" + Session["OrderID"].ToString();
                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");
                }

                CheckOutHelper cHelper = new CheckOutHelper();
                cHelper.ClearSessions();
    
            }
            else
            {

                lblerror.Text = GetSageMessage("Payment", "PaymentError");
            }
        }
        else
        {
            Response.Redirect(sageRedirectPath, false);
        }
    }
コード例 #12
0
    private void MobileSuccess(string sageRedirectPath)
    {
        try
        {

            if (Session["mb_OrderDetail"] != null)
            {
                var orderInfo = (OrderInfo) Session["mb_OrderDetail"];
                               var giftCardUsage = (List<GiftCardUsage>) Session["mb_GiftCardUsage"];
                var coupons = (List<CouponSession>)Session["mb_CouponSession"];
                               var billingAddress = (UserAddressInfo) Session["mb_BillingAddress"];
                var shippingAddress = (UserAddressInfo) Session["mb_ShippingAddress"];
                var itemsInfo = (List<OrderItem>) Session["mb_ItemDetails"];
                int storeId = orderInfo.StoreId;
                int portalId = orderInfo.PortalId;
                string userName = orderInfo.AddedBy;
                int customerId = orderInfo.CustomerId;
                bool isTestPaypal = false;



                _invoice = orderInfo.InvoiceNumber;
                if (!string.IsNullOrEmpty(orderInfo.TransactionId) && orderInfo.TransactionId.Trim() != "0")
                {
                    lblTransaction.Text = orderInfo.TransactionId;
                    lblInvoice.Text = orderInfo.InvoiceNumber;
                    lblPaymentMethod.Text = orderInfo.PaymentMethodName;
                    lblDateTime.Text = orderInfo.AddedOn.ToString("dddd, dd MMMM yyyy ");
                    lblOrderNo.Text = "#" + orderInfo.OrderId;
                }
                else
                {
                var pw = new PayPalWCFService();
                List<PayPalSettingInfo> setting = pw.GetAllPayPalSetting(orderInfo.PaymentGatewayTypeId, storeId,
                                                                         portalId);
                _authToken = setting[0].AuthToken;
                isTestPaypal = bool.Parse(setting[0].IsTestPaypal);

                if (giftCardUsage != null && giftCardUsage.Count > 0)
                {
                    AspxGiftCardController.UpdateGiftCardUsage(giftCardUsage, storeId,
                                                           portalId,
                                                           orderInfo.OrderId,
                                                           userName,
                                                           orderInfo.CultureName);

                }



               
                               _txToken = Request.QueryString.Get("tx");
                _query = string.Format("cmd=_notify-synch&tx={0}&at={1}", _txToken, _authToken);
                                              const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                const string strLive = "https://www.paypal.com/cgi-bin/webscr";
                string test;
                if (Session["IsTestPayPal"] != null)
                {
                    test = bool.Parse(Session["IsTestPayPal"].ToString()) ? strSandbox : strLive;
                }
                else
                {
                    test = isTestPaypal ? strSandbox : strLive;
                }
                var req = (HttpWebRequest) WebRequest.Create(test);

                               req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = _query.Length;

                               var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                stOut.Write(_query);
                stOut.Close();

                               var stIn = new StreamReader(req.GetResponse().GetResponseStream());
                _strResponse = stIn.ReadToEnd();
                stIn.Close();

                               if (_strResponse.StartsWith("SUCCESS"))
                {
                    string sessionCode = orderInfo.SessionCode;
                                                                             try
                    {
                        var paypalHandler = new PayPalHandler();
                                               
                                               paypalHandler.ParseAfterIPNMobile(orderInfo, coupons, itemsInfo, _strResponse,
                                                          billingAddress,
                                                          shippingAddress,
                                                          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]);

                                               switch (sKey)
                        {
                            case "txn_id":
                                _transID = Convert.ToString(sValue);
                                break;
                            case "payment_status":
                                status = Convert.ToString(sValue);
                                break;

                        }
                    }
                    lblOrderNo.Text = "#" + orderInfo.OrderId;
                    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");
                    }
                    Session.Clear();
                    }
                }
                Session.Clear();
            }
            else
            {
                Response.Redirect(sageRedirectPath);
            }
        }
        catch (Exception ex)
        {

            ProcessException(ex);
        }

    }
コード例 #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string islive     = Request.Form["custom"];
            string test       = string.Empty;
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            string strLive    = "https://www.paypal.com/cgi-bin/webscr";
            if (bool.Parse(islive.Split('#')[6].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";
            byte[] param      = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest       += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://*****:*****@"IPN\IPN.xml"; //
                //DataSet ds = new DataSet();
                //ds.ReadXml(st);
                //DataRow r = ds.Tables[0].NewRow();
                //r[0] = transID;
                //r[1] = payerEmail;
                //r[2] = amount;
                //r[3] = paymentStatus;
                //r[4] = receiverEmail;
                //r[5] = orderID;
                //r[6] = storeID;
                //r[7] = portalID;
                //r[8] = userName;
                //r[9] = customerID;
                //r[10] = sessionCode;
                //ds.Tables[0].Rows.Add(r);
                //ds.WriteXml(st);

                if (paymentStatus.Equals("Completed"))
                {
                    //string appPath = Request.PhysicalApplicationPath;
                    //string filePath = appPath + "IPN.txt";
                    //StreamWriter w;
                    //w = File.CreateText(filePath);
                    //w.WriteLine("This is a test line.");
                    //w.WriteLine(payerEmail + " " + paymentStatus + " " + amount);
                    //w.WriteLine("This 2nd.");
                    //w.Flush();
                    //w.Close();
                    PayPalHandler pdt = PayPalHandler.ParseIPN(orderID, transID, paymentStatus, storeID, portalID, userName, customerID, sessionCode);
                    // PayPalHandler.UpdateItemQuantity(itemReduce, coupon, storeID, portalID, userName);
                }
                // Session.Remove("IsTestPayPal");
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
            // }
        }
        catch (Exception ex)
        {
            ProcessException(ex);
            //  throw new Exception("This Page is not accessible!");
        }
    }
コード例 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PayPalHandler payPal = new PayPalHandler(InternalBodyArchitectService.PaymentsManager);

        PowrotTransferujUrl = ApplicationSettings.ServerUrl + "V2/PaymentsFinished.aspx?Transferuj=1";
        PayPalNotifyUrl     = ApplicationSettings.ServerUrl + "V2/PayPalOrderProcessing.aspx";
        PayPalUrl           = payPal.PayPalUrl;
        PayPalButton30      = payPal.BAPoints_30_Button;
        PayPalButton120     = payPal.BAPoints_120_Button;
        //AmazonHandler amazon = new AmazonHandler(InternalBodyArchitectService.PaymentsManager);
        //AmazonNotifyUrl = ApplicationSettings.ServerUrl + "V2/AmazonOrderProcessing.aspx";
        //AmazonNotifyUrl = "http://test.bodyarchitectonline.com/V2/AmazonOrderProcessing.aspx";
        //amazon.AmazonNotifyUrl = AmazonNotifyUrl;
        //AmazonUrl = amazon.AmazonUrl;
        //TODO: Amazon credentials
        //AmazonAccessKey = "AKIAIPL5YHFX7JYBMJTA";   //obtain keys at https://portal.aws.amazon.com/gp/aws/securityCredentials
        //AmazonSecretKey = "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";

        MyRenderForm.RenderFormTag = false;

#if !DEBUG
        if (Request.QueryString["Token"] == null)
        {
            Response.Redirect("http://bodyarchitectonline.com");
        }
#else
        ProfileEmail = "*****@*****.**";
#endif
        ////now using specified token we must check if this token is authenticated and if yes then we take profile id
        if (Request.QueryString["Token"] != null)
        {
            Token token        = new Token(new Guid(Request.QueryString["Token"]));
            var   securityInfo = InternalBodyArchitectService.SecurityManager.EnsureAuthentication(token);
            ProfileId        = securityInfo.SessionData.Profile.GlobalId.ToString();
            ProfileEmail     = securityInfo.SessionData.Profile.Email;
            lblUserName.Text = securityInfo.SessionData.Profile.UserName;
            Language         = securityInfo.SessionData.Token.Language;
        }
        //payNowWidgetForm = ButtonGenerator.GenerateForm(AmazonAccessKey, AmazonSecretKey, "USD 5", "BAPoints_30",
        //    ProfileId, "0", null, null, "1", AmazonNotifyUrl, "0", "HmacSHA256", amazon.UseSandbox ? "sandbox" : "prod");

        TransferujHandler transferuj = new TransferujHandler(InternalBodyArchitectService.PaymentsManager);
        TransferujUrl              = transferuj.Url;
        TransferujNotifyUrl        = ApplicationSettings.ServerUrl + "V2/TransferujOrderProcessing.aspx";
        TransferujId               = transferuj.TransferujId;
        TransferujKwota            = "15";
        TransferujCrc              = string.Format("{0}|{1}", ProfileId, "BAPoints_30");
        TransferujKodPotwierdzajcy = transferuj.TransferujKodPotwierdzajcy;

        Transferuj120Opis = (string)this.GetGlobalResourceObject("Payments.aspx", "lbl120PointsPaymentDescription.value");
        TransferujOpis    = (string)this.GetGlobalResourceObject("Payments.aspx", "lbl30PointsPaymentDescription.value");
        TransferujMd5     = FormsAuthentication.HashPasswordForStoringInConfigFile(
            TransferujId + TransferujKwota + TransferujCrc + TransferujKodPotwierdzajcy, "MD5").ToLower();

        Transferuj120Kwota = "60";
        Transferuj120Crc   = string.Format("{0}|{1}", ProfileId, "BAPoints_120");
        Transferuj120Md5   = FormsAuthentication.HashPasswordForStoringInConfigFile(
            TransferujId + Transferuj120Kwota + Transferuj120Crc + TransferujKodPotwierdzajcy, "MD5").ToLower();



        Przelewy24Handler przelewy24 = new Przelewy24Handler(InternalBodyArchitectService.PaymentsManager);
        Przelewy24Id           = przelewy24.MyId;
        Przelewy24NotifyUrl    = przelewy24.NotifyUrl;
        Przelewy24Url          = przelewy24.Url;
        Przelewy24Kwota        = "1500";
        Przelewy24Kwota120     = "6000";
        Przelewy24SessionId    = string.Format("{0}|{1}|BAPoints_30", Guid.NewGuid().ToString(), ProfileId);
        Przelewy24SessionId120 = string.Format("{0}|{1}|BAPoints_120", Guid.NewGuid().ToString(), ProfileId);
        string value    = Przelewy24SessionId + "|" + Przelewy24Id + "|" + Przelewy24Kwota + "|" + przelewy24.KluczCRC;
        string value120 = Przelewy24SessionId120 + "|" + Przelewy24Id + "|" + Przelewy24Kwota120 + "|" + przelewy24.KluczCRC;
        Przelewy24Crc    = FormsAuthentication.HashPasswordForStoringInConfigFile(value, "MD5").ToLower();
        Przelewy24Crc120 = FormsAuthentication.HashPasswordForStoringInConfigFile(value120, "MD5").ToLower();


        hideControls();
    }
コード例 #15
0
    private void WebSuccess(string sageRedirectPath)
    {
        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"];
                _invoice  = orderdata.ObjOrderDetails.InvoiceNumber;
                var pw = new PayPalWCFService();
                int i  = orderdata.ObjOrderDetails.PaymentGatewayTypeID;
                List <PayPalSettingInfo> setting = pw.GetAllPayPalSetting(i, storeID, portalID);
                _authToken = setting[0].AuthToken;
                if (orderdata.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null)
                {
                    AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID,
                                                               orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy,
                                                               orderdata.ObjCommonInfo.CultureName);
                    HttpContext.Current.Session.Remove("UsedGiftCard");
                }
            }



            _txToken = Request.QueryString.Get("tx");
            _query   = string.Format("cmd=_notify-synch&tx={0}&at={1}", _txToken, _authToken);
            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);

            req.Method        = "POST";
            req.ContentType   = "application/x-www-form-urlencoded";
            req.ContentLength = _query.Length;

            var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(_query);
            stOut.Close();

            var stIn = new StreamReader(req.GetResponse().GetResponseStream());
            _strResponse = stIn.ReadToEnd();
            stIn.Close();

            if (_strResponse.StartsWith("SUCCESS"))
            {
                string sessionCode = HttpContext.Current.Session.SessionID;
                try
                {
                    var paypalHandler = new PayPalHandler();
                    var aspxCommonObj = new AspxCommonInfo();
                    aspxCommonObj.StoreID     = storeID;
                    aspxCommonObj.PortalID    = portalID;
                    aspxCommonObj.UserName    = userName;
                    aspxCommonObj.CustomerID  = customerID;
                    aspxCommonObj.SessionCode = sessionCode;
                    int orderID = orderdata.ObjOrderDetails.OrderID;
                    paypalHandler.ParseAfterIPN(_strResponse, aspxCommonObj, TemplateName, _addressPath);

                    AspxGiftCardController.IssueGiftCard(orderdata.LstOrderItemsInfo, orderID, true, aspxCommonObj);
                    if (orderdata.GiftCardDetail != null && CheckOutSessions.Get <List <GiftCardUsage> >("UsedGiftCard").Count > 0)
                    {
                        AspxGiftCardController.UpdateGiftCardUsage(orderdata.GiftCardDetail, orderdata.ObjCommonInfo.StoreID,
                                                                   orderdata.ObjCommonInfo.PortalID, orderdata.ObjOrderDetails.OrderID, orderdata.ObjCommonInfo.AddedBy,
                                                                   orderdata.ObjCommonInfo.CultureName);
                    }
                }
                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]);

                    switch (sKey)
                    {
                    case "txn_id":
                        _transID = Convert.ToString(sValue);
                        break;

                    case "payment_status":
                        status = Convert.ToString(sValue);
                        break;
                    }
                }
                lblOrderNo.Text       = "#" + Session["OrderID"].ToString();
                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");
                }

                CheckOutHelper cHelper = new CheckOutHelper();
                cHelper.ClearSessions();
            }
            else
            {
                lblerror.Text = GetSageMessage("Payment", "PaymentError");
            }
        }
        else
        {
            Response.Redirect(sageRedirectPath, false);
        }
    }
コード例 #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string selectedCurrency = string.Empty;
        string MainCurrency     = string.Empty;

        try
        {
            StoreSettingConfig ssc = new StoreSettingConfig();
            MainCurrency = ssc.GetStoreSettingsByKey(StoreSetting.MainCurrency, GetStoreID, GetPortalID, GetCurrentCultureName);
            if (Session["SelectedCurrency"] != null)
            {
                if (Session["SelectedCurrency"].ToString() != "")
                {
                    selectedCurrency = Session["SelectedCurrency"].ToString();
                }
            }
            else
            {
                selectedCurrency = MainCurrency;
            }

            string       islive     = Request.Form["custom"];
            string       test       = string.Empty;
            const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            const string strLive    = "https://www.paypal.com/cgi-bin/webscr";
            test = bool.Parse(islive.Split('#')[6]) ? strSandbox : strLive;

            var req = (HttpWebRequest)WebRequest.Create(test);
            req.Method      = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param      = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest       += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
            var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            var    streamIn    = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
            if (strResponse == "VERIFIED")
            {
                string payerEmail     = Request.Form["payer_email"];
                string paymentStatus  = Request.Form["payment_status"];
                string receiverEmail  = Request.Form["receiver_email"];
                string amount         = Request.Form["mc_gross"];
                string invoice        = Request.Form["invoice"];
                string addressName    = Request.Form["address_name"];
                string addressStreet  = Request.Form["address_street"];
                string addressCity    = Request.Form["address_city"];
                string addressZip     = Request.Form["address_zip"];
                string addressCountry = Request.Form["address_country"];
                string transID        = Request.Form["txn_id"];
                string custom         = Request.Form["custom"];

                string[] ids         = custom.Split('#');
                int      orderID     = int.Parse(ids[0]);
                int      storeID     = int.Parse(ids[1]);
                int      portalID    = int.Parse(ids[2]);
                string   userName    = ids[3];
                int      customerID  = int.Parse(ids[4]);
                string   sessionCode = ids[5];
                string   pgid        = ids[7];

                var tinfo = new TransactionLogInfo();
                var tlog  = new TransactionLog();

                tinfo.TransactionID      = transID;
                tinfo.AuthCode           = "";
                tinfo.TotalAmount        = decimal.Parse(amount);
                tinfo.ResponseCode       = "1";
                tinfo.ResponseReasonText = "";
                tinfo.OrderID            = orderID;
                tinfo.StoreID            = storeID;
                tinfo.PortalID           = portalID;
                tinfo.AddedBy            = userName;
                tinfo.CustomerID         = customerID;
                tinfo.SessionCode        = sessionCode;
                tinfo.PaymentGatewayID   = int.Parse(pgid);
                tinfo.PaymentStatus      = paymentStatus;
                tinfo.PayerEmail         = payerEmail;
                tinfo.CreditCard         = "";
                tinfo.RecieverEmail      = receiverEmail;
                tinfo.CurrencyCode       = selectedCurrency;
                tlog.SaveTransactionLog(tinfo);


                if (paymentStatus.Equals("Completed"))
                {
                    var paypalobj = new PayPalHandler();
                    paypalobj.ParseIPN(orderID, transID, paymentStatus, storeID, portalID, userName, customerID, sessionCode);
                }
            }
            else if (strResponse == "INVALID")
            {
            }
            else
            {
            }
        }
        catch (Exception ex)
        {
            ProcessException(ex);
        }
    }
コード例 #17
0
 public PaymentGateway(string baseUrl, string businessEmail, string successUrl, string cancelUrl, string notifyUrl, string buyerEmail)
 {
     _payPalPayments = new PayPalHandler(baseUrl, businessEmail, successUrl, cancelUrl, notifyUrl, buyerEmail);
 }
コード例 #18
0
    public static PayPalHandler ParseAfterIPN(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode, string TemplateName, string addressPath)
    {
        String        sKey, sValue;
        PayPalHandler ph      = new PayPalHandler();
        string        transID = string.Empty;

        try
        {
            String[] StringArray = postData.Split('\n');

            /*
             * loop is set to start at 1 rather than 0 because first
             * string in array will be single word SUCCESS or FAIL
             * Only used to verify post data
             */
            OrderDetailsCollection ot     = new OrderDetailsCollection();
            OrderDetailsInfo       odinfo = new OrderDetailsInfo();
            CartManageSQLProvider  cms    = new CartManageSQLProvider();
            CommonInfo             cf     = new CommonInfo();
            cf.StoreID  = storeID;
            cf.PortalID = portalID;
            cf.AddedBy  = userName;
            AspxOrderDetails objad = new AspxOrderDetails();
            SQLHandler       sqlH  = new SQLHandler();
            odinfo.OrderID = int.Parse(HttpContext.Current.Session["OrderID"].ToString());
            int i;
            for (i = 1; i < StringArray.Length - 1; i++)
            {
                String[] StringArray1 = StringArray[i].Split('=');

                sKey   = StringArray1[0];
                sValue = HttpUtility.UrlDecode(StringArray1[1]);

                switch (sKey)
                {
                case "payment_status":
                    odinfo.ResponseReasonText = Convert.ToString(sValue);
                    break;

                case "mc_fee":
                    break;

                case "payer_email":
                    break;

                case "Tx Token":
                    break;

                case "txn_id":
                    odinfo.TransactionID = Convert.ToString(sValue);
                    transID = Convert.ToString(sValue);
                    break;
                }
            }

            ot.ObjOrderDetails = odinfo;
            ot.ObjCommonInfo   = cf;
            HttpContext.Current.Session.Remove("OrderID");
            HttpContext.Current.Session.Remove("OrderCollection");

            return(ph);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
コード例 #19
0
        public void SaveErrorLog(string postData)
        {
            var ph = new PayPalHandler();

            try
            {
                //split response into string array using whitespace delimeter
                String[] stringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */

                int i;
                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 "payment_status":
                            //  odinfo.ResponseReasonText = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            //  odinfo.TransactionID = Convert.ToString(sValue);
                            break;

                    }
                }

               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string selectedCurrency = string.Empty;
        string MainCurrency = string.Empty;
        try
        {
            StoreSettingConfig ssc = new StoreSettingConfig();
            MainCurrency = ssc.GetStoreSettingsByKey(StoreSetting.MainCurrency, GetStoreID, GetPortalID, GetCurrentCultureName);
            if (Session["SelectedCurrency"] != null)
            {
                if (Session["SelectedCurrency"].ToString() != "")
                {
                    selectedCurrency = Session["SelectedCurrency"].ToString();
                }
            }
            else
            {
                selectedCurrency = MainCurrency;
            } 

            string islive = Request.Form["custom"];
            string test = string.Empty;
            const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            const string strLive = "https://www.paypal.com/cgi-bin/webscr";
            test = bool.Parse(islive.Split('#')[6]) ? strSandbox : strLive;

            var req = (HttpWebRequest)WebRequest.Create(test);
                       req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
                                                        var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
                                                                                                    if (strResponse == "VERIFIED")
            {
                string payerEmail = Request.Form["payer_email"];
                string paymentStatus = Request.Form["payment_status"];
                string receiverEmail = Request.Form["receiver_email"];
                string amount = Request.Form["mc_gross"];
                string invoice = Request.Form["invoice"];
                string addressName = Request.Form["address_name"];
                string addressStreet = Request.Form["address_street"];
                string addressCity = Request.Form["address_city"];
                string addressZip = Request.Form["address_zip"];
                string addressCountry = Request.Form["address_country"];
                string transID = Request.Form["txn_id"];
                string custom = Request.Form["custom"];
             
                string[] ids = custom.Split('#');
                int orderID = int.Parse(ids[0]);
                int storeID = int.Parse(ids[1]);
                int portalID = int.Parse(ids[2]);
                string userName = ids[3];
                int customerID = int.Parse(ids[4]);
                string sessionCode = ids[5];
                string pgid = ids[7];

                var tinfo = new TransactionLogInfo();
                var tlog = new TransactionLog();

                tinfo.TransactionID = transID;
                tinfo.AuthCode = "";
                tinfo.TotalAmount = decimal.Parse(amount);
                tinfo.ResponseCode = "1";
                tinfo.ResponseReasonText = "";
                tinfo.OrderID = orderID;
                tinfo.StoreID = storeID;
                tinfo.PortalID = portalID;
                tinfo.AddedBy = userName;
                tinfo.CustomerID = customerID;
                tinfo.SessionCode = sessionCode;
                tinfo.PaymentGatewayID = int.Parse(pgid);
                tinfo.PaymentStatus = paymentStatus;
                tinfo.PayerEmail = payerEmail;
                tinfo.CreditCard = "";
                tinfo.RecieverEmail = receiverEmail;
                tinfo.CurrencyCode = selectedCurrency;
                tlog.SaveTransactionLog(tinfo);
              

                if (paymentStatus.Equals("Completed"))
                {
                                                                                                                                                                                               var paypalobj = new PayPalHandler();
                    paypalobj.ParseIPN(orderID, transID, paymentStatus, storeID, portalID, userName, customerID, sessionCode);
                                   }
              

            }
            else if (strResponse == "INVALID")
            {
                           }
            else
            {
                           }
                   }
        catch (Exception ex)
        {
            ProcessException(ex);
                 }
    }
コード例 #21
0
    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);
            }
        }
    }