Я пытаюсь следовать этой документации, пытаясь реализовать проверку полосы:
https://stripe.com/docs/payments/checkout/one-time
В настоящее время у меня не работает, как при нажатии Моя кнопка "Купить сейчас" в моем файле html, она ничего не делает (это для проверки используется мой локальный хост). Когда я говорю, что ничего не происходит, я имею в виду, что я нажимаю кнопку и ничего не загружается, оставаясь на той же странице.
Ниже приведен код html для кнопки "Купить сейчас" и sone javascript код:
<script src="https://js.stripe.com/v3/"></script>
...
<a class="buy-btn" onclick="showStripe()">Buy Now</a>
...
<script src="myScript.js"></script>
<script src="stripe.js"></script>
У меня есть два javascript файла, которые имеют дело с полосой и которые вы можете сравнить с документацией:
myScript. js:
var stripe = Stripe('pk_test_xxxx'); //xxxx out key for SO
function showStripe(){
stripe.redirectToCheckout({
// 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`.
});
}
нашивка. JS
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_xxxx'); //xxxx out key for SO
(async () => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
name: 'title',
description: 'description',
images: ['img/top-view-img.jpg'],
amount: 25,
currency: 'gbp',
quantity: 1,
}],
payment_intent_data: {
capture_method: 'manual',
},
success_url: 'http://localhost:8080/order-confirmation',
cancel_url: 'http://localhost:8080/',
});
})();
Мой вопрос просто, как мне заставить это работать?