public ActionResult Payment(PaymentInformationModel data) { if (CurrentUser.Payment != null) { return(RedirectToAction <UserController>(c => c.Index())); } if (ModelState.IsValid) { //var subscription = SubscriptionRequest.CreateMonthly(CurrentUser.Email, "Hatley", // AuthorizeNetConfigurationSection.Price); //subscription.CardNumber = data.CartNumber; //subscription.CardCode = data.CardCode; //subscription.CardExpirationMonth = (int)data.ExpirationMonth; //subscription.CardExpirationYear = (int)data.ExpirationYear; //subscription.StartsOn = DateTime.UtcNow; //subscription.WithBillingAddress(new Address() //{ // First = data.FirstName, // Last = data.LastName, // Phone = CurrentUser.PhoneNumber //}); //ISubscriptionRequest payment = null; CustomerInfo info = new CustomerInfo { CardNumber = data.CartNumber, Cvc = data.CardCode, Email = CurrentUser.Email, ExpMonth = data.ExpirationMonth.ToString(), ExpYear = data.ExpirationYear.ToString(), FullName = CurrentUser.FullName }; try { payment.CreateSubscription(info, planId); CurrentUser.Payment = new Payment { PaymentId = payment.PaymentId, PaymentDateUTC = DateTime.UtcNow, CardNumber = data.CartNumber.Substring(data.CartNumber.Length - 4) }; } catch (Exception e) { logger.Error("Error while saving payment", e); ModelState.AddModelError("", "Invalid payment information!"); return(View(data)); } UnitOfWork.Commit(); return(RedirectToAction <UserController>(c => c.Index())); } return(View(data)); }
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()))); }
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(GetContentIdByContentName(ConfirmationPage))); }