protected void btnPaypalExpress_Click(object sender, EventArgs e)
        {
            if ((NopContext.Current.User == null) || (NopContext.Current.User.IsGuest && !CustomerManager.AnonymousCheckoutAllowed))
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }

            var payPalExpress    = new PayPalExpressPaymentProcessor();
            var ppePaymentMethod = PaymentMethodManager.GetPaymentMethodBySystemKeyword("PayPalExpress");

            if (ppePaymentMethod != null && ppePaymentMethod.IsActive)
            {
                //apply reward points
                CheckoutPaymentMethodControl checkoutPaymentMethodControl = CommonHelper.FindControlRecursive <CheckoutPaymentMethodControl>(this.Page.Controls);
                if (checkoutPaymentMethodControl != null)
                {
                    checkoutPaymentMethodControl.ApplyRewardPoints();
                }

                //payment
                var     cart      = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
                decimal?cartTotal = ShoppingCartManager.GetShoppingCartTotal(cart,
                                                                             ppePaymentMethod.PaymentMethodId, NopContext.Current.User);
                if (cartTotal.HasValue && cartTotal.Value > decimal.Zero)
                {
                    string expressCheckoutURL = payPalExpress.SetExpressCheckout(cartTotal.Value,
                                                                                 CommonHelper.GetStoreLocation(false) + "paypalexpressreturn.aspx",
                                                                                 CommonHelper.GetStoreLocation(false));
                    Response.Redirect(expressCheckoutURL);
                }
            }
        }
        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    PayPalExpressPaymentProcessor payPalExpress = new PayPalExpressPaymentProcessor();
                    string      token = CommonHelper.QueryString("token");
                    PaypalPayer payer = payPalExpress.GetExpressCheckout(token);
                    if (string.IsNullOrEmpty(payer.PayerID))
                    {
                        throw new NopException("Payer ID is not set");
                    }

                    PaymentInfo paymentInfo = new PaymentInfo();

                    PaymentMethod paypalExpressPaymentMethod = PaymentMethodManager.GetPaymentMethodBySystemKeyword("PayPalExpress");

                    paymentInfo.PaymentMethodId  = paypalExpressPaymentMethod.PaymentMethodId;
                    paymentInfo.BillingAddress   = NopContext.Current.User.BillingAddress;
                    paymentInfo.ShippingAddress  = NopContext.Current.User.ShippingAddress;
                    paymentInfo.PaypalPayerId    = payer.PayerID;
                    paymentInfo.PaypalToken      = token;
                    paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                    paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

                    int    orderId = 0;
                    string result  = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderId);

                    Order order = OrderManager.GetOrderById(orderId);
                    if (!String.IsNullOrEmpty(result))
                    {
                        lConfirmOrderError.Text = Server.HtmlEncode(result);
                        btnNextStep.Visible     = false;
                        return;
                    }
                    else
                    {
                        PaymentManager.PostProcessPayment(order);
                    }
                    Response.Redirect("~/checkoutcompleted.aspx");
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
                    lConfirmOrderError.Text = Server.HtmlEncode(exc.ToString());
                    btnNextStep.Visible     = false;
                }
            }
        }
Beispiel #3
0
        protected void btnPaypalExpress_Click(object sender, EventArgs e)
        {
            if ((NopContext.Current.User == null) || (NopContext.Current.User.IsGuest && !CustomerManager.AnonymousCheckoutAllowed))
            {
                string loginURL = CommonHelper.GetLoginPageURL(true);
                Response.Redirect(loginURL);
            }

            PayPalExpressPaymentProcessor payPalExpress = new PayPalExpressPaymentProcessor();

            //todo pass payment method identifier if paypal express requires additional payment fee
            decimal?cartTotal = ShoppingCartManager.GetShoppingCartTotal(Cart, NopContext.Current.User);

            if (cartTotal.HasValue)
            {
                string expressCheckoutURL = payPalExpress.SetExpressCheckout(cartTotal.Value,
                                                                             CommonHelper.GetStoreLocation(false) + "PaypalExpressReturn.aspx",
                                                                             CommonHelper.GetStoreLocation(false) + "Default.aspx");
                Response.Redirect(expressCheckoutURL);
            }
        }
Beispiel #4
0
        protected void btnPaypalExpress_Click(object sender, EventArgs e)
        {
            if ((NopContext.Current.User == null) || (NopContext.Current.User.IsGuest && !CustomerManager.AnonymousCheckoutAllowed))
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }

            var payPalExpress    = new PayPalExpressPaymentProcessor();
            var ppePaymentMethod = PaymentMethodManager.GetPaymentMethodBySystemKeyword("PayPalExpress");

            if (ppePaymentMethod != null && ppePaymentMethod.IsActive)
            {
                decimal?cartTotal = ShoppingCartManager.GetShoppingCartTotal(cart,
                                                                             ppePaymentMethod.PaymentMethodId, NopContext.Current.User, false);
                if (cartTotal.HasValue)
                {
                    string expressCheckoutURL = payPalExpress.SetExpressCheckout(cartTotal.Value,
                                                                                 CommonHelper.GetStoreLocation(false) + "paypalexpressreturn.aspx",
                                                                                 CommonHelper.GetStoreLocation(false));
                    Response.Redirect(expressCheckoutURL);
                }
            }
        }