public void LoadSetting()
    {
        var pw = new PayPalWCFService();
        var orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];

        try
        {
            List<PayPalSettingInfo> sf = pw.GetAllPayPalSetting(CheckOutSessions.Get<int>("GateWay", 0), storeID,
                                                                portalID);

            string postUrl;
            if (bool.Parse(sf[0].IsTestPaypal))
            {
                postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;

            }
            else
            {
                postUrl = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;

            }
            string ids = HttpContext.Current.Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + UserName + "#" +
                         customerID + "#" + SessionCode + "#" + HttpContext.Current.Session["IsTestPayPal"].ToString() + "#" +
                       CheckOutSessions.Get<int>("GateWay", 0);


            var url = new StringBuilder();

            url.Append(postUrl + "?cmd=_cart&business=" +
                       HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim()));
            string serviceType = string.Empty;
            if (HttpContext.Current.Session["ServiceType"] != null)
            {
                serviceType = HttpContext.Current.Session["ServiceType"].ToString();
            }
            if (serviceType.ToLower() == "true")
            {
                var appointmentInfo = new BookAppointmentInfo();
                if (HttpContext.Current.Session["AppointmentCollection"] != null)
                {
                    appointmentInfo = (BookAppointmentInfo)HttpContext.Current.Session["AppointmentCollection"];
                }
                int nCount = 1;
                double itemPrice = Convert.ToDouble(appointmentInfo.ServiceProductPrice) * Rate;
                url.AppendFormat("&item_name_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(appointmentInfo.ServiceProductName));
                url.AppendFormat("&amount_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
               
                double discountAll = 0.00;
                double couponDiscount = 0.00;
                double taxAll = 0.00;
                double shippingCostAll = 0.00;

                url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
                url.AppendFormat("&discount_amount_cart={0}",
                                 HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
                url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
                url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
                url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(MainCurrency));

                if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                {


                                                          var serviceSuccessPage = "Appointment-Success.aspx";
                    var successPageURL = sf[0].ReturnUrl.Substring(0, sf[0].ReturnUrl.LastIndexOf("/")) + "/" + serviceSuccessPage;
                    url.AppendFormat("&return={0}", HttpUtility.UrlEncode(successPageURL.ToString()));
                }
                if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                    url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
                if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                    url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));

                url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

                url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));
                HttpContext.Current.Response.Redirect(url.ToString(), false);
            }
            else
            {
                List<CartInfoforPaypal> cd = pw.GetCartDetails(storeID, portalID, customerID, UserName,
                                                               CultureName, SessionCode);
                int nCount = 1;


                foreach (CartInfoforPaypal oItem in cd)
                {
                    double itemPrice = Convert.ToDouble(oItem.Price) * Rate;
                    url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.ItemName));
                    url.AppendFormat("&amount_" + nCount + "={0}",
                                     HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
                    url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                    nCount++;
                }
                nCount--;
                decimal gcamount = 0;

                List<GiftCardUsage> list = CheckOutSessions.Get<List<GiftCardUsage>>("UsedGiftCard");// (List<GiftCardUsage>)Session["UsedGiftCard"];

                if (list.Count > 0)
                    gcamount = list.Sum(e => e.ReducedAmount);


                double discountAll = CheckOutSessions.Get<double>("DiscountAmount", 0)+ Convert.ToDouble(gcamount.ToString()) * Rate;
                double couponDiscount = (double)orderdata2.ObjOrderDetails.CouponDiscountAmount * Rate;
                double taxAll =CheckOutSessions.Get<double>("TaxAll", 0) * Rate;
                double shippingCostAll = CheckOutSessions.Get<double>("ShippingCostAll", 0)  * Rate;
                url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
                url.AppendFormat("&discount_amount_cart={0}",
                                 HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
                url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
                url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
                url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(MainCurrency));

                if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                    url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
                if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                    url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
                if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                    url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));

                url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

                url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

                HttpContext.Current.Response.Redirect(url.ToString(), false);
            }
        }
        catch
        {
            lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            //ProcessException(ex);
        }

    }
