我设法使用 Strip.net dll 的一个版本来创建付款方式,但我在处理错误时遇到了问题。我做到了这一点。
try
{
StripeCustomer current = GetCustomer();
// int? days = getaTraildays();
//if (days != null)
//{
int chargetotal = 300; //Convert.ToInt32((3.33*Convert.ToInt32(days)*100));
var mycharge = new StripeChargeCreateOptions();
mycharge.AmountInCents = chargetotal;
mycharge.Currency = "USD";
mycharge.CustomerId = current.Id;
string key = "sk_test_XXX";
var chargeservice = new StripeChargeService(key);
StripeCharge currentcharge = chargeservice.Create(mycharge);
//}
}
catch (StripeException)
{
lblerror.Text = "Please check your card information and try again";
}
它将捕获错误并让用户知道存在问题,但我对此很陌生,以了解为什么如果该过程有效,它仍然会显示错误。我知道它的写法有问题,但我不确定如何处理,我努力尝试的一切都失败了。我想做的是让它重定向到另一个页面。有任何想法吗
++更新
在 Olivier Jacot-Descombes 的帮助下,我将代码更改为
catch (StripeException ex)
{
lblerror.Text = (ex.Message);
}
并且能够得到更好的结果