예제 #1
0
        public ActionResult Purchase(CheckoutViewModel viewModel, IPaymentOption paymentOption)
        {
            if (CartIsNullOrEmpty())
            {
                return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
            }

            // Since the payment property is marked with an exclude binding attribute in the CheckoutViewModel
            // it needs to be manually re-added again.
            viewModel.Payment = paymentOption;

            if (User.Identity.IsAuthenticated)
            {
                _checkoutService.CheckoutAddressHandling.UpdateAuthenticatedUserAddresses(viewModel);

                var validation = _checkoutService.AuthenticatedPurchaseValidation;

                if (!validation.ValidateModel(ModelState, viewModel) ||
                    !validation.ValidateOrderOperation(ModelState, _cartService.ValidateCart(Cart)) ||
                    !validation.ValidateOrderOperation(ModelState, _cartService.RequestInventory(Cart)))
                {
                    return(View(viewModel));
                }
            }
            else
            {
                _checkoutService.CheckoutAddressHandling.UpdateAnonymousUserAddresses(viewModel);

                var validation = _checkoutService.AnonymousPurchaseValidation;

                if (!validation.ValidateModel(ModelState, viewModel) ||
                    !validation.ValidateOrderOperation(ModelState, _cartService.ValidateCart(Cart)) ||
                    !validation.ValidateOrderOperation(ModelState, _cartService.RequestInventory(Cart)))
                {
                    return(View(viewModel));
                }
            }

            if (!paymentOption.ValidateData())
            {
                return(View(viewModel));
            }

            _checkoutService.UpdateShippingAddresses(Cart, viewModel);

            _checkoutService.CreateAndAddPaymentToCart(Cart, viewModel);

            var purchaseOrder = _checkoutService.PlaceOrder(Cart, ModelState, viewModel);

            if (purchaseOrder == null)
            {
                return(View(viewModel));
            }

            var confirmationSentSuccessfully = _checkoutService.SendConfirmation(viewModel, purchaseOrder);

            _recommendationService.SendOrderTracking(HttpContext, purchaseOrder);

            return(Redirect(_checkoutService.BuildRedirectionUrl(viewModel, purchaseOrder, confirmationSentSuccessfully)));
        }
        public ActionResult Purchase(CheckoutViewModel viewModel, IPaymentOption paymentOption)
        {
            if (CartIsNullOrEmpty())
            {
                return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
            }

            // Since the payment property is marked with an exclude binding attribute in the CheckoutViewModel
            // it needs to be manually re-added again.
            viewModel.Payment = paymentOption;

            viewModel.IsAuthenticated = User.Identity.IsAuthenticated;

            _checkoutService.CheckoutAddressHandling.UpdateUserAddresses(viewModel);
            if (!_checkoutService.ValidateOrder(ModelState, viewModel, _cartService.ValidateCart(Cart)))
            {
                return(View(viewModel));
            }

            if (!paymentOption.ValidateData())
            {
                return(View(viewModel));
            }

            _checkoutService.UpdateShippingAddresses(Cart, viewModel);

            _checkoutService.CreateAndAddPaymentToCart(Cart, viewModel);

            var purchaseOrder = _checkoutService.PlaceOrder(Cart, ModelState, viewModel);

            if (!string.IsNullOrEmpty(viewModel.RedirectUrl))
            {
                return(Redirect(viewModel.RedirectUrl));
            }

            if (purchaseOrder == null)
            {
                return(View(viewModel));
            }

            var confirmationSentSuccessfully = _checkoutService.SendConfirmation(viewModel, purchaseOrder);

            if (Request.IsAjaxRequest())
            {
                return(Json(new { Url = _checkoutService.BuildRedirectionUrl(viewModel, purchaseOrder, confirmationSentSuccessfully) }));
            }
            return(Redirect(_checkoutService.BuildRedirectionUrl(viewModel, purchaseOrder, confirmationSentSuccessfully)));
        }
예제 #3
0
        /// <summary>
        /// Validates the data.
        /// </summary>
        /// <returns></returns>
        public bool ValidateData()
        {
            bool isValid = false;

            PaymentMethodDto.PaymentMethodRow paymentRow = PaymentMethod;
            if (paymentRow != null)
            {
                IPaymentOption po = FindPaymentControl(paymentRow.SystemKeyword);
                if (po != null)
                {
                    isValid = po.ValidateData();
                }
            }

            return(isValid & RadioButtonsPaymentCustomValidator.IsValid);
        }