node.js - 使用不同卡为现有客户创建费用
问题描述
所以我有一个客户已经创建了一张卡。
在前端,我提供了使用现有卡或其他卡的选项。
按照 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 文档: https ://stripe.com/docs/api/charges/create
来源 可选 要收取的付款来源。这可以是卡(即信用卡或借记卡)、银行账户、来源、令牌或关联账户的 ID。对于某些来源(即卡、银行帐户和附加来源),您还必须传递关联客户的 ID。
解决方案
我找到了解决方案:
if (token) {
const card = await stripe.customers.createSource(customerId, {
source: token
})
paymentInfo.source = card.id
}
推荐阅读
- ios - 为什么我的垂直编程滚动视图在 Swift 中不起作用
- if-statement - Gitlab-CI:有条件的allow_failure
- python - 在 Cython 中使用 clang
- java - 应用程序在尝试获取 Sleuth 的踪迹时因“需要一个无法找到的 'brave.Tracer' 类型的 bean”而失败
- android - 已被 Play Protect 屏蔽的签名版本 APK
- python - 如何大写列表中的特定元素(python)
- c# - 分页接收记录的SQL查询
- python - 用其他数据框列中的值替换数据框列值
- solr - 带有 docID 的 Apache SOLR 异常
- drag-and-drop - 如何使用列表视图在 swiftUI 中创建两列列表?