Пример #1
0
        protected CheckoutConfirmModel PrepareConfirmOrderModel(IList <OrganizedShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            //min order amount validation
            bool minOrderTotalAmountOk = _orderProcessingService.ValidateMinOrderTotalAmount(cart);

            if (!minOrderTotalAmountOk)
            {
                decimal minOrderTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderTotalAmount, _workContext.WorkingCurrency);
                model.MinOrderTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderTotalAmount"), _priceFormatter.FormatPrice(minOrderTotalAmount, true, false));
            }

            model.TermsOfServiceEnabled      = _orderSettings.TermsOfServiceEnabled;
            model.ShowEsdRevocationWaiverBox = _shoppingCartSettings.ShowEsdRevocationWaiverBox;
            model.BypassPaymentMethodInfo    = _paymentSettings.BypassPaymentMethodInfo;
            model.NewsLetterSubscription     = _shoppingCartSettings.NewsLetterSubscription;
            model.ThirdPartyEmailHandOver    = _shoppingCartSettings.ThirdPartyEmailHandOver;

            if (_shoppingCartSettings.ThirdPartyEmailHandOver != CheckoutThirdPartyEmailHandOver.None)
            {
                model.ThirdPartyEmailHandOverLabel = _shoppingCartSettings.GetLocalized(x => x.ThirdPartyEmailHandOverLabel, _workContext.WorkingLanguage, true, false);

                if (model.ThirdPartyEmailHandOverLabel.IsEmpty())
                {
                    model.ThirdPartyEmailHandOverLabel = T("Admin.Configuration.Settings.ShoppingCart.ThirdPartyEmailHandOverLabel.Default");
                }
            }

            return(model);
        }
Пример #2
0
        /// <summary>
        /// Prepare confirm order model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <returns>Confirm order model</returns>
        public virtual CheckoutConfirmModel PrepareConfirmOrderModel(IList <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel
            {
                //terms of service
                TermsOfServiceOnOrderConfirmPage = _orderSettings.TermsOfServiceOnOrderConfirmPage,
                TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks
            };
            //min order amount validation
            var minOrderTotalAmountOk = _orderProcessingService.ValidateMinOrderTotalAmount(cart);

            if (!minOrderTotalAmountOk)
            {
                var minOrderTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderTotalAmount, _workContext.WorkingCurrency);
                model.MinOrderTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderTotalAmount"), _priceFormatter.FormatPrice(minOrderTotalAmount, true, false));
            }
            //load payment method
            var paymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute <string>(
                SystemCustomerAttributeNames.SelectedPaymentMethod,
                _genericAttributeService, _storeContext.CurrentStore.Id);
            var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(paymentMethodSystemName);

            if (paymentMethod != null)
            {
                paymentMethod.GetPublicViewComponent(out string viewComponentName);
                model.PaymentViewComponentName = viewComponentName;
            }
            return(model);
        }
Пример #3
0
        protected CheckoutConfirmModel PrepareConfirmOrderModel(IList <OrganizedShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            // Minimum order totals validation
            var customerRoleIds = _workContext.CurrentCustomer.GetRoleIds();

            var(isAboveMinimumOrderTotal, orderTotalMinimum) = _orderProcessingService.IsAboveOrderTotalMinimum(cart, customerRoleIds);
            if (!isAboveMinimumOrderTotal)
            {
                orderTotalMinimum = _currencyService.ConvertFromPrimaryStoreCurrency(
                    orderTotalMinimum,
                    _workContext.WorkingCurrency);

                var resource = _orderSettings.ApplyToSubtotal ? "Checkout.MinOrderSubtotalAmount" : "Checkout.MinOrderTotalAmount";
                model.OrderAmountWarning = string.Format(
                    _localizationService.GetResource(resource),
                    _priceFormatter.FormatPrice(orderTotalMinimum, true, false));
            }

            // Maximum order totals validation
            var(isBelowOrderTotalMaximum, orderTotalMaximum) = _orderProcessingService.IsBelowOrderTotalMaximum(cart, customerRoleIds);
            if (isAboveMinimumOrderTotal && !isBelowOrderTotalMaximum)
            {
                orderTotalMaximum = _currencyService.ConvertFromPrimaryStoreCurrency(
                    orderTotalMaximum,
                    _workContext.WorkingCurrency);

                var resource = _orderSettings.ApplyToSubtotal ? "Checkout.MaxOrderSubtotalAmount" : "Checkout.MaxOrderTotalAmount";
                model.OrderAmountWarning = string.Format(
                    _localizationService.GetResource(resource),
                    _priceFormatter.FormatPrice(orderTotalMaximum, true, false));
            }

            model.TermsOfServiceEnabled      = _orderSettings.TermsOfServiceEnabled;
            model.ShowEsdRevocationWaiverBox = _shoppingCartSettings.ShowEsdRevocationWaiverBox;
            model.BypassPaymentMethodInfo    = _paymentSettings.BypassPaymentMethodInfo;
            model.NewsLetterSubscription     = _shoppingCartSettings.NewsLetterSubscription;
            model.ThirdPartyEmailHandOver    = _shoppingCartSettings.ThirdPartyEmailHandOver;

            if (_shoppingCartSettings.ThirdPartyEmailHandOver != CheckoutThirdPartyEmailHandOver.None)
            {
                model.ThirdPartyEmailHandOverLabel = _shoppingCartSettings.GetLocalizedSetting(x => x.ThirdPartyEmailHandOverLabel, _workContext.WorkingLanguage, _storeContext.CurrentStore.Id, true, false);

                if (model.ThirdPartyEmailHandOverLabel.IsEmpty())
                {
                    model.ThirdPartyEmailHandOverLabel = T("Admin.Configuration.Settings.ShoppingCart.ThirdPartyEmailHandOverLabel.Default");
                }
            }

            return(model);
        }
        public CheckoutConfirmModel PrepareConfirmOrderModel(IList <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();
            //min order amount validation
            bool minOrderTotalAmountOk = _orderProcessingService.ValidateMinOrderTotalAmount(cart);

            if (!minOrderTotalAmountOk)
            {
                decimal minOrderTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderTotalAmount, _workContext.WorkingCurrency);
                model.MinOrderTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderTotalAmount"), _priceFormatter.FormatPrice(minOrderTotalAmount, true, false));
            }
            return(model);
        }
Пример #5
0
        protected CheckoutConfirmModel PrepareConfirmOrderModel(IList<OrganizedShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();
            //min order amount validation
            bool minOrderTotalAmountOk = _orderProcessingService.ValidateMinOrderTotalAmount(cart);
            if (!minOrderTotalAmountOk)
            {
                decimal minOrderTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderTotalAmount, _workContext.WorkingCurrency);
                model.MinOrderTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderTotalAmount"), _priceFormatter.FormatPrice(minOrderTotalAmount, true, false));
            }

            model.TermsOfServiceEnabled = _orderSettings.TermsOfServiceEnabled;
            model.ShowConfirmOrderLegalHint = _shoppingCartSettings.ShowConfirmOrderLegalHint;
            model.BypassPaymentMethodInfo = _paymentSettings.BypassPaymentMethodInfo;
            return model;
        }
Пример #6
0
        /// <summary>
        /// Prepare confirm subscription model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <returns>Confirm subscription model</returns>
        public virtual CheckoutConfirmModel PrepareConfirmSubscriptionModel(IList <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            //terms of service
            model.TermsOfServiceOnSubscriptionConfirmPage = _subscriptionSettings.TermsOfServiceOnSubscriptionConfirmPage;
            //min subscription amount validation
            bool minSubscriptionTotalAmountOk = _subscriptionProcessingService.ValidateMinSubscriptionTotalAmount(cart);

            if (!minSubscriptionTotalAmountOk)
            {
                decimal minSubscriptionTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_subscriptionSettings.MinSubscriptionTotalAmount, _workContext.WorkingCurrency);
                model.MinSubscriptionTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinSubscriptionTotalAmount"), _priceFormatter.FormatPrice(minSubscriptionTotalAmount, true, false));
            }
            return(model);
        }
Пример #7
0
        /// <summary>
        /// Prepare confirm order model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <returns>Confirm order model</returns>
        public virtual CheckoutConfirmModel PrepareConfirmOrderModel(IList <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            //terms of service
            model.TermsOfServiceOnOrderConfirmPage = _orderSettings.TermsOfServiceOnOrderConfirmPage;
            model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
            //min order amount validation
            var minOrderTotalAmountOk = _orderProcessingService.ValidateMinOrderTotalAmount(cart);

            if (!minOrderTotalAmountOk)
            {
                var minOrderTotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderTotalAmount, _workContext.WorkingCurrency);
                model.MinOrderTotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderTotalAmount"), _priceFormatter.FormatPrice(minOrderTotalAmount, true, false));
            }
            return(model);
        }
        /// <summary>
        /// Prepare confirm order model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the confirm order model
        /// </returns>
        public virtual async Task <CheckoutConfirmModel> PrepareConfirmOrderModelAsync(IList <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel
            {
                //terms of service
                TermsOfServiceOnOrderConfirmPage = _orderSettings.TermsOfServiceOnOrderConfirmPage,
                TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks
            };
            //min order amount validation
            var minOrderTotalAmountOk = await _orderProcessingService.ValidateMinOrderTotalAmountAsync(cart);

            if (!minOrderTotalAmountOk)
            {
                var minOrderTotalAmount = await _currencyService.ConvertFromPrimaryStoreCurrencyAsync(_orderSettings.MinOrderTotalAmount, await _workContext.GetWorkingCurrencyAsync());

                model.MinOrderTotalWarning = string.Format(await _localizationService.GetResourceAsync("Checkout.MinOrderTotalAmount"), await _priceFormatter.FormatPriceAsync(minOrderTotalAmount, true, false));
            }
            return(model);
        }
