dpl3350 2015-12-04 23:24
浏览 37
已采纳

无法在Laravel Cashier 4.2中设置订阅试用版,以便客户不会立即收取费用

I'm currently using Laravel Cashier (4.2) with Stripe. The current Stripe API version I'm using is 2014-06-17. I have tried in various ways to set the trial end date when creating a subscription. I have tried all kinds of variations of this code:

$company->trial_ends_at = Carbon::now()->addDays(14);
// Also tried this variation of the trial date
// $trialEndDateUnixTimestamp = strtotime(Carbon::parse($company->trial_ends_at));

$company->subscription('annual')
        ->create($creditCardToken, ['description'=>$company->company_name, 'email'=>Auth::user()->email], null);

$company->trial_ends_at = Carbon::now()->addDays(14);;
$company->save(); 

When I look at the request sent to Stripe, trial_end is always null. Any ideas are appreciated.

The official Laravel Cashier documentation states the following:

$user->subscription('monthly') ->withCoupon('code') ->create($creditCardToken);

The subscription method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information. If your plan has a trial configured in Stripe, the trial end date will also automatically be set on the user record.

If your plan has a trial period that is not configured in Stripe, you must set the trial end date manually after subscribing:

$user->trial_ends_at = Carbon::now()->addDays(14);

$user->save();

The manual setting of the trial date is what seems to not be working. I tried the method outlined by the official docs, and the user is always charged right away because for some reason the trial period is not being applied.

The more I look at the documentation, the more I think it doesn't even support trial periods if it's not on the Stripe side. The key lines are: "If your plan has a trial period that is not configured in Stripe, you must set the trial end date manually after subscribing", but by that point, the subscription has already been created, and thus the charge has already been made....

  • 写回答

3条回答 默认 最新

  • douqianrou9079 2015-12-07 17:46
    关注

    By pure chance, I came across this issue posted in the Laravel Cashier repository.

    The answerer of the question said this:

    Not in the docs for some reason, but you can do:

    $user->subscription($plan) ->trialFor($user->trial_ends_at) ->create($creditCardToken, ['email' => $user->email, 'description' => $user->name ]);

    This solves my question as it creates the subscription but does not charge the user right away if they have a free trial. I can verify this by looking on the Stripe dashboard and seeing that the trial field has been applied to the subscription.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向