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

boyjarv's avatar

Page gets redirected to undefined after stripe payment

Please help, after a stripe payment has been made, my page then gets redirected to https://www.bnhere.co.uk/undefined

here is my method in my controller:

public function subscribe(Request $request)
    {
        $user = auth()->user();
        $venueid = $user->venue_id;
        $paymentMethod = $request->payment_method;
        $planId = $request->plan;
        $user->newSubscription('main', $planId)->create($paymentMethod);
//        $venueid = Venue::where('user_id',$userid)->get();


        return response([
            'success_url'=>redirect()->intended('/venue/'.$venueid.'/edit')->getTargetUrl(),
            'message'=>'success'
        ]);
    }
0 likes
14 replies
laracoft's avatar

What is the redirect URL you want for successful payments?

boyjarv's avatar

I just changed the URL to redirect to /home

I still get redirected to: https://bnhere.co.uk/undefined

here is my return response:

return response([

            'success_url'=>redirect()->intended('/home')->getTargetUrl(),
            'message'=>'success'
        ]);
boyjarv's avatar

would it be anything to do with php7.4 and same site?

should I implement the following somewhere?!

$cookie_options = array(
  'expires' => time() + 60*60*24*30,
  'path' => '/',
  'domain' => '.domain.com', // leading dot for compatibility or use subdomain
  'secure' => true, // or false
  'httponly' => false, // or false
  'samesite' => 'None' // None || Lax || Strict
);

setcookie('cors-cookie', 'my-site-cookie', $cookie_options);

laracoft's avatar

Is Stripe server or user supposed to call subscribe()?

If user, try ending your function with

return redirect()->intended('/home')->getTargetUrl();
laracoft's avatar

This should work

return response([
    'data' => [
        'success' => redirect()->intended('/home')->getTargetUrl(),
        'message' => 'success'
    ]
]));

If it does not, add below to your blade and show the output here

...
} else {
    console.log('handling success', setupIntent.payment_method);
    axios.post('/subscribe',{
        payment_method: setupIntent.payment_method,
        plan: plan
    }).then((data)=>{
        console.log(data)
        alert(data)
        location.replace(data.data.success)
    });
}
...
boyjarv's avatar

Thanks laracoft the return response you suggested did not work.

I added the code in my blade template and I got [object object] alerted to the screen

and in the console:

{data: {...}, status: 200, statusText: "", headers: {...}, config: {...}, ...}


subscribe:234
laracoft's avatar

Can you expand {data: {...}}? What is in the ...?

boyjarv's avatar

I was unable to expand this as the alert was on the screen and then the page redirected

laracoft's avatar
laracoft
Best Answer
Level 27

Ok, I think this should work

return response([
    'success' => redirect()->intended('/home')->getTargetUrl(),
    'message' => 'success'
]);

Otherwise really need to see your expanded console.log()

alert() can now be removed as I wasn't sure if you knew how to access the console.

boyjarv's avatar

that's what it was originally but without an extra closing parenthesis )

laracoft's avatar

My bad. Parenthesis removed. It is different, originally, you were using success_url, I changed it to success.

boyjarv's avatar

YAY! Thank you thank you Laracoft!!!!!!

Please or to participate in this conversation.