使用其他卡为现有客户收取费用

时间:2019-10-28 00:51:49

标签: node.js stripe-payments

所以我有一个已经创建了卡的客户。
在前端,我可以选择使用现有卡还是其他卡。
按照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

  

source可选要收取的付款来源。这可以是   卡(即信用卡或借记卡),银行帐户,来源,   令牌或关联的帐户。对于某些来源,即卡,银行   帐户和附加的来源-您还必须传递   相关客户。

1 个答案:

答案 0 :(得分:0)

我找到了解决方法:

for i in df_xm.index:
    if df_xm['value'][i] != df_ym['value'][i]:
        print(f"{df_xm['id'][i]},{df_xm['variable'][i]}")
相关问题