如果支付成功,它会重定向到“成功”页面,但如果支付失败,它不会重定向到“取消”页面,它看起来像下图。如果你能帮忙,我会很高兴的,谢谢。
ERROR PAGE PHOTO升
else if ($payment_method == 'stripe') {
$stripe = array(
"secret_key" => $stripe_secret_key,
"publishable_key" => $stripe_publish_key
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$customer = \Stripe\Customer::create(array(
'email' => $order_email,
'source' => $token
));
$item_name = $item_names_data;
$item_price = $amount * 100;
$currency = $site_currency;
$order_id = $purchase_token;
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $item_price,
'currency' => $currency,
'description' => $item_name,
'metadata' => array(
'order_id' => $order_id
)
));
$chargeResponse = $charge->jsonSerialize();
if ($chargeResponse['paid'] == 1 && $chargeResponse['captured'] == 1) {
//if the payment is successful they will...
return view('success')->with($data_record);
}
else
{
return redirect("cancel")->with("error", $response->getMessage()); //NOT WORKING
}
}
1条答案
按热度按时间but5z9lq1#
正如@aynber所说,您需要一个PHP try-catch块来处理异常(https://www.phptutorial.net/php-oop/php-try-catch/)。
您还可能希望捕获其他Stripe异常,例如InvalidRequestException、AuthenticationException和ApiConnectionException,并且可能只需要彻底捕获一般异常。API调用并不总是按计划进行。