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

david001's avatar

laravel cashier start charging after trial period

I am using laravel8 and cashier stripe. I want to charge user only after their trial period which is one month(30 days trial). In users table I have trial_expiry column which include trial expiry date(for example: 2022-06-30). Lets say my trial will expire in 20 days from now and user want to take one of monthly plan now(eg: business plan). Now I want to charge user only after his trial period even if he subscribes to plan before his trial finish. I wrote some code below, but I am not sure how to achieve it.

  public function upgradeFromTrial(Request $request) {
        $request->user()->newSubscription(
            'default',
            $request->priceId
        )->trialUntil(now()->addMonth())->create($request->token);
  }

Any help? Thanks

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

So when you create the user, you are just setting the expiry date of the trial, but you are not creating a subscription from what I can see in the code above.

So if the user wants to upgrade in the middle of the trial period, you should not use now()->addMonth() because that will give them new 30 days. So with your example above, if 10 days already passed, and they chose a plan, you are giving them 30 days from the day they chose a plan.

This should do it:

public function upgradeFromTrial(Request $request) {
	$user = $request->user();
	if ($user->onTrial())
    {
    	$user->newSubscription(
            'default',
            $request->priceId
        )->trialUntil($user->expiry_date)->create($request->token);
    }
	else
	{
		$user->newSubscription(
            'default',
            $request->priceId
        )->create($request->token);
	}
}

Please or to participate in this conversation.