Пример #9
0
        protected CheckoutConfirmModel PrepareConfirmOrderModel(IList <OrganizedShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel
            {
                TermsOfServiceEnabled      = _orderSettings.TermsOfServiceEnabled,
                ShowEsdRevocationWaiverBox = _shoppingCartSettings.ShowEsdRevocationWaiverBox,
                BypassPaymentMethodInfo    = _paymentSettings.BypassPaymentMethodInfo,
                NewsLetterSubscription     = _shoppingCartSettings.NewsLetterSubscription,
                ThirdPartyEmailHandOver    = _shoppingCartSettings.ThirdPartyEmailHandOver
            };

            if (_shoppingCartSettings.ThirdPartyEmailHandOver != CheckoutThirdPartyEmailHandOver.None)
            {
                model.ThirdPartyEmailHandOverLabel = _shoppingCartSettings.GetLocalizedSetting(x => x.ThirdPartyEmailHandOverLabel, _workContext.WorkingLanguage, _storeContext.CurrentStore.Id, true, false);

                if (model.ThirdPartyEmailHandOverLabel.IsEmpty())
                {
                    model.ThirdPartyEmailHandOverLabel = T("Admin.Configuration.Settings.ShoppingCart.ThirdPartyEmailHandOverLabel.Default");
                }
            }

            return(model);
        }
Пример #10
0
        public ActionResult ConfirmOrder(CheckoutConfirmModel model)
        {
            //validation
            var cart = _paymentStripeCheckoutService.GetCart();

            if (cart.Count == 0)
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            if (!_paymentStripeCheckoutService.IsAllowedToCheckout())
            {
                return(new HttpUnauthorizedResult());
            }

            //model
            var checkoutPlaceOrderModel = _paymentStripeCheckoutPlaceOrderService.PlaceOrder();

            if (checkoutPlaceOrderModel.RedirectToCart)
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            if (checkoutPlaceOrderModel.IsRedirected)
            {
                return(Content("Redirected"));
            }

            if (checkoutPlaceOrderModel.CompletedId.HasValue)
            {
                return(RedirectToRoute("CheckoutCompleted", new { orderId = checkoutPlaceOrderModel.CompletedId }));
            }

            //If we got this far, something failed, redisplay form
            return(View("~/Plugins/Payments.Stripe/Views/Confirm.cshtml", checkoutPlaceOrderModel));
        }
