【发布时间】:2021-09-18 10:40:30
【问题描述】:
我正在使用Laravel Cashier / Stripe Checkout(订阅)。
我有多个计划,我只想有一个页面 (/subscribe),其中将列出所有计划,并且每个计划都会有一个链接(按钮)将用户发送到 Stripe Checkout 页面(订阅)。
当用户访问/subscribepage 时,我会为每个计划启动 Stripe Checkout 会话:
Route::get('/subscribe', function () {
$checkout1 = Auth::user()->newSubscription('Supporter', 'price_1')->checkout([
'success_url' => route('dashboard'),
'cancel_url' => route('dashboard'),
'client_reference_id' => auth()->id(),
]);
$checkout2 = Auth::user()->newSubscription('Supporter', 'price_2')->checkout([
'success_url' => route('dashboard'),
'cancel_url' => route('dashboard'),
'client_reference_id' => auth()->id(),
]);
$checkout3 = Auth::user()->newSubscription('Supporter', 'price_3')->checkout([
'success_url' => route('dashboard'),
'cancel_url' => route('dashboard'),
'client_reference_id' => auth()->id(),
]);
$checkout4 = Auth::user()->newSubscription('Supporter', 'price_4')->checkout([
'success_url' => route('dashboard'),
'cancel_url' => route('dashboard'),
'client_reference_id' => auth()->id(),
]);
// ... AND MANY MORE ...
$checkout10 = Auth::user()->newSubscription('Supporter', 'price_10')->checkout([
'success_url' => route('dashboard'),
'cancel_url' => route('dashboard'),
'client_reference_id' => auth()->id(),
]);
return view('subscribe', compact('checkout1', 'checkout2', 'checkout3', 'checkout4' ... '$checkout10'));
});
这是错误的和坏的吗?我问是因为启动所有这些会话似乎会减慢 /subscribepage 的加载速度,我猜这是因为每当我们调用 checkout() 方法(启动会话)时 - 将进行新的 API 调用 + Cashier 会命中数据库。
如果同时启动多个会话是错误的,那么正确的方法是什么?我知道我可以为每个计划添加额外的页面(视图),然后每页只有一个会话启动,但我想尽可能避免(我只想要一个带有计划的页面列出,每个计划都有自己的“订阅”按钮,当用户点击该按钮时 - 他直接进入 Stripe)。
【问题讨论】:
标签: laravel-cashier stripe-payments