laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 667 forks source link

Subscriptions: Support of billing cycle and trial in checkout #1682

Closed Nowocyn closed 1 month ago

Nowocyn commented 1 month ago

With the actual implementation, it is not possible to make use of a new billing anchor but Stripe is supporting it through their API. Stripe allows the usage of trial_end and billing_cycle_anchor inside the checkout process.

The line 354 ( https://github.com/laravel/cashier-stripe/blob/15.x/src/SubscriptionBuilder.php#L354 ) sets the variable billingCycleAnchor to null if there is a trialEnd given, but this line only represents the possibility of stripes frontend and not the capability of their API which can handle the presence of both variables correctly.

If a change on this line will be planned I would suggest the usage of an environment that allows to switch the behavior before breaking many integrations.

Actual behavior: Date: 26.06.2024 A new checkout with the given trial end set to 11.07.2024 and the given billing cycle anchor set to 01.07 or 01.08 would create a new subscription with the billing cycle set to 11.07 or even 26.06 but not to the given billing cycle anchor. Subscription Billing cycle 11.07 -> 11.08

Requested behavior with a set environment variable: Date: 26.06.2024 A new checkout with a given trial end set to 11.07.2024 and the given billing cycle anchor set to 01.07 would create a new subscription with a trial end at 11.07 but the billing cycle will start correctly at 01.07 Subscription Billing cycle 01.07 -> 01.08

Stripe will handle the needed calculation of the proration and the correctly calculated trial period inside the actual billing cycle.

Documentation of stripe: https://docs.stripe.com/billing/subscriptions/trials#combine-trial-anchor

driesvints commented 1 month ago

Thanks @Nowocyn. I agree this would be useful. I've set up a new 16.x branch where you can direct a PR against. Thanks!