public ActionResult SavePaymentInformation(PaymentInformationModel model) { if (!ModelState.IsValid) return CurrentUmbracoPage(); // Saves the customer Billing Information Basket.SalePreparation().SaveBillToAddress(model.ToAddress()); var paymentMethod = Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod; // Save the payment method selection Basket.SalePreparation().SavePaymentMethod(paymentMethod); return RedirectToUmbracoPage(ConfirmationId); }
public ActionResult SavePayment(PaymentInformationModel model) { // has error occurred bool error = false; // do we raise events bool raiseEvents = false; // payment attempt result information IPaymentResult attempt = null; // get payment method var paymentMethod = Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod; // get customer, items var preparation = base.Basket.SalePreparation(); // Save the payment method selection preparation.SavePaymentMethod(paymentMethod); // make sure there is a billing address - it can be empty - it just has to exist if (!preparation.IsReadyToInvoice()) return RedirectToUmbracoPage(BasketPageId); // AuthorizePayment will save the invoice with an Invoice Number. attempt = preparation.AuthorizePayment(paymentMethod.Key); // if payment isn't successful, grab some information if (!attempt.Payment.Success) { error = true; // TBD - Not in Merchello yet // Notification.Trigger("OrderConfirmationFailure", attempt, new[] { preparation.GetBillToAddress().Email }); _log.CreateAuditLogWithKey("Checkout failed - attempt payment failure", preparation.Customer.ExtendedData); } else { // trigger the order notification confirmation Notification.Trigger("OrderConfirmation", attempt, new[] { preparation.GetBillToAddress().Email }); } // grab final content page var receipt = Umbraco.TypedContent(ReceiptId); // redirect so that url has invoice number (encrypted) in address bar // this feels clunky and unsafe but illustrative all the same return Redirect(string.Format("{0}?inv={1}", receipt.Url, attempt.Invoice.Key.ToString().EncryptWithMachineKey())); }