客户
我正在使用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个结果,没有多大帮助 .
2 回答
你必须提供"token"作为
card
参数实际上应该只是令牌ID(例如:"tok_425dVa2eZvKYlo2CLCK8DNwq"),而不是完整对象 . 使用Checkout,您的应用永远不会看到卡号 .你需要改变:
至:
关于这个
card
选项的文档不是很清楚,但Stripe API Reference有一个例子 .在
npm install stripe
之后这样做