@dushaun That if() statement doesn’t look right. There’s no && or || in between ! $request->user()->subscribed('subscriber') and ! $request->user()->subscribed('premium').
Laravel Cashier: Failed Registration Redirect?
Hi There,
I'm currently sorting out webhooks for Stripe in a project I'm working on. The task at hand is when a user tries to register to the website and because their card fails, the user does not receive a subscription status in the subscriptions table.
With this, how would you go about writing middleware to redirect the failed registered user to their account page to update their card information, and redirect a guest to the billing page if they try to access certain pages for subscribed users.
I've tried the demo given in the Laravel docs:
public function handle($request, Closure $next)
{
if ($request->user() &&
! $request->user()->subscribed('subscriber') ||
! $request->user()->subscribed('premium')) {
if (Auth::check()) {
// This user has signed up but membership has failed or expired
} else {
// This user is not a paying customer...
return redirect('billing');
}
}
return $next($request);
}
Can anyone give me any tips please? Thanks
@martinbean yes I realised my mistake with misunderstanding Laravel Cashier, my misunderstanding lead to my confused code you see above.
I've resolved the issue by having a dedicated middleware for checking whether the user is subscribed or not. Another handling premium tier. A guest just gets directed to a login page with options to choose subscription.
Here's an example of the subscribed middleware:
public function handle($request, Closure $next)
{
if ($request->user() && ! $request->user()->subscribed('primary')) {
// This user has signed up but membership has expired
return redirect('settings/subscription/card');
}
return $next($request);
}
I've also setup a webhooks controller to handle Stripe events.
Please or to participate in this conversation.