Пример #1
0
        public OrderProcessingViewModel ProcessOrderBeforePayment(ShoppingCartViewModel cart, CheckoutInputModel checkout)
        {
            var response = new OrderProcessingViewModel();
            
            // 1. Save checkout data as part of the customer record (shipping & payment).
            //    This is a bit simplistic as shipping address and payment details should be both on Customer
            //    (to set default options) and Order (to be part of the history).
            var address = Address.Create(checkout.Address, "", checkout.City, "", checkout.Country);
            var payment = CreditCard.Create(checkout.CardType, checkout.CardNumber, "", new ExpiryDate(checkout.Month, checkout.Year));
            _requestService.SaveCheckoutInformation(cart.OrderRequest, address, payment);


            // 2. Goods in store (precheck to give users a chance not to place an order that may take a while to 
            //    be completed and served. Most sites just make you pay and place an order for missing items while
            //    giving you a chance to cancel the order at any time.
            var stock = _requestService.CheckStockLevelForOrderedItems(cart.OrderRequest);
            if (stock.Insufficient.Any())
            {
                response.Denied = true;
                response.AddMessage("It seems that we don't have available all the items you ordered. What would you like to do? Buying a bit less or trying later?");
                return response;
            }

            // 3. Payment history for the customer
            //    Probably not really an appropriate scenario for this simple store: if the online store accept
            //    payment cash-on-delivery, however, you might want to enable it only for customers with a
            //    positive payment history.
            if (!_requestService.CheckCustomerPaymentHistory(cart.OrderRequest.Buyer.CustomerId))
            {
                response.Denied = true;
                response.AddMessage("We've found something incorrect in your record that prevents our system from processing your order. Please, contact our customer care.");
                return response;
            }

            // 4. Refill stock
            var productsToOrder = new List<Product>();
            productsToOrder.AddRange(stock.Low);
            productsToOrder.AddRange(stock.Insufficient);
            _requestService.RefillStoreForProduct(productsToOrder);

            return response;
        }
 public ProcessOrderBeforePaymentCommand(ShoppingCartViewModel cart, CheckoutInputModel checkout)
 {
     ShoppingCart = cart;
     CheckoutData = checkout;
 }
Пример #3
0
        public ActionResult Checkout(CheckoutInputModel checkout)
        {
            // Pre-payment steps
            var cart = RetrieveCurrentShoppingCart();
            var response = _service.ProcessOrderBeforePayment(cart, checkout);
            if (!response.Denied)
            {
                return Redirect(Url.Content("~/fake_payment.aspx?"));
            }

            TempData["ibuy-stuff:denied"] = response;
            return RedirectToAction("Denied");            
        }
Пример #4
0
 public ActionResult Checkout(CheckoutInputModel checkout)
 {
     // Pre-payment steps
     var cart = RetrieveCurrentShoppingCart();           
     var command = new ProcessOrderBeforePaymentCommand(cart, checkout);
     var response = CommandProcessor.Send<ProcessOrderBeforePaymentCommand, OrderProcessingViewModel>(command);
     if (!response.Denied)
     {
         return Redirect(Url.Content("~/fake_payment.aspx?"));
     }
     
     TempData["ibuy-stuff:denied"] = response;
     return RedirectToAction("Denied"); 
 }