gpt4 book ai didi

node.js - 使用不同的卡为现有客户创建费用

转载 作者:太空宇宙 更新时间:2023-11-04 01:23:01 26 4
gpt4 key购买 nike

所以我有一个客户已经创建了一张卡。
在前端,我提供了使用现有卡或其他卡的选项。
按照 API 文档,对于新卡,我创建 token ,将其发送到我的后端...

在后端:

const paymentInfo = {
customer: customerId,
amount: Number(total) * 100,
currency: 'usd',
source: existingCardId || token
}

const charge = await stripe.charges.create(paymentInfo)

如果我使用现有卡付款,则费用会通过,但如果我发送新 token ,则会收到错误消息:

Customer cus_G4V0KvxKMmln01 does not have a linked source with ID tok_1FYMLTAOg97eusNI2drudzlJ.

来自 API 文档: https://stripe.com/docs/api/charges/create

source optional A payment source to be charged. This can be the ID of a card (i.e., credit or debit card), a bank account, a source, a token, or a connected account. For certain sources—namely, cards, bank accounts, and attached sources—you must also pass the ID of the associated customer.

最佳答案

我找到了解决方案:

if (token) {
const card = await stripe.customers.createSource(customerId, {
source: token
})
paymentInfo.source = card.id
}

关于node.js - 使用不同的卡为现有客户创建费用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58584659/

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