public ActionResult Index(CheckoutViewModel model)
        {
            var cart = cartProvider.GetCart();
            var contactDataCollection = contactDataProvider.GetContactData();

            ViewBag.CheckVAT = !String.IsNullOrEmpty(vatDataProvider.VatNumber);

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                if (!RecaptchaHelper.IsResponseValid(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("recaptcha", this.GlobalCommonResource("RecaptchaVerificationFaild"));
                }
            }

            if (cart.IsEmpty())
            {
                ModelState.AddModelError("cart", "Cart is empty");
            }
            else if (contactDataCollection == null)
            {
                ModelState.AddModelError("contactData", "Contact data is empty");
            }

            if (ModelState.IsValid)
            {
                // Recalculate cart one last time, to make sure e.g. setup fees are still there.
                cartPricingService.CalculatePricing(cart);

                var paymentData = new PaymentData
                {
                    Id          = model.SelectedPaymentMethod.Id,
                    PaymentForm = model.SelectedPaymentMethod.Form,
                    SaveCcInfo  = model.SelectedPaymentMethod.SupportsPaymentProfile && model.SaveCcInfo,
                    AutoPay     = model.SelectedPaymentMethod.SupportsPaymentProfile && model.AutoPay
                };

                var orderContext = new OrderContext(cart, contactDataCollection, paymentData, new object[] { Request });
                var result       = orderPlacementService.PlaceOrder(orderContext);

                if (result.RedirectUrl == urlProvider.SuccessUrl)
                {
                    contactDataProvider.ClearContactData();
                    cartProvider.ClearCart();
                }

                return(Redirect(result.RedirectUrl));
            }

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                ViewBag.RecaptchaEnabled = true;
                ViewBag.RecaptchaSiteKey = RecaptchaHelper.GetSiteKey();
            }

            ViewData["formHasErrors"] = true;
            return(View(model));
        }
        public ActionResult Index()
        {
            // Make sure cart is properly calculated.
            var cart = cartProvider.GetCart();

            cartPricingService.CalculatePricing(cart);

            // If VAT number was submitted, indicate a VAT check should be made
            ViewBag.CheckVAT = !string.IsNullOrEmpty(vatDataProvider.VatNumber);
            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                ViewBag.RecaptchaEnabled = true;
                ViewBag.RecaptchaSiteKey = RecaptchaHelper.GetSiteKey();
            }

            var model = DependencyResolver.Current.GetService <CheckoutViewModel>();

            ViewData["formHasErrors"] = false;

            return(View(model));
        }