#RafaCitec-checkout-cors
1 messages · Page 1 of 1 (latest)
Hey! Happy to help
How are you integrating with Checkout? Is the error when you're trying to redirect to the URL?
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
Are you doing the redirect in your Python backend?
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)
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?
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
ok, how do I pass the checkout object to the window.location.assign(checkoutSession.url) statement?
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)
cool, looks good
so what's blocking you now? you commented out the line that assigns to window.location , is there a reason?
yes, look at the console.log
checkoutSession.url is undefined
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.
no problem, with this changes works
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
I don't know, in back now is there
what are you asking exactly?