【发布时间】:2013-07-18 23:28:57
【问题描述】:
在网站中测试 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
【问题讨论】:
-
只有this solution 帮助了我。
标签: php error-handling try-catch stripe-payments