javascript - 来源 : 'tok_visa' in Stripe

标签 javascript node.js express stripe-payments

我正在尝试让 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/

相关文章:

javascript - 函数返回值是否可以作为数组键?

javascript - 谷歌图表获取自定义工具提示来处理动画

node.js - Docker - 构建失败,操作系统不受支持,命令 '/bin/sh -c npm install' 返回非零代码

node.js - 如何保护我的应用程序 API 免受外部利用?

javascript - 创建 React App 语法错误 : Unexpected Token

node.js - 当我创建一个带有引用另一个 Mongoose 对象的位置的模式时,如何防止 Mongoose 创建 id?

javascript - FullCalendar 在每个日期旁边添加 "undefined"

javascript - 为什么这个 Javascript 图像对象没有添加到图像数组中?

node.js - 如何使用 Express 获取目录内容?

html - ExpressJS/NodeJS 重定向图像