Stripe issues.

529 views
Skip to first unread message

Dylan Evans

unread,
Mar 2, 2022, 11:20:35 AM3/2/22
to Stripe API Discussion
I am trying to use strip checkout, I have attached 5 images of what I have in my backend and what my browser is showing. The link returned from the backend works and takes me to a new tab if I click but no automatic redirect. I am get a cors error.

I have enabled cors in my Django backend by pip install django-cors-headers, adding to installed apps, and configuring the middleware to include it at the top. But for some reason, I am still getting the error in the attached image in the console and network tab. Please can somebody direct or help me allow this to work.
Screenshot 2022-03-02 at 10.18.20.png
Screenshot 2022-03-02 at 10.18.33.png
Screenshot 2022-03-02 at 10.21.36.png
Screenshot 2022-03-02 at 10.24.13.png
Screenshot 2022-03-02 at 10.19.01.png

Remi J.

unread,
Mar 2, 2022, 11:27:56 AM3/2/22
to api-d...@lists.stripe.com
Hello Dylan,

That error is often due to a mismatch between your server-side and client-side code. The screenshots you shared show the server-side code where you create a Checkout Session and then you directly redirect to the Session's URL from the server. This is likely due to your client-side code using `fetch()` or similar (such as an AJAX call). When that happens, the client-side code expects a response back from the server that they can process and action, but the server is instead trying to abort the flow and redirect, which is where you get that CORS error.

The easiest fix here is to change your client-side code to move to a form submission or similar. You'd have a button that can be clicked and when that happens there's a form submission for the whole page that then lets your server control what to do next, whether to redirect to the Checkout Session's URL or display an error. This is what we document in our quickstart which you can see here: https://stripe.com/docs/checkout/quickstart

Alternatively, if you stick with your current client-side code, you need to change your server-side Python code to return the Checkout Session's id instead of doing a redirect. You'll have it return for example `{session_id: checkout_session.id}` and your client-side code can parse the JSON, extract that id and use the `stripe.redirectToCheckout()` call that you have likely built.

I hope this helps! If you have any follow up questions, I recommend reaching out to our support team instead so that they can help you directly: https://support.stripe.com/contact

Best,
Remi

On Wed, Mar 2, 2022 at 8:20 AM Dylan Evans <dweva...@gmail.com> wrote:
I am trying to use strip checkout, I have attached 5 images of what I have in my backend and what my browser is showing. The link returned from the backend works and takes me to a new tab if I click but no automatic redirect. I am get a cors error.

I have enabled cors in my Django backend by pip install django-cors-headers, adding to installed apps, and configuring the middleware to include it at the top. But for some reason, I am still getting the error in the attached image in the console and network tab. Please can somebody direct or help me allow this to work.

--
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages