Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trial end date exception with stripe checkout subscription when using 'trialDays(2)' methond on subscription #1156

Closed
mohsinaliryk opened this issue May 18, 2021 · 3 comments

Comments

@mohsinaliryk
Copy link

  • Cashier Version: 12.13.1
  • Laravel Version: 8.41.0
  • PHP Version: 7.4.6
  • Database Driver & Version: mysql 7.4.6

Description:

I'm getting the following exception message when I try to use trialDays(2) on checkout subscription.

The trial_end date has to be at least 2 days in the future.

After some research I find that there is 3s difference between API request timestamp in stripe error log and 'trial_end' parameter.

My code snippet that produces this error:

$trial_checkout = $user->newSubscription('default', config('app.stripe_price_id'))->trialDays(2)->checkout($redirects);
@driesvints
Copy link
Member

That's odd since there's a failsafe for this right here which provides exactly 2 days of trial time at a minimum: https://github.com/laravel/cashier-stripe/blob/12.x/src/SubscriptionBuilder.php#L373-L378

I wonder if we should add like a minute of extra time for the API request delay. Can you try to see if the following works for you?

$trial_checkout = $user->newSubscription('default', config('app.stripe_price_id'))
    ->trialDays(Carbon::now()->addDays(2)->addMinute())
    ->checkout($redirects);

@mohsinaliryk
Copy link
Author

mohsinaliryk commented May 18, 2021

That's odd since there's a failsafe for this right here which provides exactly 2 days of trial time at a minimum: https://github.com/laravel/cashier-stripe/blob/12.x/src/SubscriptionBuilder.php#L373-L378

I wonder if we should add like a minute of extra time for the API request delay. Can you try to see if the following works for you?

$trial_checkout = $user->newSubscription('default', config('app.stripe_price_id'))
    ->trialDays(Carbon::now()->addDays(2)->addMinute())
    ->checkout($redirects);

Yes I managed to resolve the issue by adding 10 seconds.

$trial_checkout = $user->newSubscription('default', config('app.stripe_price_id'))
             ->trialUntil(Carbon::now()->addDays(2)->addSeconds(10))->checkout($redirects);

@driesvints
Copy link
Member

Sent in #1160 for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants