public ActionResult Custom(CustomViewModel customViewModel) { customViewModel.PaymentFormHidden = false; var chargeOptions = new StripeChargeCreateOptions() { //required Amount = 3900, Currency = "usd", Source = new StripeSourceOptions() { TokenId = customViewModel.StripeToken }, //optional Description = string.Format("JavaScript Framework Guide Ebook for {0}", customViewModel.StripeEmail), ReceiptEmail = customViewModel.StripeEmail }; var chargeService = new StripeChargeService(); try { StripeCharge stripeCharge = chargeService.Create(chargeOptions); //Validate charge chargeService.Capture(stripeCharge.Id); if (stripeCharge.Status == "succeeded") { //creating the customer and add it to stripe var newCustomer = new StripeCustomerService().Create( new StripeCustomerCreateOptions { Email = customViewModel.StripeEmail } ); // CREATE NEW INVOICE // var invoiceService = new StripeInvoiceService(); // StripeInvoice response = invoiceService.Create(newCustomer.Id); // optional StripeInvoiceCreateOptions //var response = invoiceService.Upcoming(newCustomer.Id); // stripeCharge.InvoiceId = response.Id; //SEND THE CONFIRMATION var emailService = new EmailService(); emailService.SendPaymentReceivedFromChargeEmail(stripeCharge); } } catch (StripeException stripeException) { Debug.WriteLine(stripeException.Message); ModelState.AddModelError(string.Empty, stripeException.Message); return View(customViewModel); } return RedirectToAction("Confirmation"); }
public ActionResult Custom() { string stripePublishableKey = ConfigurationManager.AppSettings["stripePublishableKey"]; var model = new CustomViewModel() { StripePublishableKey = stripePublishableKey, PaymentFormHidden = true }; return View(model); }