public ActionResult Index(CheckoutViewModel model) { var cart = cartProvider.GetCart(); var contactDataCollection = contactDataProvider.GetContactData(); 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); return Redirect(result.RedirectUrl); } return View(model); }
/// <summary> /// Place the order with data collected in the provided <see cref="Atomia.Store.Core.OrderContext"/>. /// </summary> /// <param name="orderContext">Context with cart, contact and other relevant data.</param> /// <returns>The results of placing the order</returns> public OrderResult PlaceOrder(OrderContext orderContext) { var publicOrderContext = new PublicOrderContext(orderContext); // Add some extra data that might be needed by order handlers. foreach (var cartItem in orderContext.Cart.CartItems) { var product = productProvider.GetProduct(cartItem.ArticleNumber); var renewalPeriodId = renewalPeriodProvider.GetRenewalPeriodId(cartItem); publicOrderContext.AddItemData(new ItemData(cartItem, product, renewalPeriodId)); } var paymentHandler = paymentDataHandlers.FirstOrDefault(h => h.Id == orderContext.PaymentData.Id); if (paymentHandler == null) { throw new InvalidOperationException(String.Format("Payment data handler is not available for {0}.", orderContext.PaymentData.Id)); } var createdOrder = orderCreator.CreateOrder(publicOrderContext, paymentHandler); var redirectUrl = urlProvider.SuccessUrl; if (paymentHandler.PaymentMethodType == PaymentMethodEnum.PayByCard && createdOrder.Total > Decimal.Zero) { redirectUrl = paymentTransactionCreator.CreatePaymentTransaction(publicOrderContext, createdOrder, paymentHandler); } return new OrderResult { RedirectUrl = redirectUrl }; }
/// <summary> /// Create new instance with the basic order data collected from customer. /// </summary> public PublicOrderContext(OrderContext orderContext) { if (orderContext == null) { throw new ArgumentNullException("orderContext"); } this.orderContext = orderContext; }
public OrderResult PlaceOrder(OrderContext orderContext) { return new OrderResult { RedirectUrl = urlProvider.SuccessUrl }; }