Skip to content

Subscription Trials

If you would like to offer trial periods to your customers while still collecting payment method information up front, you should use the trialDays method when creating your subscriptions:

$user = User::find(1);
$user->newSubscription('main', 'monthly')
->trialDays(10)
->create();

This method will set the trial period ending date on the subscription record within the database.

The trialUntil method allows you to provide a Carbon instance to specify when the trial period should end:

use Carbon\Carbon;
$user->newSubscription('main', 'monthly')
->trialUntil(Carbon::now()->addDays(10))
->create();

You may determine if the user is within their trial period using either the onTrial method of the user instance, or the onTrial method of the subscription instance. The two examples below yield the same result:

if ($user->onTrial('main')) {
//
}
if ($user->subscription('main')->onTrial()) {
//
}

If you would like to offer trial periods without collecting the user’s payment method information up front, you may set the trial_ends_at column on the user record to your desired trial ending date. This is typically done during user registration:

$user = User::create([
// Populate other user properties...
'trial_ends_at' => now()->addDays(10),
]);

Cashier refers to this type of trial as a “generic trial”, since it is not attached to any existing subscription. The onTrial method on the User instance will return true if the current date is not past the value of trial_ends_at:

if ($user->onTrial()) {
// User is within their trial period...
}

You may also use the onGenericTrial method if you wish to know specifically that the user is within their “generic” trial period and has not created an actual subscription yet:

if ($user->onGenericTrial()) {
// User is within their "generic" trial period...
}

Once you are ready to create an actual subscription for the user, you may use the newSubscription method as usual:

$user = User::find(1);
$user->newSubscription('main', 'monthly')->create();