#peppemu-checkout

1 messages ยท Page 1 of 1 (latest)

pearl whale
fathom raptor
#

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?

pearl whale
#

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.

fathom raptor
#

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 ?

raw silo
#

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)

fathom raptor
#

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

#

๐Ÿ™‚

raw silo
#

There's front-end 'checkout' form which submits to a server which creates the Checkout Session and redirects the user

fathom raptor
#

thanks ynnoj, will have a look now.
sorry for the late reply ๐Ÿ™‚

raw silo
#

Np!

fathom raptor
#

ok, I'll test this out, I am trying to have this implemented on a checkout page of webflow

#

just fyi

raw silo
#

Hmm, you'll need a server component which I don't think Webflow offers?

fathom raptor
#

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

unborn mason
#

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?

fathom raptor
#

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

unborn mason
#

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:

  1. Collect cart information (how this happens is entirely up to you)
  2. Pass cart details to your server
  3. Have your server retrieve any necessary product/price IDs
  4. Generate the checkout session on your server
  5. Have your server's response redirect your customer to the checkout session link
fathom raptor
#

all right, this is super helpful

#

thanks toby ๐Ÿ’ฏ

#

I'll spin my head around this to find a viable solution given our infrastructure

#

again, thanks everyone for your inputs, I find this channel extremely useful ๐Ÿ‘ ๐Ÿ™‚