在网站上测试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();
}
Run Code Online (Sandbox Code Playgroud)
问题是卡有时会出错(没有被我在那里的"catch"参数捕获)并且"try"失败并且页面立即在屏幕上发布错误而不是进入"if"和重定向回checkout.php. …