根据文档 swap()
方法,在下一个计费日期(即当前计划结束后)将当前订阅与新订阅交换。并且swapAndInvoice()
会立即生效,无需等待当前计划结束。
但是 swap()
方法没有按照描述的那样工作。它立即生效。
$subscription_result = $user->subscription('primary')->swap('new_price_id');
这就是我用来交换订阅的东西。
示例
,
Plan A :- 3 days ($3)
Plan B :- 7 days ($7)
用户于3月25日订阅了计划A,下一个计费周期为3月28日。
用户于 3 月 25 日更改订阅B 计划,应于 28 日生效(使用 swap() 方法
)。但它立即生效,并显示下一个计费周期是4 月 1 日。
我尝试使用 swapAndInvoice()
而不是 swap()
,但这两种方法都给出相同的输出,没有区别。
As per the documentation swap()
method swap the current subscription with the new one on the next billing date, means after end of current plan. And swapAndInvoice()
will take immediate effect without waiting for the current plan to end.
But the swap()
method is not working as described. It is taking immediate effect.
$subscription_result = $user->subscription('primary')->swap('new_price_id');
This is what I am using to swap subscription.
example
,
Plan A :- 3 days ($3)
Plan B :- 7 days ($7)
User subscribed to Plan A on 25th March, next billing cycle is on 28th March.
User changed subscription to Plan B on 25th March, it should take effect on 28th (using swap() method
). But it is taking effect immediately and showing next billing cycle is on 1st April.
I have tried using swapAndInvoice()
instead of swap()
, but both the methods are giving same output, no difference.
发布评论
评论(2)
此行为的原因与
swap()
方法具体无关,而是与 订阅升级和降级行为。当您将订阅更新为与先前价格不同的间隔的价格时(例如您的示例为 3 天间隔与 7 天间隔),则 billing_cycle_anchor 将立即重置,并生成新发票。无论价格更新的间隔是否保持不变,swapAndInvoice()
方法都会在订阅更新时截取新发票。而在两个价格的间隔相同的情况下,仅使用swap()
会导致在下一个自然计费周期之前无法创建发票。此处完成用例的 Stripe API 方法是利用 订阅计划。然而,Cashier 可能不直接支持此功能。
The reason for this behavior is not related to the
swap()
method specifically, but instead to how Subscription upgrades and downgrades behave. When you update a subscription to a price with a different interval than the previous price (like with your example a 3 day interval vs. 7 day interval), then the billing_cycle_anchor will be reset immediately and a new invoice will be generated. TheswapAndInvoice()
method will cut a new invoice at the time of the Subscription update regardless of whether the intervals of the price update stay the same. Whereas just usingswap()
in the case where the interval of the two prices are the same would result in an invoice not being created until the next natural billing cycle.The Stripe API way to accomplish your use-case here would be to utilize Subscription Schedules. However, Cashier may not support this feature directly.
我遇到了同样的问题,但可能找到了解决方法。我仍在亲自测试,因此请记住这一点。
简而言之,这不是出纳员的问题,当订阅的计费周期发生变化时,Stripe 的默认行为是立即收费。 (但是,如果是相同的计费周期,则将来会收费。不幸的是,这不是我们需要的。)
https://stripe.com/docs/billing/subscriptions/upgrade- downgrade#immediate- payment
然而,Stripe 的设计目的是处理每个用户的多个订阅! Cashier auth()->user()->subscription() 将始终提取他们最近的订阅,因此效果很好。
代码示例。
注意:订阅表下的“试用结束时间”日期将不准确。我建议在用户表下使用“Trial_ends_at”,该表在用户注册时与付款无关。
I ran into this same issue, but might have found a workaround. I'm still testing it myself so bear that in mind.
In short, it's not Cashier that's the issue, Stripe's default behaviour when billing period changes in a subscription is to charge immediately. (If it was the same billing period however, it would charge in the future. Unfortunately not what we need here.)
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment
However, Stripe is designed to handle multiple subscriptions per user! Cashier auth()->user()->subscription() will always pull their most recent subscription so it works nicely.
Code Ex.
Note: Your "trial_ends_at" date under subscriptions table will be inaccurate. I'm recommend using "trial_ends_at" under users table which isn't tied to payments when a user registers.