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'
]);
}
What is the redirect URL you want for successful payments?
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'
]);
can anyone help me here please?
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);
Is Stripe server or user supposed to call subscribe()?
If user, try ending your function with
return redirect()->intended('/home')->getTargetUrl();
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)
});
}
...
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
Can you expand {data: {...}}? What is in the ...?
I was unable to expand this as the alert was on the screen and then the page redirected
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.
that's what it was originally but without an extra closing parenthesis )
My bad. Parenthesis removed.
It is different, originally, you were using success_url, I changed it to success.
YAY! Thank you thank you Laracoft!!!!!!
Please or to participate in this conversation.