Node.js 为使用不同卡的现有客户创建费用
因此,我有一位客户已经创建了一张卡。Node.js 为使用不同卡的现有客户创建费用,node.js,stripe-payments,Node.js,Stripe Payments,因此,我有一位客户已经创建了一张卡。 在前端,我可以选择使用现有卡或其他卡。 按照API文档,对于新卡,我创建令牌,将其发送到后端 在后端: const paymentInfo = { customer: customerId, amount: Number(total) * 100, currency: 'usd', source: existingCardId || token } const charge = await stripe.charges.create(pay
在前端,我可以选择使用现有卡或其他卡。
按照API文档,对于新卡,我创建令牌,将其发送到后端 在后端:
const paymentInfo = {
customer: customerId,
amount: Number(total) * 100,
currency: 'usd',
source: existingCardId || token
}
const charge = await stripe.charges.create(paymentInfo)
如果我用现有的卡支付,费用会通过,但如果我发送新的代币,我会返回一个错误:
Customer cus_G4V0KvxKMmln01 does not have a linked source with ID tok_1FYMLTAOg97eusNI2drudzlJ.
从API文档中:
来源可选要收费的付款来源。这可以是的ID
一张卡(即信用卡或借记卡)、一个银行账户、一个来源、一个
令牌或连接的帐户。对于某些来源,即卡、银行
帐户和附加源您还必须传递
关联客户
我找到了解决办法:
if (token) {
const card = await stripe.customers.createSource(customerId, {
source: token
})
paymentInfo.source = card.id
}
我找到了解决办法:
if (token) {
const card = await stripe.customers.createSource(customerId, {
source: token
})
paymentInfo.source = card.id
}
我不确定我是否理解,我将如何做到这一点?我不确定我是否理解,我将如何做到这一点?