Exemplo n.º 2
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);
        }
    }
    private void LoadSetting()
    {
        var pw        = new PayPalWCFService();
        var orderdata = OrderDetail;

        try
        {
            List <PayPalSettingInfo> sf = pw.GetAllPayPalSetting(orderdata.PaymentGatewayTypeId, orderdata.StoreId, orderdata.PortalId);

            string postUrl;
            if (bool.Parse(sf[0].IsTestPaypal))
            {
                postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;
            }
            else
            {
                postUrl = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;
            }
            string ids = orderdata.OrderId + "#" + orderdata.StoreId + "#" + orderdata.PortalId + "#" + orderdata.AddedBy + "#" + orderdata.CustomerId + "#" + orderdata.SessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" + orderdata.PaymentGatewayTypeId;


            var url = new StringBuilder();

            url.Append(postUrl + "?cmd=_cart&business=" +
                       HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim()));

            List <CartInfoforPaypal> cd = pw.GetCartDetails(orderdata.StoreId, orderdata.PortalId, orderdata.CustomerId, orderdata.AddedBy, orderdata.CultureName, orderdata.SessionCode);
            int nCount = 1;
            if (ItemDetails.Count() == cd.Count())
            {
                if (cd.Count == 0)
                {
                    throw new Exception("Your cart does't have any items!Please re-check and checkout again!");
                }
                foreach (CartInfoforPaypal oItem in cd)
                {
                    double itemPrice = Convert.ToDouble(oItem.Price) * Rate;
                    url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.ItemName));
                    url.AppendFormat("&amount_" + nCount + "={0}",
                                     HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
                    url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                    nCount++;
                }
            }
            else
            {
                throw new Exception("Your ordered items and current cart items does not matched!");
            }

            nCount--;
            double discountAll     = Convert.ToDouble(DiscountTotal) * Rate;
            double couponDiscount  = (double)CouponTotal * Rate;
            double taxAll          = Convert.ToDouble(TaxTotal) * Rate;
            double shippingCostAll = Convert.ToDouble(ShippingCostTotal) * Rate;
            url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
            url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
            url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
            url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
            url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(Currency));

            if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
            {
                url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
            }
            if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
            {
                url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
            }
            if (!string.IsNullOrEmpty(sf[0].CancelUrl))
            {
                url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));
            }

            url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

            url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

            Response.Redirect(url.ToString(), false);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Exemplo n.º 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);
        }
    }
Exemplo n.º 5
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);
        }
    }
Exemplo n.º 6
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);
            }
        }
    }
    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");
                    }
                    else
                    {
                        sageRedirectPath = ResolveUrl("~/" + sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx");
                    }
                }
                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);

                        }
                        catch (Exception)
                        {
                            lblerror.Text = "Some Error Ocuured. Please view your order wheather order processed or pending";
                           
                        } 
                        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 = "Your payment has been successfully processed." +
                            " A confirmation email has been sent to you with the details of the order. Please quote the order number for all future correspondence regarding this transaction.";
                        }
                        else if (status.ToLower().Trim() == "pending")
                        {
                            lblerror.Text = "Transaction completed with status is pending. Your order status is pending and Also" +
                        " a confirmation email has been sent to you with the details of the order. Please complete your transaction in order to further process.";
                     
                        }

                        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 = "Something goes wrong !! you may check your email or contact merchant whether transaction occured successfully or not....";
                    }
                }
                else
                {
                    Response.Redirect(sageRedirectPath, false);
                }
            }
            catch (Exception ex)
            {

                ProcessException(ex);
            }
        }
    }
    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();
        }
    }
Exemplo n.º 9
0
    public void GetCartDetails()
    {
        //Response.Write(GetCustomerID.ToString() + "st" + GetStoreID.ToString());
        PayPalWCFService pw = new PayPalWCFService();
        List<CartInfoforPaypal> cd;
        try
        {
        cd = pw.GetCartDetails(storeID, portalID,customerID, userName, GetCurrentCultureName, sessionCode);
        int nCount = 1;
        string sAdd;

        foreach (CartInfoforPaypal oItem in cd)
        {


            sAdd = "<input name=\"item_name_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + oItem.ItemName.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));        
            sAdd = "<input name=\"amount_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + oItem.Price.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input name=\"quantity_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + oItem.Quantity.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            nCount++;
        }
        nCount--;
        sAdd = "<input name=\"num_cart_items\" type=\"hidden\" value=\"" + nCount.ToString() + "\"> ";
        plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));     
        sAdd = "<input type=\"hidden\" name=\"discount_amount_cart\" value=\"" + Session["DiscountAll"].ToString() + "\" />";
        plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
        sAdd = "<input type=\"hidden\" name=\"tax_cart\" value=\"" + Session["TaxAll"].ToString() + "\" />";  
        plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
        sAdd = "<input type=\"hidden\" name=\"no_shipping\" value=\"1\" />";
        plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
        sAdd = " <input type=\"hidden\" name=\"shipping_1\" value=\"" + Session["ShippingCostAll"].ToString() + "\" />";
        plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));        
       
        }
        catch (Exception ex)
        {
            lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }
      
     //  HttpContext.Current.Session.Remove("")

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

    }
    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);
        }
    }
