Я получаю много удовольствия от работы интеграции Stripe.
Я использую старую страницу с платежами, но она работала над устаревшей версией оформления заказа. С обновлением у меня было много проблем, но документация, похоже, не помогает.
У меня приведенный ниже код работает в одном индексе. php file
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, дальнейший прогресс отсутствует.
Как мне структурировать этот код?