gpt4 book ai didi

javascript - 如何在不使用 Stripe 的 UI 层的情况下获取客户端 token ?

转载 作者:行者123 更新时间:2023-11-28 17:10:16 26 4
gpt4 key购买 nike

我有以下运行良好的 php 页面:

<html>
<head>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var handler = StripeCheckout.configure({
key: '<?=$stripePublicKey?>',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
console.log("token.id: " + token.id);
console.log("token: " + token);
}
});

function init(){
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'TruckerCert',
description: 'Buy Certs',
amount: 2000
});
e.preventDefault();
});

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
}
</script>
</head>
<body onload="init()">
<h1>Stripe Token Test</h1>
<button id="customButton">Purchase</button>
</body>
</html>

它工作并生成以下 JSON:

{
"id": "tok_1E255j2*****wC135im",
"object": "token",
"card": {
"id": "card_1E255j2H1*****RGS4Kqc",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2021,
"fingerprint": "3nk5B*****29xV",
"funding": "unknown",
"last4": "1111",
"metadata": {
},
"name": "her*******@gmail.com",
"tokenization_method": null,
"type": "Visa"
},
"client_ip": "67.***.***.17",
"created": 1549754315,
"email": "her********@gmail.com",
"livemode": false,
"type": "card",
"used": false
}

所以这一切都符合预期。问题是,我能找到提交信用卡号和到期日期并接收回 JSON 的唯一方法是通过他们的 UI。例如,当我单击 customButton 时,会出现此对话框:

enter image description here

我不想使用他们的抄送表格。我有自己的 CC 表格。我想使用自己的表单,向 Stripe 的 API 端点发送 ajax 请求,然后接收返回的 JSON,就像上面一样。我已经梳理了 Stripe 的在线文档一个小时,但找不到任何方法来做到这一点。

这是怎么做到的?

最佳答案

您提到的产品名为Stripe Checkout并让您可以安全地收集银行卡详细信息,而无需构建自己的付款表单。

既然您提到已经有了付款表格,那么您应该查看 Stripe Elements 。这使您可以设计和设计自己的付款表单,同时仍满足最低级别的 PCI 合规性 SAQ A,如 documented here .

您仍然可以在此处查看多个付款表格示例和相应的代码:https://stripe.github.io/elements-examples/

关于javascript - 如何在不使用 Stripe 的 UI 层的情况下获取客户端 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54613520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com