search

Home  >  Q&A  >  body text

Redirect Laravel to Stripe session URL

<p>After creating the Stripe checkout session in my controller, I am trying to redirect it by using </p> <pre class="brush:php;toolbar:false;">return redirect($session->url);</pre> <p>But I keep getting a CORS error. <br /><br />I can add the URL and go there manually without any problems. <br /><br />However, according to this article</p><p><br /></p> <blockquote> <p>Getting a CORS error when trying to onboard users to Stripe Connect with Node.js</p> </blockquote> <p>The solution is to return the URL from the server to the client and let him redirect from there. <br /><br />Can anyone tell me how to do this in Laravel?</p><p><br /></p>
P粉897881626P粉897881626568 days ago592

reply all(1)I'll reply

  • P粉617237727

    P粉6172377272023-08-08 00:58:44

    You can return the URL instead of redirecting:

    return response()->json([
        'redirect_url' => $session->url
    ]);

    and redirect the user from the client. You will get the redirect url in the JSON response. Handle it accordingly.

    Assuming the client uses AJAX, you can use the following command to redirect the user:


    success: function (data) {
        window.location.href = data.redirect_url;
    }

    reply
    0
  • Cancelreply