laravel / cashier-stripe

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

Use trial_period_days instead of trial_expires to set correct trial end date #1135

Closed Jacketh closed 3 years ago

Jacketh commented 3 years ago

Description:

I'm trying to give the user a 30 free day trial via the following code:

$customer->newSubscription('default', request()->input())
   ->trialDays(30)
   ->checkout([
         'success_url' => route('company.trial.finish') . '?session_id={CHECKOUT_SESSION_ID}',
         'cancel_url' => route('company.trial.finish'),
   ]);

On checkout it's displaying "29 days free". I've spoke to Stripe and they say that trial_period_days should be used in the payload instead. This is because setting trial_expires will be the date upon when the stripe session was created. However I believe the trial should expire x amount of days from when the subscription is actually created. I'm happy to create a PR for this if agreed?

Steps To Reproduce:

  1. Create a new subscription and add 30 trialDays
  2. Go to checkout
  3. Free days is 1 day less than expected due to the seconds that have passed since checkout redirection
driesvints commented 3 years ago

The internal trialExpires contains a timestamp or datetime object for fine grained trial ending. It needs to be 48 into the future. See the note here:

https://github.com/laravel/cashier-stripe/blob/e3f0b9c2869abd11964d4afa89195567ff51d3d8/src/SubscriptionBuilder.php#L373-L375

We currently aren't considering to make use of trial_period_days because we want to offer fine grained trial ending. You can still make use of this by passing the option directly in the array of the checkout method.