public ActionResult ConfirmOrder() { //validation var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .ToList(); if (cart.Count == 0) return RedirectToRoute("ShoppingCart"); if (UseOnePageCheckout()) return RedirectToRoute("CheckoutOnePage"); if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed)) return new HttpUnauthorizedResult(); //model var model = new CheckoutConfirmModel(); try { var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest; if (processPaymentRequest == null) { //Check whether payment workflow is required if (IsPaymentWorkflowRequired(cart)) return RedirectToRoute("CheckoutPaymentInfo"); else 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 placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest); if (placeOrderResult.Success) { _httpContext.Session["OrderPaymentInfo"] = null; var postProcessPaymentRequest = new PostProcessPaymentRequest() { Order = placeOrderResult.PlacedOrder }; _paymentService.PostProcessPayment(postProcessPaymentRequest); if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone) { //redirection or POST has been done in PostProcessPayment return Content("Redirected"); } else { return RedirectToRoute("CheckoutCompleted", new { orderId = placeOrderResult.PlacedOrder.Id }); } } 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 return View(model); }
public ActionResult OpcConfirmOrder() { try { //validation var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .ToList(); if (cart.Count == 0) throw new Exception("Your cart is empty"); if (!UseOnePageCheckout()) throw new Exception("One page checkout is disabled"); if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed)) throw new Exception("Anonymous checkout is not allowed"); //prevent 2 orders being placed within an X seconds time frame if (!IsMinimumOrderPlacementIntervalValid(_workContext.CurrentCustomer)) throw new Exception(_localizationService.GetResource("Checkout.MinOrderPlacementInterval")); //place order var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest; if (processPaymentRequest == null) { //Check whether payment workflow is required if (IsPaymentWorkflowRequired(cart)) { throw new Exception("Payment information is not entered"); } else processPaymentRequest = new ProcessPaymentRequest(); } processPaymentRequest.StoreId = _storeContext.CurrentStore.Id; processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id; processPaymentRequest.PaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>( SystemCustomerAttributeNames.SelectedPaymentMethod, _genericAttributeService, _storeContext.CurrentStore.Id); var placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest); if (placeOrderResult.Success) { _httpContext.Session["OrderPaymentInfo"] = null; var postProcessPaymentRequest = new PostProcessPaymentRequest() { Order = placeOrderResult.PlacedOrder }; var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(placeOrderResult.PlacedOrder.PaymentMethodSystemName); if (paymentMethod != null) { if (paymentMethod.PaymentMethodType == PaymentMethodType.Redirection) { //Redirection will not work because it's AJAX request. //That's why we don't process it here (we redirect a user to another page where he'll be redirected) //redirect return Json(new { redirect = string.Format("{0}checkout/OpcCompleteRedirectionPayment", _webHelper.GetStoreLocation()) }); } else { _paymentService.PostProcessPayment(postProcessPaymentRequest); //success return Json(new { success = 1 }); } } else { //payment method could be null if order total is 0 //success return Json(new { success = 1 }); } } else { //error var confirmOrderModel = new CheckoutConfirmModel(); foreach (var error in placeOrderResult.Errors) confirmOrderModel.Warnings.Add(error); return Json(new { update_section = new UpdateSectionJsonModel() { name = "confirm-order", html = this.RenderPartialViewToString("OpcConfirmOrder", confirmOrderModel) }, goto_section = "confirm_order" }); } } catch (Exception exc) { _logger.Warning(exc.Message, exc, _workContext.CurrentCustomer); return Json(new { error = 1, message = exc.Message }); } }
protected 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; }