public ActionResult Process(StorePaymentModel model) { try { var paymentMethod = CheckoutManager.Payment.GetPaymentMethod(); if (paymentMethod == null) { var ex = new NullReferenceException("PaymentMethod was null"); return(HandlePaymentException(model, ex)); } var args = new ProcessorArgumentCollection(); if (Request.IsAjaxRequest()) { args.SetPayPalExpressAjaxRequest(true); } // Don't empty the basket here. CheckoutManager.Context.Settings.EmptyBasketOnPaymentSuccess = false; var attempt = CheckoutManager.Payment.AuthorizePayment(paymentMethod.Key, args); var resultModel = CheckoutPaymentModelFactory.Create(CurrentCustomer, paymentMethod, attempt); if (attempt.Payment.Success) { CustomerContext.SetValue("invoiceKey", attempt.Invoice.Key.ToString()); return(Redirect(attempt.RedirectUrl)); } if (!resultModel.ViewData.Success) { var invoiceKey = attempt.Invoice.Key; var paymentKey = attempt.Payment.Result != null ? attempt.Payment.Result.Key : Guid.Empty; EnsureDeleteInvoiceOnCancel(invoiceKey, paymentKey); } return(HandlePaymentSuccess(resultModel)); } catch (Exception ex) { return(HandlePaymentException(model, ex)); } }