#peppemu-checkout
1 messages ยท Page 1 of 1 (latest)
@fathom raptor hello! do you have a request ID req_xxx (https://support.stripe.com/questions/finding-the-id-for-an-api-request) for the error you get, and the exact code you're using to call the API?
hi @pearl whale
sure
one sec
oh wait a sec
the error might be somewhere else
I cant find the request id cause the request does not show up in the logs
so, checking the browser I saw that I was missing the auth part of the request body
I am gonna test this now and see what I get
ok, I am getting another error now but I guess that's another question then
sorry, didnt want to waste your time, thanks for the quick reply
do you have any tip on how to convert a json array to url form-urlencoded?
my advice would be to use our libraries https://stripe.com/docs/libraries
you should never need to do that conversion of a JSON object to formdata yourself since you'd use our libraries which take the parameters in an idiomatic format and make the appropriately-formatted API call for you.
ok I see, thanks
I am not sure if I found what I need though
I am adding a js on a checkout page to get element of the page (shipping, lineItems, price_id, qty, ...) to create a checkout session and redirect the user to it
I used a json body in the request and this does not work cause the request must have a form-urlencoded body
hence I was looking for a method to convert that, would one of the libraries also work ?
or do you have another recommendation ?
Hello! As @pearl whale explained, your best bet is to use one of our server libraries for creating a Checkout Session
You shouldn't be making an API call to create a Session via your client application (security concerns etc)
hi @raw silo,
thanks for the feedback,
I am new to this kind of dev and I am finding my way through it, appreciate your help
๐
This integration sample is a good starting point: https://stripe.com/docs/checkout/quickstart
There's front-end 'checkout' form which submits to a server which creates the Checkout Session and redirects the user
thanks ynnoj, will have a look now.
sorry for the late reply ๐
Np!
ok, I'll test this out, I am trying to have this implemented on a checkout page of webflow
just fyi
Hmm, you'll need a server component which I don't think Webflow offers?
that's the tricky part I guess
but so far I am able to deploy a script on the checkout page and then redirect to a stripe checkout page (also including line items, shipping rates)
and I tested this by hardcoding line items and shipping rates, however with the final version I need to iterate through the cart items, get the price_id and the quantity of each item and then add them to the request body
this is for me easily done with a json array, and that's why I asked how could I then convert that into a form-urlencoded
not sure if it is clear, and if there is something wrong in this approach, please let me know, as I said I am new this kind of dev
Hey there ๐ I'm getting caught up on this thread.
Can we take a step back and understand the larger process you're working on, and then drill back into the step where you're having problems?
It sounds like your customers have a cart on your site. Then when they check out, is this cart information being returned to your server?
hi toby, thanks for stepping in
so I think an important starting point is that I am using webflow (not sure how familiar you are with it)
now, our plan is to generate a stripe checkout session with info a user provides on a page.
the checkout session has to include line items (retrieved from stripe) and shipping rate (retrieved from stripe)
now, I dont manage the server as our site is hosted on webflow
I tried to generate checkout session (test mode) using javascript on this checkout page.
I am able to generate a session.
This was easy by hardcoding the elements.
the point where I am stuck is to convert a json array (basically the body of the request) to urlencoded (given the requirement of the api)
so I was also asking if there is any alternative to this approach which I could use or any other recommendation
...I am still validating this whole process
Understood, I'd strongly discourage you from creating the checkout session on the client side. This approach could allow users to manipulate the provided js files and alter how the session is created.
Ideally you'd have a flow something like this:
- Collect cart information (how this happens is entirely up to you)
- Pass cart details to your server
- Have your server retrieve any necessary product/price IDs
- Generate the checkout session on your server
- Have your server's response redirect your customer to the checkout session link