【发布时间】:2023-04-03 00:41:01
【问题描述】:
我在让 Stripe 集成工作时获得了很多“乐趣”。
我正在构建一个旧的付款页面,但它在旧版本的结帐上运行。升级后我遇到了很多问题,但文档似乎没有帮助。
我在单个 index.php 文件中运行以下代码
require('../config.php');
<script>
// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_KEY');
$checkout_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' => 'gbp',
'quantity' => 1,
]],
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/cancel',
]);
</script>
<script src="https://js.stripe.com/v3/"></script>
<?php stripe = Stripe('pk_test_KEY'); ?>
<li> <a href="javascript:void(0)" onclick="myRedirectFN"><button class="btn btn-buy"> Buy image <?php echo htmlspecialchars(" - from £" . $imagePrice); ?></button></a></li>
<script>
function myRedirectFN() {
stripe.redirectToCheckout({
var stripe = Stripe('pk_test_CXv2tKPq22Bo9o9CaKi6z3nW00ZprVPd08')
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: '$checkout_session['id']'
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});}
</script>
这是Stripe Documentation 上的所有内容。
目前我收到一个意外的 var 错误,但是当我删除 var 时没有进一步的进展。
我应该如何构造这段代码?
【问题讨论】:
标签: php stripe-payments