Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Karss's avatar

Stripe - redirect two different types of users to different pages.

I have two types of users: Seller and Buyer.

Seller users->is_seller = 1 Buyer users->is_seller = 0

I am implementing a Stripe gateway to allow users to make a deposit.

Both can make a deposit to their balance. For the Seller, Stripe payment works fine, and when the Buyer makes a deposit, fills out the Stripe form for payment instead of redirecting to the Stripe success route, it redirects to buyer's dashboard.

How to force redirect to the Stripe success route?

StripeController

SellerMiddleware

public function handle(Request $request, Closure $next)
{
	$user = $request->user('web');

	if ($user && (int) $user->is_seller === 0) {
		return to_route('buyer.dashboard');
	}
	return $next($request);	
}

Buyer Middleware

public function handle(Request $request, Closure $next)
{
	$user = $request->user('web');

	if (auth()->user()->is_seller == 1) {
		return to_route('user.dashboard');
	}
	return $next($request);	
}

userRoute.php

Route::post('/deposit/stripe-submit', [StripeController::class, 'store'])->name('user.deposit.stripe.submit');
 Route::get('deposit/stripe-submit', [StripeController::class,'success'])->name('user.deposit.stripe.success');

buyerRoute.php

 Route::middleware('auth')->group(function () {
    Route::middleware(BuyerMiddleware::class)->group(function () {
    Route::post('/deposit/stripe-submit', [StripeController::class, 'store'])->name('buyer.deposit.stripe.submit');
    Route::get('/deposit/stripe-submit', [StripeController::class,' success'])->name('buyer.deposit.stripe.success');
    });
});
0 likes
6 replies
MohamedTammam's avatar

Create a redirect page in your app and handle the logic from your end.

From Stripe:

  1. Modify the success_url to pass the Checkout Session ID to the client side.
  2. Look up the Checkout Session using the ID on your success page.
  3. Use the Checkout Session to customize what’s displayed on your success page.
session = Stripe::Checkout::Session.create(
  success_url: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}",
)

https://docs.stripe.com/payments/checkout/custom-success-page

Karss's avatar

Hi ghabe, Thank you for your help. I did all your recommendations.

Now with the Route::middleware(BuyerMiddleware::class)->group(function () { >>> "Target class [BuyerMiddleware] does not exist".

Without it, after payment, it is redirecting to buyer dashboard, but with the not completed payment. This is because it should redirect to the success route, but it doesn't.

The payment from the Seller side still fine.

Karss's avatar

I solved the problem by simply moving both routes to web.php.

Please or to participate in this conversation.