The stripe.net documentation says you should handle errors as follows:
Any errors that occur on any of the services will throw a StripeException with the message returned from Stripe. It is a good idea to run your service calls in a try and catch StripeException.
How do you handle catching the errors and returning the view.
If the chargeService.Create fails with an error how return the object, stripeCharge, back to the View: return View(stripeCharge);
public ActionResult Create(StripeCharge stripeCharge)
{
if (ModelState.IsValid)
{
var myPlan = new StripeChargeCreateOptions();
myPlan.Amount = stripeCharge.Amount;
try
{
var chargeService = new StripeChargeService();
StripeCharge response = chargeService.Create(myPlan);
}
catch (Exception e)
{
errorMessage = e.Message;
}
return RedirectToAction("Index");
}
return View(stripeCharge);
}
Update upon further research this this might be a solution
public ActionResult Create(StripeCharge stripeCharge)
{
if (ModelState.IsValid)
{
var myPlan = new StripeChargeCreateOptions();
myPlan.Amount = stripeCharge.Amount;
try
{
var chargeService = new StripeChargeService();
StripeCharge response = chargeService.Create(myPlan);
return RedirectToAction("Index");
}
catch (Exception e)
{
errorMessage = e.Message;
return View(stripeCharge);
}
}
return View(stripeCharge);
}