public ActionResult Create(DonationCreateViewModel model) { if (ModelState.IsValid) { //Debug Purpose to see if we are getting the data Debug.WriteLine("I'm pulling data of Name: " + model.name + ", Amount: " + model.amount + ", Email: " + model.email + ", Anonymous: " + model.anonymous); //+ ", Card Number: " + model.number + " Card ExpMonth: " + model.expMonth //+ " Card ExpYear: " + model.expYear + " Card CVC: " + model.cvc); Donation newDonation = new Donation(); newDonation.donationName = model.name; newDonation.donationAmount = model.amount; newDonation.donationEmail = model.email; newDonation.donationAnonymous = model.anonymous; //This method is when you want the payment done on the Server Side (not safe due to sending card info.) /* * StripeConfiguration.ApiKey = "sk_test_T3BF2ap8TTDpmetCKxF038r400HAf7zrj8"; * var options = new PaymentIntentCreateOptions * { * Amount = model.amount, * Currency = "usd", * // Verify your integration in this guide by including this parameter * Metadata = new Dictionary<string, string> * { * { "integration_check", "accept_a_payment" }, * } * }; * * var service = new PaymentIntentService(); * try * { * var paymentIntent = service.Create(options); * * //Create the Payment Method * PaymentMethodCreateOptions payMethodOptions = new PaymentMethodCreateOptions * { * Type = "card", * Card = new PaymentMethodCardCreateOptions * { * Number = model.number, * ExpMonth = model.expMonth, * ExpYear = model.expYear, * Cvc = model.cvc, * }, * BillingDetails = new BillingDetailsOptions * { * Name = model.name * } * }; * * //Confirm the payment we are making * PaymentMethodService payMethodService = new PaymentMethodService(); * PaymentMethod payMethod = payMethodService.Create(payMethodOptions); * PaymentIntentConfirmOptions payOptions = new PaymentIntentConfirmOptions * { * PaymentMethod = payMethod.Id * }; * service = new PaymentIntentService(); * service.Confirm( * paymentIntent.Id, * payOptions * ); * * //Add the id for the payment in the Stripe API (Unique identifier for the object) * newDonation.donationReceiptId = paymentIntent.Id; * } * catch (Exception e) { * Debug.WriteLine(e.Message); * //Something failed, redisplay form * return View(model); * } */ //Add the object to the database db.Donations.Add(newDonation); //Save the changes in the database db.SaveChanges(); //Must confirm the payment return(RedirectToAction("CardPayment/" + newDonation.donationId)); //Go back to the list of Donation to see the added Donation (If everything is done in the Server Side) //return Redirect("List"); } //Something failed, redisplay form return(View(model)); }