Exemplo n.º 12
0
    public void LoadSetting()
    {
        PayPalWCFService         pw = new PayPalWCFService();
        List <PayPalSettingInfo> sf;
        OrderDetailsCollection   orderdata2 = new OrderDetailsCollection();

        orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
        string postURL = string.Empty;

        try
        {
            sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID, portalID);

            if (bool.Parse(sf[0].IsTestPaypal.ToString()))
            {
                postURL = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;
            }
            else
            {
                postURL = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;
            }
            string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + userName + "#" + customerID + "#" + sessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" + Session["GateWay"].ToString();


            StringBuilder url = new StringBuilder();

            url.Append(postURL + "?cmd=_cart&business=" +
                       HttpUtility.UrlEncode(sf[0].BusinessAccount.ToString()));

            List <CartInfoforPaypal> cd;

            cd = pw.GetCartDetails(storeID, portalID, customerID, userName, GetCurrentCultureName, sessionCode);
            int nCount = 1;


            foreach (CartInfoforPaypal oItem in cd)
            {
                url.AppendFormat("&item_name_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.ItemName.ToString()));
                url.AppendFormat("&amount_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.Price.ToString()));
                url.AppendFormat("&quantity_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                nCount++;
            }
            nCount--;
            url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
            url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Session["DiscountAll"].ToString()));
            url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Session["TaxAll"].ToString()));
            url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Session["ShippingCostAll"].ToString()));

            if (sf[0].ReturnUrl.ToString() != null && sf[0].ReturnUrl.ToString() != "")
            {
                url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
            }
            if (sf[0].VerificationUrl != null && sf[0].VerificationUrl != "")
            {
                url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
            }
            if (sf[0].CancelUrl != null && sf[0].CancelUrl != "")
            {
                url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));
            }

            url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

            url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

            Response.Redirect(url.ToString(), false);
        }
        catch (Exception ex)
        {
            lblnotity.Text    = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }
    }
