[英]Working With Stripe and Node / Express to Charge Existing Customer with No Card
[英]create charge for existing customer with different card
所以我有一個客戶已經創建了一張卡。
在前端,我提供了使用現有卡或其他卡的選項。
按照 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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.