我正在尝试为我的网站设置Stripe Checkout。
我创建并验证了Stripe帐户,现在需要设置结帐页面。我从Github下载了PHP条带库(我有PHP 5.6.4,所以兼容性很好)。然后,我进入了Stripe文档,找到了this page。
我为结帐创建了一个新页面,其中包括Stripe库中的init.php
,并将在文档页面中找到的代码粘贴到该页面中。当我打开它时,它会返回一个空白页,但我不知道为什么。
我不知道这是否是正确的过程,但是我在网上搜索了大约2个小时却一无所获,而且文档对我来说似乎并不清晰。有人可以帮我吗?
我检查了一下,页面没有产生错误。页面的代码是这样的:
<?php
require_once('assets/stripe/init.php');
\Stripe\Stripe::setApiKey('sk_test_OW6K5e96gNXbAhEvPo15IB3C');
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => 'T-shirt',
'description' => 'Comfortable cotton t-shirt',
'images' => ['https://example.com/t-shirt.png'],
'amount' => 500,
'currency' => 'eur',
'quantity' => 1,
]],
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/cancel',
]);
?>
这是我在页面中复制的内容,仍然不知道是否需要更改或添加其他内容。
答案 0 :(得分:0)
<?php
require_once 'shared.php';
$domain_url = $config['domain'];
$base_price = $config['base_price'];
$currency = $config['currency'];
$quantity = $body->quantity;
// Create new Checkout Session for the order
// Other optional params include:
// [billing_address_collection] - to display billing address details on the page
// [customer] - if you have an existing Stripe Customer ID
// [payment_intent_data] - lets capture the payment later
// [customer_email] - lets you prefill the email input in the form
// For full details see https://stripe.com/docs/api/checkout/sessions/create
// ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
$checkout_session = \Stripe\Checkout\Session::create([
'success_url' => $domain_url . '/success.html?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $domain_url . '/canceled.html',
'payment_method_types' => ['card'],
'line_items' => [[
'name' => 'Pasha photo',
'images' => ["https://picsum.photos/300/300?random=4"],
'quantity' => $quantity,
'amount' => $base_price,
'currency' => $currency
]]
]);
echo json_encode(['sessionId' => $checkout_session['id']]);
有关更多详细信息和演示代码: https://github.com/stripe-samples/checkout-one-time-payments/tree/master/client-and-server/server/php/public