Exemplo n.º 13
0
    public void LoadSetting()
    {
        var pw         = new PayPalWCFService();
        var orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];

        try
        {
            List <PayPalSettingInfo> sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID,
                                                                 portalID);

            string postUrl;
            if (bool.Parse(sf[0].IsTestPaypal))
            {
                postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;
            }
            else
            {
                postUrl = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;
            }
            string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + UserName + "#" +
                         customerID + "#" + SessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" +
                         Session["GateWay"].ToString();


            var url = new StringBuilder();

            url.Append(postUrl + "?cmd=_cart&business=" +
                       HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim()));
            string serviceType = string.Empty;
            if (Session["ServiceType"] != null)
            {
                serviceType = Session["ServiceType"].ToString();
            }
            if (serviceType.ToLower() == "true")
            {
                var appointmentInfo = new BookAppointmentInfo();
                if (HttpContext.Current.Session["AppointmentCollection"] != null)
                {
                    appointmentInfo = (BookAppointmentInfo)HttpContext.Current.Session["AppointmentCollection"];
                }
                int    nCount    = 1;
                double itemPrice = Convert.ToDouble(appointmentInfo.ServiceProductPrice) * Rate;
                url.AppendFormat("&item_name_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(appointmentInfo.ServiceProductName));
                url.AppendFormat("&amount_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
                //   url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));

                double discountAll     = 0.00;
                double couponDiscount  = 0.00;
                double taxAll          = 0.00;
                double shippingCostAll = 0.00;

                url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
                url.AppendFormat("&discount_amount_cart={0}",
                                 HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
                url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
                url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
                url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(MainCurrency));

                if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                {
                    // url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
                    //var successPage = sf[0].ReturnUrl.Split('/');
                    var serviceSuccessPage = "Appointment-Success.aspx";
                    var successPageURL     = sf[0].ReturnUrl.Substring(0, sf[0].ReturnUrl.LastIndexOf("/")) + "/" + serviceSuccessPage;
                    url.AppendFormat("&return={0}", HttpUtility.UrlEncode(successPageURL.ToString()));
                }
                if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                {
                    url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
                }
                if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                {
                    url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));
                }

                url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

                url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));
                Response.Redirect(url.ToString(), false);
            }
            else
            {
                List <CartInfoforPaypal> cd = pw.GetCartDetails(storeID, portalID, customerID, UserName,
                                                                GetCurrentCultureName, SessionCode);
                int nCount = 1;


                foreach (CartInfoforPaypal oItem in cd)
                {
                    double itemPrice = Convert.ToDouble(oItem.Price) * Rate;
                    url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.ItemName));
                    url.AppendFormat("&amount_" + nCount + "={0}",
                                     HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
                    url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                    nCount++;
                }
                nCount--;
                double discountAll     = Convert.ToDouble(Session["DiscountAll"].ToString()) * Rate;
                double couponDiscount  = (double)orderdata2.ObjOrderDetails.CouponDiscountAmount * Rate;
                double taxAll          = Convert.ToDouble(Session["TaxAll"].ToString()) * Rate;
                double shippingCostAll = Convert.ToDouble(Session["ShippingCostAll"].ToString()) * Rate;
                url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
                url.AppendFormat("&discount_amount_cart={0}",
                                 HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
                url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
                url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
                url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(MainCurrency));

                if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                {
                    url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
                }
                if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                {
                    url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
                }
                if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                {
                    url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));
                }

                url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

                url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

                Response.Redirect(url.ToString(), false);
            }
        }
        catch (Exception ex)
        {
            lblnotity.Text    = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }
    }
    public void LoadSetting()
    {
        PayPalWCFService pw = new PayPalWCFService();
        List<PayPalSettingInfo> sf;
        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
        orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
        string postURL=string.Empty;
       
        try
        {
            sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID, portalID);

            if (bool.Parse(sf[0].IsTestPaypal.ToString()))
            {
                postURL = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;

            }
            else
            {
                postURL = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;

            }
            string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + userName + "#" + customerID + "#" + sessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" + Session["GateWay"].ToString();


            StringBuilder url = new StringBuilder();

            url.Append(postURL + "?cmd=_cart&business=" +
                HttpUtility.UrlEncode(sf[0].BusinessAccount.ToString()));

            List<CartInfoforPaypal> cd;

            cd = pw.GetCartDetails(storeID, portalID, customerID, userName, GetCurrentCultureName, sessionCode);
            int nCount = 1;


            foreach (CartInfoforPaypal oItem in cd)
            {
                url.AppendFormat("&item_name_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.ItemName.ToString()));
                url.AppendFormat("&amount_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.Price.ToString()));
                url.AppendFormat("&quantity_" + nCount.ToString() + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                nCount++;
            }
            nCount--;
            url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
            url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Session["DiscountAll"].ToString()));
            url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Session["TaxAll"].ToString()));
            url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Session["ShippingCostAll"].ToString()));

            if (sf[0].ReturnUrl.ToString() != null && sf[0].ReturnUrl.ToString() != "")
                url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
            if (sf[0].VerificationUrl != null && sf[0].VerificationUrl != "")
                url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
            if (sf[0].CancelUrl != null && sf[0].CancelUrl != "")
                url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));

            url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

            url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

            Response.Redirect(url.ToString(), false);
        }
        catch (Exception ex)
        {
            lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }

    }
    public void LoadSetting()
    {
        var pw = new PayPalWCFService();
        var orderdata2 =  (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];

        try
        {
            List<PayPalSettingInfo> sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID,
                                                                portalID);

            string postUrl;
            if (bool.Parse(sf[0].IsTestPaypal))
            {
                postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;

            }
            else
            {
                postUrl = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;

            }
            string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + UserName + "#" +
                         customerID + "#" + SessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" +
                         Session["GateWay"].ToString();


            var url = new StringBuilder();

            url.Append(postUrl + "?cmd=_cart&business=" +
                       HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim()));
            string serviceType = string.Empty;
            if (Session["ServiceType"] != null)
            {
                serviceType = Session["ServiceType"].ToString();
            }
            if (serviceType.ToLower() == "true")
            {
                var appointmentInfo = new BookAppointmentInfo();
                if (HttpContext.Current.Session["AppointmentCollection"] != null)
                {
                    appointmentInfo = (BookAppointmentInfo) HttpContext.Current.Session["AppointmentCollection"];
                }
                int nCount = 1;
                double itemPrice = Convert.ToDouble(appointmentInfo.ServiceProductPrice)*Rate;
                url.AppendFormat("&item_name_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(appointmentInfo.ServiceProductName));
                url.AppendFormat("&amount_" + nCount + "={0}",
                                 HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
               
                double discountAll = 0.00;
                double couponDiscount = 0.00;
                double taxAll = 0.00;
                double shippingCostAll = 0.00;

                url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
                url.AppendFormat("&discount_amount_cart={0}",
                                 HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
                url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
                url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
                url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(MainCurrency));

                if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                {

                 
                                                          var serviceSuccessPage = "Appointment-Success.aspx";
                    var successPageURL = sf[0].ReturnUrl.Substring(0, sf[0].ReturnUrl.LastIndexOf("/")) + "/" +serviceSuccessPage;
                    url.AppendFormat("&return={0}", HttpUtility.UrlEncode(successPageURL.ToString()));
                }
                if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                    url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
                if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                    url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));

                url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
                url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

                url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));
                Response.Redirect(url.ToString(), false);
            }            
        }
        catch (Exception ex)
        {
            lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }

    }
