我正在使用客户端 PHP 代码将网站从使用 Stripe Checkout v2 迁移到 v3(此处所有内容均处于测试模式)。我已成功设置结帐流程,付款后重定向到成功页面。
在成功页面上,我放置了webhook代码,因为我想验证付款是否已完成,然后显示一个表单。
Webhook 已在 Stripe 仪表板中设置,并在 Webhook 日志中显示为“成功”。
以下是用于结帐的 PHP 代码:
require('includes/stripe/stripe-v3/init.php');
\Stripe\Stripe::setApiKey('sk_test_...');
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => 'Example',
'description' => 'Example description',
'images' => ['https://example/com/image.png'],
'amount' => 99,
'currency' => 'gbp',
'quantity' => 1,
]],
'success_url' => 'https://example.com/test-payment.php?checkout=v3&payment=success&session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/test-payment?payment=failed',
]);
$session_id = $session->id;
Run Code Online (Sandbox Code Playgroud)
这是 JavaScript:
var stripe = Stripe('pk_test_4iEnGexyFSJgXFumnmEXWDlG');
function checkout_redirect() {
stripe.redirectToCheckout({
// Make the id field from the Checkout Session …Run Code Online (Sandbox Code Playgroud)