在我对网站中的Stripe进行测试时,我编写了如下代码:
try {
$charge = Stripe_Charge::create(array(
"amount" => $clientPriceStripe, // amount in cents
"currency" => "usd",
"customer" => $customer->id,
"description" => $description));
$success = 1;
$paymentProcessor="Credit card (www.stripe.com)";
}
catch (Stripe_InvalidRequestError $a) {
// Since it's a decline, Stripe_CardError will be caught
$error3 = $a->getMessage();
}
catch (Stripe_Error $e) {
// Since it's a decline, Stripe_CardError will be caught
$error2 = $e->getMessage();
$error = 1;
}
if ($success!=1)
{
$_SESSION['error3'] = $error3;
$_SESSION['error2'] = $error2;
header('Location: checkout.php');
exit();
}
问题在于有时候卡片存在错误(未被"catch"参数捕获),"try"失败并且页面立即在屏幕上显示错误信息,而不是进入"if"语句并重定向回checkout.php。
我应该如何构建错误处理结构以便获取错误并立即重定向回checkout.php并在那里显示错误?
谢谢!
抛出的错误:
Fatal error: Uncaught exception 'Stripe_CardError' with message 'Your card was declined.' in ............
/lib/Stripe/ApiRequestor.php on line 92