Exemplo n.º 16
0
    public void LoadSetting()
    {
        PayPalWCFService pw = new PayPalWCFService();
        List<PayPalSettingInfo> sf;
        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
        orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];

        try
        {
            sf = pw.GetAllPayPalSetting(int.Parse(Session["GateWay"].ToString()), storeID, portalID);

            string sAdd;

            if (bool.Parse(sf[0].IsTestPaypal.ToString()))
            {
                PaypalForm.Action = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;
                // clickhere.NavigateUrl="https://www.sandbox.paypal.com/us/cgi-bin/webscr";
            }
            else
            {
                PaypalForm.Action = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;
                // clickhere.NavigateUrl = "https://www.paypal.com/us/cgi-bin/webscr";
            }
            sAdd = "<input name=\"business\" type=\"hidden\" value=\"" + sf[0].BusinessAccount.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input name=\"cancel_return\"  type=\"hidden\" value=\"" + sf[0].CancelUrl.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));

            sAdd = "<input name=\"return\" type=\"hidden\" value=\"" + sf[0].ReturnUrl.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input name=\"notify_url\"  type=\"hidden\" value=\"" + sf[0].VerificationUrl.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input type=\"hidden\" name=\"cmd\" value=\"_cart\" />";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input type=\"hidden\" name=\"upload\" value=\"1\" />";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            sAdd = "<input type=\"hidden\" name=\"rm\" value=\"1\" />";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
            //43#1#1#usern#44#session
            string ids = Session["OrderID"].ToString() + "#" + storeID + "#" + portalID + "#" + userName + "#" + customerID + "#" + sessionCode + "#" + Session["IsTestPayPal"].ToString();
            sAdd = "<input type=\"hidden\" name=\"custom\" value=\"" + ids + "\" />";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
         
            //string itemReduce = string.Empty;
            //string coupon = string.Empty;
            //foreach (OrderItemInfo objItems in orderdata2.lstOrderItemsInfo)
            //{
            //    itemReduce += objItems.ItemID + "," + objItems.Quantity + "," + objItems.IsDownloadable + "#";
            //}
            //sAdd = "<input type=\"hidden\" name=\"custom_1\" value=\"" + itemReduce + "\" />";
            //plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));

            //if (orderdata2.objOrderDetails.CouponCode != null && Session["CouponApplied"] != null)
            //{
            //    coupon = orderdata2.objOrderDetails.CouponCode + "#" + Session["CouponApplied"].ToString();
            //}
            //sAdd = "<input type=\"hidden\" name=\"custom_2\" value=\"" + coupon + "\" />";
            //plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));



        }
        catch (Exception ex)
        {
            lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout";
            clickhere.Visible = false;
            ProcessException(ex);
        }

    }
