无法在 Laravel Cashier 4.2 中设置订阅试用,这样客户就不会立即被收费
Unable to set trial for subscription in Laravel Cashier 4.2 so that customer does not get charged right away
我目前正在使用 Laravel Cashier (4.2) 和 Stripe。我当前使用的 Stripe API 版本是 2014-06-17。在创建订阅时,我尝试了多种方式来设置试用结束日期。我已经尝试了此代码的各种变体:
$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();
当我查看发送到 Stripe 的请求时,trial_end
总是 null
。任何想法表示赞赏。
官方Laravel Cashier documentation声明如下:
$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();
试用日期的手动设置似乎不起作用。我尝试了官方文档中概述的方法,并且总是立即向用户收费,因为由于某种原因未应用试用期。
我看文档越多,我越认为如果它不在 Stripe 端,它甚至不支持试用期。关键行是:"If your plan has a trial period that is not configured in Stripe, you must set the trial end date manually after subscribing",但到那时,订阅已经创建,因此费用已经产生....
据我所知,您必须在订阅客户后设置试用结束时间。
像这样:
$trialEndDateUnixTimestamp = strtotime(Carbon::parse($company->trial_ends_at));
$customer->subscription('annual')
->create(NULL, $customer);
$customer->trial_ends_at = $trialEndDateUnixTimestamp;
$cusomer->save();
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of App\User. Once you have retrieved the model instance, you may use the subscription method to manage the model's subscription:
$user = User::find(1);
$user->subscription('monthly')->create($creditCardToken);
The create 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 you want to implement trial periods, but are managing the trials entirely within your application instead of defining them within Stripe, you must manually set the trial end date:
$user->trial_ends_at = Carbon::now()->addDays(14);
$user->save();
$company->trial_ends_at = date('Y-m-d', strtotime("+14 days"));
纯属偶然,我遇到了this issue posted in the Laravel Cashier repository。
问题的回答者是这样说的:
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
]);
这解决了我的问题,因为它创建了订阅,但如果用户有免费试用,则不会立即向他们收费。我可以通过查看 Stripe 仪表板并查看试用字段已应用于订阅来验证这一点。
我目前正在使用 Laravel Cashier (4.2) 和 Stripe。我当前使用的 Stripe API 版本是 2014-06-17。在创建订阅时,我尝试了多种方式来设置试用结束日期。我已经尝试了此代码的各种变体:
$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();
当我查看发送到 Stripe 的请求时,trial_end
总是 null
。任何想法表示赞赏。
官方Laravel Cashier documentation声明如下:
$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();
试用日期的手动设置似乎不起作用。我尝试了官方文档中概述的方法,并且总是立即向用户收费,因为由于某种原因未应用试用期。
我看文档越多,我越认为如果它不在 Stripe 端,它甚至不支持试用期。关键行是:"If your plan has a trial period that is not configured in Stripe, you must set the trial end date manually after subscribing",但到那时,订阅已经创建,因此费用已经产生....
据我所知,您必须在订阅客户后设置试用结束时间。
像这样:
$trialEndDateUnixTimestamp = strtotime(Carbon::parse($company->trial_ends_at));
$customer->subscription('annual')
->create(NULL, $customer);
$customer->trial_ends_at = $trialEndDateUnixTimestamp;
$cusomer->save();
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of App\User. Once you have retrieved the model instance, you may use the subscription method to manage the model's subscription:
$user = User::find(1);
$user->subscription('monthly')->create($creditCardToken);
The create 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 you want to implement trial periods, but are managing the trials entirely within your application instead of defining them within Stripe, you must manually set the trial end date:
$user->trial_ends_at = Carbon::now()->addDays(14);
$user->save();
$company->trial_ends_at = date('Y-m-d', strtotime("+14 days"));
纯属偶然,我遇到了this issue posted in the Laravel Cashier repository。
问题的回答者是这样说的:
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 ]);
这解决了我的问题,因为它创建了订阅,但如果用户有免费试用,则不会立即向他们收费。我可以通过查看 Stripe 仪表板并查看试用字段已应用于订阅来验证这一点。