Laravel Cashier: should I add a trial period in St

2019-08-20 08:23发布

Quoting Laravel Cashier documentation:

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.

Assuming I want to add a 30 days trial period to my subscriptions, I can create a subscription with this code:

$user->newSubscription('main', 'monthly')
        ->trialDays(30)
        ->create($stripeToken);

As a Stripe user, should I add a trial period in Stripe plan too?

enter image description here

I'm not sure to understand the logic of Laravel Cashier here. It seems redundant to declare something at two different places.

3条回答
老娘就宠你
2楼-- · 2019-08-20 08:56

I would say its not necessary. If you're adding trial days at the time of subscription creation (trial_end parameter when using the API directly), that will take precedence over the trial days defined on a plan anyway!

查看更多
再贱就再见
3楼-- · 2019-08-20 08:59

I'm not 100% satisfied with these answers, since the question was specifically asking about using Cashier.

Creating a subscription using Cashier will always set a trial_end

protected function buildPayload()
{
    return array_filter([
        'billing_cycle_anchor' => $this->billingCycleAnchor,
        'coupon' => $this->coupon,
        'metadata' => $this->metadata,
        'plan' => $this->plan,
        'quantity' => $this->quantity,
        'tax_percent' => $this->getTaxPercentageForPayload(),
        'trial_end' => $this->getTrialEndForPayload(),
    ]);
}

This trial_end will either be "now" (no trial) by default or whatever you pass optionally in ->trialDays(XXX).

The trial period that is defined within Stripe seems to be ignored.

I agree, the expected behaviour should be that what you pass via cashier will take precedence over the trial days defined on a plan. However this doesn't seem to be the case. (cashier v8.0.1)

查看更多
Root(大扎)
4楼-- · 2019-08-20 09:18

If you define a trial period in stripe then there is no need to do it in code. If you you don't want trial every time someone subscribes you might want to have it in code.

查看更多
登录 后发表回答