gpt4 book ai didi

javascript - 来源 : 'tok_visa' in Stripe

转载 作者:行者123 更新时间:2023-11-30 20:34:32 29 4
gpt4 key购买 nike

我正在尝试让 Stripe 运行起来,我几乎已经完成了,但有一件令人困惑的事情。 source: 'tok_visa' 部分。看起来它可以是“tok_mastercard”、“bank_account”等等。问题是:我怎么知道应该使用哪一个?文档说“通过 Stripe.js 获得”,这很酷,但我找不到它的确切来源。

谁能解释一下?这是迄今为止唯一令人困惑的部分。

到目前为止,这是我在 Node 中的代码:

router.post('/charge', (req, res, next) => {
var amount = 10000; // in cents
stripe.customers.create({
email: req.body.email,
source: req.body.token
}).then(customer => {
req.user.stripeId = customer.id;
req.user.save();
stripe.charges.create({
amount,
description: "Charge for the example",
currency: 'cad',
source: , // obtained with Stripe.js
customer: customer.id,
})
}).then(
charge => res.render("payment/charge", {
title: "Payment report",
user: req.user
})
).catch(e => console.log(e));
});

最佳答案

您的代码正在使用 req.body.token 获取 token ,这意味着您已经实现了对客户端进行 token 化的逻辑。创建客户后,您只需将客户 ID cus_XXXX 传递到 Create Charge 的 customer 参数中即可创建费用 API .

关于javascript - 来源 : 'tok_visa' in Stripe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49971815/

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