[英]How to intergrate with Stripe Checkout JS/HTML
I am trying to follow this documentation in trying to implement stripe's checkout:我正在尝试按照此文档尝试实现条带结帐:
https://stripe.com/docs/payments/checkout/one-time https://stripe.com/docs/payments/checkout/one-time
I currently haven't got it working as when I click my buy now button in my html file, it doesn't do anything (this is through my localhost for test purposes).我目前还没有让它工作,因为当我在我的 html 文件中点击我的立即购买按钮时,它没有做任何事情(这是通过我的本地主机进行测试)。 When I say it doesn't do anything, I mean I click the button and nothing loads, remain on the same page.
当我说它不做任何事情时,我的意思是我单击按钮并且没有加载任何内容,保持在同一页面上。
Below is the html code for the buy now button along with sone javascript code:以下是立即购买按钮的 html 代码以及 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>
I then have two javascript files that deal with the stripe and which you can compare with the documentation:然后我有两个处理条纹的 javascript 文件,您可以将它们与文档进行比较:
myScript.js: 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`.
});
}
stripe.JS条纹.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/',
});
})();
My question is simply how can I get this to work?我的问题很简单,我怎样才能让它发挥作用?
The stripe.JS
file you have there is server-side code, meant to run on Node.js - it won't work in the browser, and you should never ever share your Secret Key.您拥有的
stripe.JS
文件是服务器端代码,旨在在 Node.js 上运行 - 它无法在浏览器中运行,您永远不应该共享您的密钥。
You can do client-only (ie, only in the browser) Checkout, but it's a different approach: https://stripe.com/docs/payments/checkout/client-only您可以仅在客户端(即,仅在浏览器中)结帐,但这是一种不同的方法: https : //stripe.com/docs/payments/checkout/client-only
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.