Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Swaz's avatar
Level 20

Cashier: Add trial end date when creating a subscription

I am playing around with Cashier. A user can sign up without a credit card, for a 30 day free trial. I am manually setting the trial_ends_at date in the db when the user signs up. Later on when they choose a subscription, I am creating it like this:

$user->subscription('monthly')
     ->quantity($qty)
     ->trialFor($trail_ends_at)
     ->create($token);

This works great, except for when the trial date has expired. I get an error:

Stripe_InvalidRequestError in ApiRequestor.php line 147:
Invalid timestamp: must be an integer Unix timestamp in the future.

So my only solution is to manually check if the trial has expired and have 2 different create user subscription functions. Is there any way around this?

0 likes
3 replies
toniperic's avatar

If they are later creating a subscription, like you have showed

$user->subscription('monthly')
     ->quantity($qty)
     ->trialFor($trail_ends_at)
     ->create($token);

why are you calling the trialFor() method there again?

Swaz's avatar
Level 20

@toniperic Because they have a 30 day trial, so if they start a subscription after 5 days, I do not want them to be billed until the remaining 25 days are used up.

WKMG's avatar

I did the same exact thing as you. Just did the manual check.

  $trialEndDate = Carbon::createFromTimestamp(strtotime($company->trial_ends_at));

   if($trialEndDate->isFuture()) ...

Please or to participate in this conversation.