/赶上stripe.net文档说,你应该如下处理错误:尝试Stripe.Net MVC位指示
上的任何服务的出现将引发与条纹返回的消息StripeException任何错误。尝试运行服务调用并捕获StripeException是一个好主意。
如何处理捕获错误并返回视图。
如果chargeService.Create失败,返回视图(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);
}
更新 在进一步研究这个,这可能是一个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);
}