【发布时间】:2024-01-12 17:24:01
【问题描述】:
客户
我正在通过以下方式使用 Stripe Checkout 自定义集成 - https://stripe.com/docs/checkout#integration-custom:
var handler = StripeCheckout.configure({
key: 'YOUR_KEY_HERE',
image: 'images/logo-48px.png',
token: function(token, args) {
$.post("http://localhost:3000/charge", {token: token}, function(res) {
console.log("response from charge: " + res);
})
}
})
使用 custom 而不是 simple - How can I modify Stripe Checkout to instead send an AJAX request? - 因为 simple 不允许我进行 AJAX 调用。
服务器
https://stripe.com/docs/tutorials/charges
您已经获得了用户信用卡详细信息的令牌,现在该怎么办?现在你向他们收费。
app.post('/charge', function(req, res) {
console.log(JSON.stringify(req.body, null, 2));
var stripeToken = req.body.token;
var charge = stripe.charges.create({
amount: 0005, // amount in cents, again
currency: "usd",
card: stripeToken,
description: "payinguser@example.com"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
console.log(JSON.stringify(err, null, 2));
}
res.send("completed payment!")
});
});
这是错误:
在我看来,我有 last4、exp_month、exp_year,但由于某种原因我没有 number。有什么建议/提示/想法吗?
谷歌搜索"The card object must have a value for 'number'" - 12 个结果,帮助不大。
【问题讨论】: