コード例 #1
0
        // Ajax.
        public ActionResult ConfirmOrder(string formData)
        {
            string redirectUrl = null;
            var    messages    = new List <string>();
            var    success     = false;

            try
            {
                var store    = Services.StoreContext.CurrentStore;
                var customer = Services.WorkContext.CurrentCustomer;
                var processPaymentRequest = (_httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest) ?? new ProcessPaymentRequest();

                processPaymentRequest.StoreId    = store.Id;
                processPaymentRequest.CustomerId = customer.Id;
                processPaymentRequest.PaymentMethodSystemName = AmazonPayPlugin.SystemName;

                // We must check here if an order can be placed to avoid creating unauthorized Amazon payment objects.
                var warnings = _orderProcessingService.GetOrderPlacementWarnings(processPaymentRequest);

                if (!warnings.Any())
                {
                    if (_orderProcessingService.IsMinimumOrderPlacementIntervalValid(customer, store))
                    {
                        if (_apiService.ConfirmOrderReference())
                        {
                            success = true;

                            var state = _httpContext.GetAmazonPayState(Services.Localization);
                            state.FormData = formData.EmptyNull();
                        }
                        else
                        {
                            _httpContext.Session["AmazonPayFailedPaymentReason"] = "PaymentMethodNotAllowed";

                            redirectUrl = Url.Action("PaymentMethod", "Checkout", new { area = "" });
                        }
                    }
                    else
                    {
                        messages.Add(T("Checkout.MinOrderPlacementInterval"));
                    }
                }
                else
                {
                    messages.AddRange(warnings.Select(x => HtmlUtils.ConvertPlainTextToHtml(x)));
                }
            }
            catch (Exception ex)
            {
                messages.Add(ex.Message);
                Logger.Error(ex);
            }

            return(Json(new { success, redirectUrl, messages }));
        }