/趕上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);
}