Exemplo n.º 17
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();
        }
    }
    private void LoadSetting()
    {
        var pw = new PayPalWCFService();
        var orderdata = OrderDetail;

        try
        {
            List<PayPalSettingInfo> sf = pw.GetAllPayPalSetting(orderdata.PaymentGatewayTypeId, orderdata.StoreId, orderdata.PortalId);

            string postUrl;
            if (bool.Parse(sf[0].IsTestPaypal))
            {
                postUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = true;

            }
            else
            {
                postUrl = "https://www.paypal.com/us/cgi-bin/webscr";
                HttpContext.Current.Session["IsTestPayPal"] = false;

            }
            string ids = orderdata.OrderId + "#" + orderdata.StoreId + "#" + orderdata.PortalId + "#" + orderdata.AddedBy + "#" + orderdata.CustomerId + "#" + orderdata.SessionCode + "#" + Session["IsTestPayPal"].ToString() + "#" + orderdata.PaymentGatewayTypeId;


            var url = new StringBuilder();

            url.Append(postUrl + "?cmd=_cart&business=" +
                HttpUtility.UrlEncode(sf[0].BusinessAccount.Trim()));

            List<CartInfoforPaypal> cd = pw.GetCartDetails(orderdata.StoreId, orderdata.PortalId, orderdata.CustomerId, orderdata.AddedBy, orderdata.CultureName, orderdata.SessionCode);
            int nCount = 1;
            if (ItemDetails.Count() == cd.Count())
            {


                if (cd.Count == 0)
                {
                    throw new Exception("Your cart does't have any items!Please re-check and checkout again!");
                }
                foreach (CartInfoforPaypal oItem in cd)
                {
                    double itemPrice = Convert.ToDouble(oItem.Price)*Rate;
                    url.AppendFormat("&item_name_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.ItemName));
                    url.AppendFormat("&amount_" + nCount + "={0}",
                                     HttpUtility.UrlEncode(Math.Round(itemPrice, 2).ToString()));
                    url.AppendFormat("&quantity_" + nCount + "={0}", HttpUtility.UrlEncode(oItem.Quantity.ToString()));
                    nCount++;
                }
            }else
            {
                throw new Exception("Your ordered items and current cart items does not matched!");
            }

            nCount--;
            double discountAll = Convert.ToDouble(DiscountTotal) * Rate;
            double couponDiscount = (double)CouponTotal * Rate;
            double taxAll = Convert.ToDouble(TaxTotal) * Rate;
            double shippingCostAll = Convert.ToDouble(ShippingCostTotal) * Rate;
            url.AppendFormat("&num_cart_items={0}", HttpUtility.UrlEncode(nCount.ToString()));
            url.AppendFormat("&discount_amount_cart={0}", HttpUtility.UrlEncode(Math.Round((discountAll + couponDiscount), 2).ToString()));
            url.AppendFormat("&tax_cart={0}", HttpUtility.UrlEncode(Math.Round(taxAll, 2).ToString()));
            url.AppendFormat("&no_shipping={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&shipping_1={0}", HttpUtility.UrlEncode(Math.Round(shippingCostAll, 2).ToString()));
            url.AppendFormat("&currency_code={0}", HttpUtility.UrlEncode(Currency));

            if (sf[0].ReturnUrl != null && sf[0].ReturnUrl.Trim() != "")
                url.AppendFormat("&return={0}", HttpUtility.UrlEncode(sf[0].ReturnUrl.ToString()));
            if (!string.IsNullOrEmpty(sf[0].VerificationUrl))
                url.AppendFormat("&notify_url={0}", HttpUtility.UrlEncode(sf[0].VerificationUrl));
            if (!string.IsNullOrEmpty(sf[0].CancelUrl))
                url.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(sf[0].CancelUrl));

            url.AppendFormat("&upload={0}", HttpUtility.UrlEncode("1"));
            url.AppendFormat("&rm={0}", HttpUtility.UrlEncode("1"));

            url.AppendFormat("&custom={0}", HttpUtility.UrlEncode(ids));

            Response.Redirect(url.ToString(), false);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }