#legend-items
1 messages · Page 1 of 1 (latest)
could you elaborate a bit on what you're stuck on? is the question how to write the code to make an eg: json request with a bunch of IDs & parse it on the other end? or are you asking conceptually what you'd put in that request (product IDs, quantities, etc.)?
Well I'm trying to create this button/form using JS which is how I've been drawing buttons and handling their clicks. I generate a cart like this represented as an array of objects like:
I'm not sure now how to properly create this button and have it so when they click it, in my flask route in backend I have access to that JS array
then I would check in the for to verify prices, and then build the product/price list to pass to the checkout creation function
depending on how you're doing this, you can set this up as a form submit to your backend, or have an onclick event which triggers an ajax request to your backend
an ajax request would be best
are you using a specific js framework?
I tried that but I wasn't sure how to form it
no
just jqeury, js
and flask backend
you can use https://api.jquery.com/jquery.post/ to trigger a request to your backend
whatever object you put in the data param will get json-encoded, and passed to the server as the request body
the route you define in your flask app needs to parse the body as json, then do whatever handling you want on your side
So that's this route? @app.route('/create-checkout-session', methods=['POST'])
for the url param
/create-checkout-session
yeah, assuming the API is hosted by the same server the rest of the app is
(if you make a request without specifying the server, it assumes the same server as the overall page is being served by)
(you could also specify it explicitly like https://yoursite.com/create-checkout-session if you're hosting the API somewhere else, but it makes it more of a pain when you're developing from localhost, so it's easier to omit it unless required)
I'm getting closer but it's failing to redirect. I'm getting the following error:
12.12.12.12/:1 Access to XMLHttpRequest at 'https://checkout.stripe.com/pay/cs_test_a11KnkS2XEEY2LQs6Z4WkDZ9mw7ktbYzyLNx6zGLAw4S3vLqwt3gunTEBH#fidkdWxOYHwnPyd1blpxYHZxWlFcampIVGRwc2FAQXQwMUtsUXVtTDJvfScpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl' (redirected from 'http://12.12.12.12:5000/create-checkout-session') from origin 'http://12.12.12.12:5000' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled
I tried basically every fix I could find on the net but the error is persisting
are you returning a redirect to that URL from your server?
you're meant to do the url in the client if you're using ajax
by setting window.location = checkout_url
if you return a redirect from your server, the ajax request will try to follow the redirect, which is forbidden by your cors policy
but also it wouldn't do what you want even if it weren't
uh, did you mean to post your email here? if you have a question, ask it in the channel, and we can start a new thread
@fading egret I've deleted your message above & am archiving the thread. if you did have a question, please post it in the main channel
@still jolt sorry for the confusion, I thought you had left