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条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?