Пример #11
0
        public ActionResult ConfirmOrder(FormCollection form)
        {
            //validation
            var storeId  = _storeContext.CurrentStore.Id;
            var customer = _workContext.CurrentCustomer;
            var cart     = customer.GetCartItems(ShoppingCartType.ShoppingCart, storeId);

            if (cart.Count == 0)
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            if ((customer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = new CheckoutConfirmModel();
            PlaceOrderResult          placeOrderResult          = null;
            PostProcessPaymentRequest postProcessPaymentRequest = null;

            try
            {
                var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                if (processPaymentRequest == null)
                {
                    //Check whether payment workflow is required
                    if (IsPaymentWorkflowRequired(cart))
                    {
                        return(RedirectToAction("PaymentMethod"));
                    }

                    processPaymentRequest = new ProcessPaymentRequest();
                }

                //prevent 2 orders being placed within an X seconds time frame
                if (!IsMinimumOrderPlacementIntervalValid(customer))
                {
                    throw new Exception(T("Checkout.MinOrderPlacementInterval"));
                }

                //place order
                processPaymentRequest.StoreId    = storeId;
                processPaymentRequest.CustomerId = customer.Id;
                processPaymentRequest.PaymentMethodSystemName = customer.GetAttribute <string>(SystemCustomerAttributeNames.SelectedPaymentMethod, _genericAttributeService, storeId);

                var placeOrderExtraData = new Dictionary <string, string>();
                placeOrderExtraData["CustomerComment"]               = form["customercommenthidden"];
                placeOrderExtraData["SubscribeToNewsLetter"]         = form["SubscribeToNewsLetterHidden"];
                placeOrderExtraData["AcceptThirdPartyEmailHandOver"] = form["AcceptThirdPartyEmailHandOverHidden"];

                placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest, placeOrderExtraData);

                if (!placeOrderResult.Success)
                {
                    model.Warnings.AddRange(placeOrderResult.Errors.Select(x => HtmlUtils.ConvertPlainTextToHtml(x)));
                }
            }
            catch (Exception exception)
            {
                Logger.Warn(exception, exception.Message);

                if (!model.Warnings.Any(x => x == exception.Message))
                {
                    model.Warnings.Add(exception.Message);
                }
            }

            if (placeOrderResult == null || !placeOrderResult.Success || model.Warnings.Any())
            {
                return(View(model));
            }

            try
            {
                postProcessPaymentRequest = new PostProcessPaymentRequest
                {
                    Order = placeOrderResult.PlacedOrder
                };

                _paymentService.PostProcessPayment(postProcessPaymentRequest);
            }
            catch (Exception exception)
            {
                NotifyError(exception);
            }
            finally
            {
                _httpContext.Session["OrderPaymentInfo"] = null;
                _httpContext.RemoveCheckoutState();
            }

            if (postProcessPaymentRequest != null && postProcessPaymentRequest.RedirectUrl.HasValue())
            {
                return(Redirect(postProcessPaymentRequest.RedirectUrl));
            }

            return(RedirectToAction("Completed"));
        }
Пример #12
0
        public ActionResult ConfirmOrder(FormCollection form)
        {
            //validation
            var cart = _workContext.CurrentCustomer.GetCartItems(ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id);

            if (cart.Count == 0)
                return RedirectToRoute("ShoppingCart");

            if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
                return new HttpUnauthorizedResult();

            //model
            var model = new CheckoutConfirmModel();
            try
            {
                bool isPaymentPaymentWorkflowRequired = IsPaymentWorkflowRequired(cart);

                var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                if (processPaymentRequest == null)
                {
                    //Check whether payment workflow is required
                    if (isPaymentPaymentWorkflowRequired)
                        return RedirectToAction("PaymentMethod");

                    processPaymentRequest = new ProcessPaymentRequest();
                }

                //prevent 2 orders being placed within an X seconds time frame
                if (!IsMinimumOrderPlacementIntervalValid(_workContext.CurrentCustomer))
                    throw new Exception(_localizationService.GetResource("Checkout.MinOrderPlacementInterval"));

                //place order
                processPaymentRequest.StoreId = _storeContext.CurrentStore.Id;
                processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id;
                processPaymentRequest.PaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(
                     SystemCustomerAttributeNames.SelectedPaymentMethod, _genericAttributeService, _storeContext.CurrentStore.Id);

                var placeOrderExtraData = new Dictionary<string, string>();
                placeOrderExtraData["CustomerComment"] = form["customercommenthidden"];

                var placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest, placeOrderExtraData);

                if (placeOrderResult.Success)
                {
                    if (isPaymentPaymentWorkflowRequired)
                    {
                        var postProcessPaymentRequest = new PostProcessPaymentRequest()
                        {
                            Order = placeOrderResult.PlacedOrder
                        };
                        _paymentService.PostProcessPayment(postProcessPaymentRequest);
                    }

                    _httpContext.Session["PaymentData"] = null;
                    _httpContext.Session["OrderPaymentInfo"] = null;
                    _httpContext.RemoveCheckoutState();

                    if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
                    {
                        //redirection or POST has been done in PostProcessPayment
                        return Content("Redirected");
                    }
                    else
                    {
                        //if no redirection has been done (to a third-party payment page)
                        //theoretically it's not possible
                        return RedirectToAction("Completed");
                    }
                }
                else
                {
                    foreach (var error in placeOrderResult.Errors)
                        model.Warnings.Add(error);
                }
            }
            catch (Exception exc)
            {
                Logger.Warning(exc.Message, exc);
                model.Warnings.Add(exc.Message);
            }

            //If we got this far, something failed, redisplay form

            //if (model.Warnings.Count > 0)
            //	TempData["ConfirmOrderWarnings"] = model.Warnings;

            //return RedirectToRoute("CheckoutConfirm");
            return View(model);
        }
Пример #13
0
        private CheckoutConfirmModel PrepareConfirmOrderModel(IOrderedEnumerable <ShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            return(model);
        }