简体   繁体   English

NodeJs 更新客户的默认信用卡以进行 Stripe 订阅和付款

[英]NodeJs Update default credit card of customer for Stripe subscriptions and payment

I am building an app in which i am using stripe to handle all payments.我正在构建一个应用程序,我在其中使用条带来处理所有付款。 And in our app we have a common feature where user can update the default card for their subscriptions but it not working as expected.在我们的应用程序中,我们有一个共同的功能,用户可以为他们的订阅更新默认卡,但它没有按预期工作。 I Have followed the instruction to update the customer payment method as described in the stripe documentation but it's not working as expected i still see the old credit card details as default payment method in stripe dashboard.我已按照 stripe 文档中描述的说明更新客户付款方式,但它没有按预期工作,我仍然在 stripe 仪表板中看到旧的信用卡详细信息作为默认付款方式。

Updating the customer:更新客户:

 const customer = await stripe.customers.update(body.customerId, {
  invoice_settings: {default_payment_method: body.pId},
});

Attaching payment method to customer and updating subscription:将付款方式附加到客户并更新订阅:

 const paymentMethod = await stripe.paymentMethods.attach(body.pId, {
  customer: body.customerId,
});

await stripe.subscriptions.update(subscriptionDetails?.planId as string, {
  default_payment_method: paymentMethod.id,
});

But still nothing, i am not sure what i am missing here but i couldn't update the default payment method.但仍然没有,我不确定我在这里遗漏了什么,但我无法更新默认付款方式。

条纹仪表板

The screenshot you shared refers to the payment methods saved on the Customer.您分享的屏幕截图是指客户保存的付款方式。 If you wish to set the default payment method on the Customer, it will be under invoice_settings.default_payment_method on Customer API.如果您希望为客户设置默认付款方式,它将位于客户 API 的invoice_settings.default_payment_method下。

Subscription's default payment method is different from Customer's default payment method.订阅的默认付款方式与客户的默认付款方式不同。 With default_payment_method on Subscription API, it will only update the default on the Subscription object, not Customer object like the page you see.使用订阅 API 上的default_payment_method ,它只会更新订阅 object 上的默认值,而不是像您看到的页面那样的客户 object。 You should be able to find Subscription's default payment method at the Subscription page.您应该能够在订阅页面找到订阅的默认付款方式。 在此处输入图像描述

Subscription page link will be: https://dashboard.stripe.com/test/subscriptions/sub_xxx where sub_xxx is the Subscription ID.订阅页面链接为: https://dashboard.stripe.com/test/subscriptions/sub_xxx其中sub_xxx是订阅 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM