Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            storeContext = new StoreContext(Request);
            storeUrls    = new StoreUrls(storeContext);

            string shippingOption = Request.Params["shippingOption"];

            payPalStandard = new PayPalStandardProvider(storeContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));

            if (!IsPostBack)
            {
                //CartController cartController = new CartController(storeContext);
                //Cart cart = cartController.GetCart(false);

                //Order pendingOrder = ConvertCartToPendingOrder(cart);

                decimal?shippingCost       = WA.Parser.ToDecimal(Request.Params["s"]);
                string  shippingOptionName = Request.Params["sn"] ?? string.Empty;

                CheckoutOrderInfo checkoutOrderInfo = Session[storeContext.SessionKeys.CheckoutOrderInfo] as CheckoutOrderInfo;
                if (checkoutOrderInfo != null)
                {
                    OrderController orderController = new OrderController(storeContext);
                    Order           pendingOrder    = orderController.CreateOrder(checkoutOrderInfo, OrderStatusName.PendingOffsite);
                    if (shippingCost.HasValue)
                    {
                        pendingOrder.ShippingAmount          = shippingCost.Value;
                        pendingOrder.ShippingServiceOption   = shippingOptionName;
                        pendingOrder.ShippingServiceProvider = ShippingProviderType.CustomShipping.ToString();
                        pendingOrder.Save();
                    }
                    GeneratePayPalForm(pendingOrder);
                }
            }
        }
        private void LoadPaymentProviders()
        {
            DataModel.Store store = StoreContext.CurrentStore;

            // StoreContext.CurrentStore.GetOnsiteCreditCardPaymentProvider() == PaymentProviderName.OfflinePayment
            // StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.AuthorizeNetAim)

            // ON-SITE
            chkPayLater.Checked        = store.IsPaymentProviderEnabled(PaymentProviderName.PayLater);
            chkCardCaptureOnly.Checked = store.IsPaymentProviderEnabled(PaymentProviderName.CardCaptureOnly);
            chkAuthorizeNetAim.Checked = store.IsPaymentProviderEnabled(PaymentProviderName.AuthorizeNetAim);
            chkPayPalDirect.Checked    = store.IsPaymentProviderEnabled(PaymentProviderName.PayPalDirectPayment);

            PayLaterPaymentProvider billMeLaterProvider = new PayLaterPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayLater));

            txtPayLaterDisplayText.Text          = billMeLaterProvider.DisplayText;
            txtPayLaterCustomerInstructions.Text = billMeLaterProvider.CustomerInstructions;

            AuthorizeNetAimProvider authorizeNetAimProvider = new AuthorizeNetAimProvider(store.GetPaymentProviderConfig(PaymentProviderName.AuthorizeNetAim));

            chkAuthorizeNetAimTestGateway.Checked      = authorizeNetAimProvider.IsTestGateway;
            chkAuthorizeNetAimTestTransactions.Checked = authorizeNetAimProvider.IsTestTransactions;
            txtAuthorizeNetAimApiLoginId.Text          = authorizeNetAimProvider.ApiLoginId;
            txtAuthorizeNetAimTransactionKey.Text      = authorizeNetAimProvider.TransactionKey;

            PayPalDirectPaymentProvider payPalDirectPayment = new PayPalDirectPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalDirectPayment));

            chkPayPalDirectPaymentIsSandbox.Checked = payPalDirectPayment.IsSandbox;
            txtPayPalDirectPaymentApiUsername.Text  = payPalDirectPayment.ApiUsername;
            txtPayPalDirectPaymentApiPassword.Text  = payPalDirectPayment.ApiPassword;
            txtPayPalDirectPaymentApiSignature.Text = payPalDirectPayment.ApiSignature;

            // OFF-SITE
            chkPayPalStandard.Checked = store.IsPaymentProviderEnabled(PaymentProviderName.PayPalStandard);
            chkPayPalExpress.Checked  = store.IsPaymentProviderEnabled(PaymentProviderName.PayPalExpressCheckout);

            PayPalStandardProvider payPalStandard = new PayPalStandardProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));

            chkPayPalStandardIsSandbox.Checked           = payPalStandard.IsSandbox;
            rdoPayPalStandardShippingLogic.SelectedValue = payPalStandard.ShippingLogic;
            txtPayPalStandardEmail.Text = payPalStandard.EmailAddress;

            PayPalExpressCheckoutPaymentProvider payPalExpressCheckout = new PayPalExpressCheckoutPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalExpressCheckout));

            chkPayPalExpressCheckoutIsSandbox.Checked = payPalExpressCheckout.IsSandbox;
            txtPayPalExpressCheckoutApiUsername.Text  = payPalExpressCheckout.ApiUsername;
            txtPayPalExpressCheckoutApiPassword.Text  = payPalExpressCheckout.ApiPassword;
            txtPayPalExpressCheckoutApiSignature.Text = payPalExpressCheckout.ApiSignature;
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Context.Trace.Write("PayPalIpnHandler called");

            Exceptions.LogException(new Exception("PayPalIpnHandler Called with keys: " + Request.Params.AllKeys.ToCsv()));

            InitializeEntitySpaces();


            int?orderId = WA.Parser.ToInt(Request.Params["custom"]);

            Exceptions.LogException(new Exception("PayPalIpnHandler : Order ID = " + orderId));
            Order pendingOrder = Order.GetOrder(orderId.GetValueOrDefault(-1));

            if (pendingOrder != null)
            {
                Exceptions.LogException(new Exception("PayPalIpnHandler : Found pending order"));
                DataModel.Store        store          = pendingOrder.UpToStoreByStoreId;
                StoreContext           storeContext   = new StoreContext(Request, store.Id.Value);
                PayPalStandardProvider payPalStandard = new PayPalStandardProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));
                if (payPalStandard.IsIpnResponse(Request))
                {
                    Exceptions.LogException(new Exception("PayPalIpnHandler : Is Valid IPN request, processing IPN variables..."));
                    OrderController orderController = new OrderController(storeContext);
                    CheckoutResult  checkoutResult  = orderController.CheckoutWithPayPalStandardCheckout(Request);
                }
                else
                {
                    StringBuilder request = new StringBuilder();
                    foreach (var key in Request.Params.AllKeys)
                    {
                        request.AppendFormat("{0} = {1} <br />{2}", key, Request.Params[key], Environment.NewLine);
                    }

                    Exceptions.LogException(new Exception("PayPalIpnHandler : NOT AN IPN RESPONSE. Request = " + request.ToString()));
                }
            }
            else
            {
                //Exceptions.LogException(new Exception("PayPalIpnHandler : pendingOrder IS NULL!"));
            }
        }
Пример #4
0
        public CheckoutResult CheckoutWithPayPalStandardCheckout(HttpRequest request)
        {
            Order order = null;
            PayPalStandardProvider payPalStandard = new PayPalStandardProvider(storeContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));
            int?orderId;

            if (payPalStandard.IsIpnResponse(request, out orderId))
            {
                // user arrived here through a redirect from PayPal Checkout Page
                // so we have "IPN" variables in the Request that we can process
                order = new Order();
                if (order.LoadByPrimaryKey(orderId.GetValueOrDefault(-1)))
                {
                    Exceptions.LogException(new Exception("Loaded order"));
                    PaymentStatusName paymentStatus = payPalStandard.ProcessOffsitePaymentResponse(order, request);
                    Exceptions.LogException(new Exception("paymentStatus:" + paymentStatus));
                    OrderStatusName orderStatus = order.OrderStatus;
                    Exceptions.LogException(new Exception("orderStatus:" + orderStatus));
                    if (paymentStatus == PaymentStatusName.Completed)
                    {
                        orderStatus          = OrderStatusName.Processing;
                        order.CreditCardType = CreditCardType.PayPal.ToString();
                    }
                    if (order.PaymentStatus != paymentStatus || order.OrderStatus != orderStatus)
                    {
                        Exceptions.LogException(new Exception("Updating Order Status"));
                        UpdateOrderStatus(order, orderStatus, paymentStatus);
                        Exceptions.LogException(new Exception("Updated Order Status"));
                        return(DoPostCheckoutProcessing(order, true));
                    }
                    return(DoPostCheckoutProcessing(order, false));
                }
            }
            else
            {
                Exceptions.LogException(new Exception("NOT AN IPN RESPONSE!"));
            }
            return(null);
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadResourceFileSettings();

            cartController = new CartController(StoreContext);

            checkoutOrderInfo = Session[StoreContext.SessionKeys.CheckoutOrderInfo] as CheckoutOrderInfo ?? new CheckoutOrderInfo()
            {
                Cart = cartController.GetCart(true)
            };
            checkoutOrderInfo.Cart = cartController.GetCart(true);
            checkoutOrderInfo.ReCalculateOrderTotals();

            var payPalStandard = new PayPalStandardProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));

            collectPayPalStandardShipping = payPalStandard.ShippingLogic == "Store" && !checkoutOrderInfo.HasOnlyDownloadableProducts;

            if (!IsPostBack)
            {
                int?removeCartItem = WA.Parser.ToInt(Request.QueryString["remove"]);
                if (removeCartItem.HasValue)
                {
                    RemoveCartItemFromCart(removeCartItem.Value);
                    UpdateCheckoutSession();

                    // redirect so that the "mini-cart" updates on the page also...
                    Response.Redirect(StoreUrls.Cart());
                }
                // FEATURE: Add product to the cart via URL/QueryString
                string addProductSlug = Request.QueryString["add"] ?? string.Empty;
                if (!string.IsNullOrEmpty(addProductSlug))
                {
                    var productToAdd = Product.GetBySlug(StoreContext.CurrentStore.Id.Value, addProductSlug);
                    if (productToAdd != null)
                    {
                        //bool IsAvailableForPurchase = productToAdd.IsAvailableForPurchase.GetValueOrDefault(true) && WA.Parser.ToBool(StoreContext.CurrentStore.GetSetting(StoreSettingNames.EnableCheckout)).GetValueOrDefault(true);
                        bool IsAvailableForPurchase = productToAdd.IsPurchaseableByUser;
                        if (IsAvailableForPurchase)
                        {
                            int quantityToAdd = Request.QueryString["q"] != null?Convert.ToInt32(Request.QueryString["q"]) : 1;

                            cartController.AddProductToCart(productToAdd.Id.Value, quantityToAdd, string.Empty);
                        }
                        checkoutOrderInfo.Cart = cartController.GetCart(false);
                        checkoutOrderInfo.ReCalculateOrderTotals();

                        bool redirectBackToReferrer = WA.Parser.ToBool(Request.QueryString["redirect"]).GetValueOrDefault(false);
                        if (redirectBackToReferrer && (Request.UrlReferrer != null))
                        {
                            string redirectUrl = Request.UrlReferrer.ToString();


                            // Remove previous flash message from querystring when redirecting
                            if (redirectUrl.ToLower().Contains("flash"))
                            {
                                int flashIndex = redirectUrl.IndexOf("flash");
                                redirectUrl = redirectUrl.Substring(0, flashIndex - 1);
                            }

                            bool referrerIsOnsite = (Request.UrlReferrer.Host == Request.Url.Host);
                            if (referrerIsOnsite)
                            {
                                // redirect and add a 'flash' message to notify customer that product was added to cart
                                if (IsAvailableForPurchase)
                                {
                                    redirectUrl = redirectUrl.AddUrlParam("flash", HttpUtility.UrlPathEncode(string.Format(@"""{0}"" has been added to your cart", productToAdd.Name)));
                                }
                                else
                                {
                                    redirectUrl = redirectUrl.AddUrlParam("flash", HttpUtility.UrlPathEncode(string.Format(@"""{0}"" is not available for purchase.", productToAdd.Name)));
                                }
                            }
                            //Response.Redirect(redirectUrl, true);
                            Response.Redirect(redirectUrl);
                        }
                        else
                        {
                            if (IsAvailableForPurchase)
                            {
                                flash.InnerHtml = string.Format(@"""{0}"" has been added to your cart", productToAdd.Name);
                            }
                            else
                            {
                                flash.InnerHtml = string.Format(@"""{0}"" is not available for purchase", productToAdd.Name);
                            }
                            flash.Visible = true;
                        }
                    }
                }

                DataBindCartItems();

                var store = StoreContext.CurrentStore;

                //---- checkout buttons
                bool payLaterPaymentEnabled        = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayLater);
                bool cardCaptureOnlyPaymentEnabled = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.CardCaptureOnly);
                bool authorizeNetAimEnabled        = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.AuthorizeNetAim);
                bool payPalDirectEnabled           = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalDirectPayment);
                bool onsitePaymentProviderEnabled  = payLaterPaymentEnabled || cardCaptureOnlyPaymentEnabled || authorizeNetAimEnabled || payPalDirectEnabled;

                btnCheckoutOnsite.Visible         = onsitePaymentProviderEnabled;
                btnCheckoutPayPalStandard.Visible = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalStandard);
                ibtnPayPalExpressCheckout.Visible = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalExpressCheckout);
                if (btnCheckoutOnsite.Visible && (btnCheckoutPayPalStandard.Visible || ibtnPayPalExpressCheckout.Visible))
                {
                    spnOr.Visible = true;
                }

                //collectPayPalStandardShipping = payPalStandard.ShippingLogic == "Store";
                //payPalStandard = new PayPalStandardProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));)
                if (collectPayPalStandardShipping)
                {
                    string        storeCountry         = store.GetSetting(StoreSettingNames.DefaultCountryCode);
                    var           countries            = DnnHelper.GetCountryListAdoNet();
                    StringBuilder countriesOptionsHtml = new StringBuilder(countries.Count);
                    foreach (var c in countries)
                    {
                        countriesOptionsHtml.AppendFormat(@"<option value=""{0}"" {2}>{1}</option>", c.CountryCode, c.Name, c.CountryCode == storeCountry ? "selected=selected" : string.Empty);
                    }
                    litCountryOptionsHtml.Text = countriesOptionsHtml.ToString();
                }

                //IShippingProvider fedExProvider = ShippingProviderFactory.Get(StoreContext.CurrentStore.Id.Value, ShippingProviderType.FedEx);
                //pnlShippingQuoteForm.Visible = fedExProvider.IsEnabled;
                var shippingServices = StoreContext.CurrentStore.GetEnabledShippingProviders(null, checkoutOrderInfo.Cart.Id);
                if (shippingServices.Count > 0)
                {
                    pnlShippingQuoteForm.Visible = true;
                }

                //----------Show / Hide Coupon Box and Shipping Estimate Boxes

                pnlShippingQuoteForm.Visible = WA.Parser.ToBool(store.GetSetting(StoreSettingNames.ShowShippingEstimate)).GetValueOrDefault(true);
                pnlCouponCodeForm.Visible    = WA.Parser.ToBool(store.GetSetting(StoreSettingNames.ShowCouponBox)).GetValueOrDefault(true);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataModel.Store store = StoreContext.CurrentStore;

            //PaymentProviderName onSitePaymentProvider = WA.Enum<PaymentProviderName>.TryParseOrDefault(Request.Form["enabledOnSiteProvider"], PaymentProviderName.UNKNOWN);
            //PaymentProviderName offSitePaymentProvider = WA.Enum<PaymentProviderName>.TryParseOrDefault(Request.Form["enabledOffSiteProvider"], PaymentProviderName.UNKNOWN);

            if (!onSiteCheckboxes.Exists(x => x.Checked) && !offSiteCheckboxes.Exists(x => x.Checked))
            {
                ShowFlash("<span style='color: Red;'>ERROR - Please choose at least one payment provider.</span>");
                return;
            }

            if (chkAuthorizeNetAim.Checked && chkPayPalDirect.Checked)
            {
                ShowFlash("<span style='color: Red;'>ERROR - Please choose either Authorize.Net OR PayPal Pro (both cannot be selected)</span>");
                return;
            }
            if (chkPayPalStandard.Checked && chkPayPalExpress.Checked)
            {
                ShowFlash("<span style='color: Red;'>ERROR - Please choose either PayPal Standard OR PayPal Express Checkout (both cannot be selected)</span>");
                return;
            }

            //--- ON-Site Payment Providers

            PayLaterPaymentProvider billMeLaterPaymentProvider = new PayLaterPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayLater));

            billMeLaterPaymentProvider.IsEnabled            = chkPayLater.Checked;
            billMeLaterPaymentProvider.DisplayText          = txtPayLaterDisplayText.Text;
            billMeLaterPaymentProvider.CustomerInstructions = txtPayLaterCustomerInstructions.Text;
            store.UpdatePaymentProviderConfig(billMeLaterPaymentProvider.GetConfiguration());

            CardCaptureOnlyPaymentProvider cardCaptureOnlyPaymentProvider = new CardCaptureOnlyPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.CardCaptureOnly));

            cardCaptureOnlyPaymentProvider.IsEnabled = chkCardCaptureOnly.Checked;
            store.UpdatePaymentProviderConfig(cardCaptureOnlyPaymentProvider.GetConfiguration());

            AuthorizeNetAimProvider authorizeNetAimProvider = new AuthorizeNetAimProvider(store.GetPaymentProviderConfig(PaymentProviderName.AuthorizeNetAim));

            authorizeNetAimProvider.IsEnabled          = chkAuthorizeNetAim.Checked;
            authorizeNetAimProvider.IsTestGateway      = chkAuthorizeNetAimTestGateway.Checked;
            authorizeNetAimProvider.IsTestTransactions = chkAuthorizeNetAimTestTransactions.Checked;
            authorizeNetAimProvider.ApiLoginId         = txtAuthorizeNetAimApiLoginId.Text;
            authorizeNetAimProvider.TransactionKey     = txtAuthorizeNetAimTransactionKey.Text;
            store.UpdatePaymentProviderConfig(authorizeNetAimProvider.GetConfiguration());

            PayPalDirectPaymentProvider payPalDirectPayment = new PayPalDirectPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalDirectPayment));

            payPalDirectPayment.IsEnabled    = chkPayPalDirect.Checked;
            payPalDirectPayment.IsSandbox    = chkPayPalDirectPaymentIsSandbox.Checked;
            payPalDirectPayment.ApiUsername  = txtPayPalDirectPaymentApiUsername.Text;
            payPalDirectPayment.ApiPassword  = txtPayPalDirectPaymentApiPassword.Text;
            payPalDirectPayment.ApiSignature = txtPayPalDirectPaymentApiSignature.Text;
            store.UpdatePaymentProviderConfig(payPalDirectPayment.GetConfiguration());


            //--- OFF-Site Payment Providers

            PayPalStandardProvider payPalStandard = new PayPalStandardProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));

            payPalStandard.IsEnabled     = chkPayPalStandard.Checked;
            payPalStandard.IsSandbox     = chkPayPalStandardIsSandbox.Checked;
            payPalStandard.ShippingLogic = rdoPayPalStandardShippingLogic.SelectedValue;
            payPalStandard.EmailAddress  = txtPayPalStandardEmail.Text;
            store.UpdatePaymentProviderConfig(payPalStandard.GetConfiguration());

            PayPalExpressCheckoutPaymentProvider payPalExpressCheckout = new PayPalExpressCheckoutPaymentProvider(store.GetPaymentProviderConfig(PaymentProviderName.PayPalExpressCheckout));

            payPalExpressCheckout.IsEnabled    = chkPayPalExpress.Checked;
            payPalExpressCheckout.IsSandbox    = chkPayPalExpressCheckoutIsSandbox.Checked;
            payPalExpressCheckout.ApiUsername  = txtPayPalExpressCheckoutApiUsername.Text;
            payPalExpressCheckout.ApiPassword  = txtPayPalExpressCheckoutApiPassword.Text;
            payPalExpressCheckout.ApiSignature = txtPayPalExpressCheckoutApiSignature.Text;
            store.UpdatePaymentProviderConfig(payPalExpressCheckout.GetConfiguration());

            Response.Redirect(StoreUrls.AdminWithFlash(ModuleDefs.Admin.Views.PaymentMethods, "Payment Settings Saved Successfully"));
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            pnlOrderDetails.Visible = false;
            LoadResourceFileSettings();

            if (!IsPostBack)
            {
                PayPalStandardProvider payPalStandard =
                    new PayPalStandardProvider(
                        StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));
                bool isPayPalIpn            = false;
                bool isPayPalReferrer       = false;
                bool isPayPalStandardReturn = false;

                if (payPalStandard.IsEnabled)
                {
                    isPayPalIpn      = payPalStandard.IsIpnResponse(Request);
                    isPayPalReferrer = (Request.UrlReferrer != null)
                                           ? Request.UrlReferrer.ToString().Contains("paypal.com")
                                           : false;
                    isPayPalStandardReturn = Request.Params["ppstdreturn"] != null;
                }

                Guid?completedOrderId = WA.Parser.ToGuid(Request.Params["dsoid"]);
                if (completedOrderId.HasValue && !(isPayPalReferrer || isPayPalIpn))
                {
                    // load an on-site order
                    OrderQuery q = new OrderQuery();
                    q.Where(q.CreatedFromCartId == completedOrderId.Value);
                    q.es.Top = 1;
                    order.Load(q);
                }
                else if (isPayPalReferrer || isPayPalIpn)
                {
                    OrderController orderController = new OrderController(StoreContext);
                    CheckoutResult  checkoutResult  = orderController.CheckoutWithPayPalStandardCheckout(Request);
                    if (checkoutResult != null)
                    {
                        order = checkoutResult.SubmittedOrder;
                    }
                }

                //bool clientHasCartIdCookie = order.CreatedFromCartId.Value == StoreContext.CartId;

                //if (UserInfo.IsSuperUser || UserInfo.IsInRole("Administrator") || UserInfo.UserID == order.UserId)
                //if (UserInfo.IsSuperUser || UserInfo.IsInRole("Administrator") || clientHasCartIdCookie)
                //{
                pnlOrderDetails.Visible = true;
                pnlOrderReceipt.Visible = true;



                if (order.Id.HasValue)
                {
                    ShowDigitalDownloads();

                    if (order.PaymentStatus == PaymentStatusName.Pending)
                    {
                        pnlDigitalDownloads.Visible = false;
                    }

                    if (isPayPalStandardReturn)
                    {
                        pnlOrderReceipt.Visible = false;
                    }
                    else
                    {
                        LoadOrderReceipt();
                    }
                }
                else
                {
                    //ShowFlash("Unable to find order");
                    //flash.Text = "Unable to find order";
                    ShowFlash("Could not load Order from DB");
                    //flash.Text = "Could not load Order from DB";
                    pnlOrderReceipt.Visible     = false;
                    pnlDigitalDownloads.Visible = false;
                }
                //}
            }
        }