如何让Stripe在订阅变更时自动扣费已有支付方式?
问题描述
我为客户提供月度订阅服务。客户首次开通付费订阅时,通过PaymentElement收集信用卡信息,成功后支付方式会存储在Stripe中,此流程运行正常。
但当客户升级至更高档位订阅时,Stripe生成了按比例计费的款项,却未自动扣取客户已存储的支付方式,该款项在Stripe中处于Incomplete状态,提示信息为「The customer hasn't attempted to pay this invoice yet」。
疑问:为何Stripe不直接使用已存储的支付方式扣费?为何需要等待客户主动支付?
以下是发起订阅升级的代码(与首次开通付费订阅收集卡信息的代码一致):
var service = new SubscriptionService(); var subscription = service.Get(subscriptionId); var paymentSettings = new SubscriptionPaymentSettingsOptions { SaveDefaultPaymentMethod = "on_subscription" }; var options = new SubscriptionUpdateOptions { CancelAtPeriodEnd = false, ProrationBehavior = "always_invoice", Items = new List<SubscriptionItemOptions> { new SubscriptionItemOptions { Id = subscription.Items.Data[0].Id, Price = planPriceCombo.Item2 } }, PaymentSettings = paymentSettings, PaymentBehavior = "default_incomplete" }; options.AddExpand("latest_invoice.payment_intent"); var updatedSubscription = service.Update(subscriptionId, options);
请问是否错误配置了订阅更新?如何设置才能让Stripe自动扣取客户已绑定的支付方式?
问题原因与解决方案
核心问题
代码里的PaymentBehavior = "default_incomplete"是关键问题。这个参数会强制新生成的发票进入**未完成(Incomplete)**状态,要求客户主动完成支付,哪怕已有存储的支付方式。
首次订阅正常的原因
首次订阅时用这个参数是合理的——当时客户还没绑定支付方式,需要通过PaymentElement收集并完成支付。但升级时客户已有默认支付方式,这个参数就会阻止自动扣费。
修复方式
将PaymentBehavior替换为以下两个值之一:
auto_advance:Stripe默认行为(不设置此参数时默认值)。自动尝试用客户默认支付方式扣费,扣费失败则发票进入逾期状态,同时触发webhook通知。allow_incomplete:优先尝试自动扣费,只有扣费失败时才让发票进入未完成状态。
修改后的代码示例:
var options = new SubscriptionUpdateOptions { CancelAtPeriodEnd = false, ProrationBehavior = "always_invoice", Items = new List<SubscriptionItemOptions> { new SubscriptionItemOptions { Id = subscription.Items.Data[0].Id, Price = planPriceCombo.Item2 } }, PaymentSettings = paymentSettings, // 替换为auto_advance或allow_incomplete PaymentBehavior = "auto_advance" };
额外检查
- 确认客户的
default_payment_method已正确设置(可在Stripe后台查看客户详情),首次订阅时的SaveDefaultPaymentMethod = "on_subscription"已保证这点,也可在代码里提前验证。 - 确保Stripe账户没有开启强制客户确认支付的额外设置,一般不会影响已有支付方式的自动扣费。
内容的提问来源于stack exchange,提问作者Walter
相关产品推荐
相关产品推荐

