#RafaCitec-checkout-cors

1 messages · Page 1 of 1 (latest)

heavy dragon
#

Hey! Happy to help

#

How are you integrating with Checkout? Is the error when you're trying to redirect to the URL?

dull walrus
#

yes

#

I use in frontend React and in backend FastApi (Python)

#

initially in fronted with a simple form works, backend redirect

#

but when I have added a few of complexity

#

send token to backend for send to Stripe, now show CORS error in Chrome

heavy dragon
#

Are you doing the redirect in your Python backend?

dull walrus
#

here:

heavy dragon
#

Yep that'll be the issue

#

You can't really redirect server-side when you're using fetch like that in JS

#

If you want to use fetch inside a submit function, I'd recommend just redirecting inside of your React function; window.location.assign(checkoutSession.url)

dull walrus
#

I first used a simple <form> like in your tutorials, which didn't send a token
but I needed to send the token to the backend for security and a normal <form> in React was no longer worth it, or do you know how to do it with a submit from React that can send the params that I want to the back?

heavy dragon
#

As stated, you can keep your React form as it is. You should just remove the redirect from your Python code and return the JSON to your front-end

#

Then you can redirect in JS

dull walrus
#

ok, how do I pass the checkout object to the window.location.assign(checkoutSession.url) statement?

heavy dragon
#

You need to update your Python function return statement:
return json.dumps(checkout_session)

#

then in your handleSubmit React function:

window.location.assign(checkoutSession.url)
dull walrus
open garden
#

cool, looks good

#

so what's blocking you now? you commented out the line that assigns to window.location , is there a reason?

dull walrus
#

yes, look at the console.log
checkoutSession.url is undefined

open garden
#

hmm, not sure how it could be since url is clearly in the object printed in the line above

#

my guess is your backend is not returning the right Content-Type header

#

so that the json() on the fetch response doesn't know to turn it into a Javascript object

#

make sure your Python backend returns the response with Content-Type: application/json if it's returning JSON.

dull walrus
#

no problem, with this changes works

open garden
#

yeah that would work too but it's a bit of a hack since res.json() will just do that for you if the header was set semantically

dull walrus
#

I don't know, in back now is there

open garden
#

what are you asking exactly?

dull walrus
#

nothing is all right

#

thanks for your helo