Is anyone able to assist in showing me how to send multiple items to a Stripe checkout session? I have it working with a single item but I don’t know how to handle that there will be a dynamic number of items in each basket.
I haven’t worked with the form data stuff that much but I’m assuming I need to create an array in the workflow but how do I send that given the need to have the [0] for the first item, [1] for the second etc?
Backend workflows: Create an API workflow, and then at the end of that workflow, “Schedule an API workflow” (the same exact one you just added the workflow to). It will allow you to use “Schedule API workflow on a List” in which you would do that with your list of orders/items.
Sorry, I’m not quite following how that would help in this case. I get the logic of the loop but won’t that just create 10 checkout sessions each with a unique id. I need to send it in a single payload don’t I?
Each consecutive item you add 1 with the first item always starting with 0 (as the initial index). line_items[0][price]=price_1MotwRLkdIwHu7ixYcPLm5uZ line_items[0][quantity]=2 line_items[1][price]=price_1MotwRLkdIwHe23D1dszzs133 line_items[1][quantity]=1
Ok so I’m following that but I guess my question is that when setting up the API to initialize it, say I create those 4 fields to send as part of the URL encoded call as Stripe doesn’t accept json body.
If the next customer has 3 items how to I create the new field “line_items[3]” to be able to send the third product? Apologies If I’m being super simple here - appreciate the help!
Ah. So get rid of everything except “success_url”, and “mode” in your parameters. Your “client_reference_id” should also be a shared and hidden header.
Now this is the basic structure non-dynamic, right? So, we’ll add the props:
{
line_items: [
<items>
]
}
Now it will need the same structure as the object above, separated by commas. Each item after will count as the next item.Make sure your objects are separated by commas.
So that didn’t work either - I get an error saying it has to be the form-urlencoded Content-Type. I think I just need to know how to do an array inside the line_items “Key” section but not sure if that’s possible!
Take a json and serialize it to URL that work with Stripe (and other API with similar request)
@Thimo didn’t make a new test page actually. But if we use the @GH5T example, the result will be: line_items[0][price]=price_1MotwRLkdIwHu7ixYcPLm5uZ&line_items[0][quantity]=2&line_items[1][price]=price_1M433999439Lm5uZ&line_items[1][quantity]=1&line_items[2][price]=price_3LkdIw441PLm5uZ&line_items[2][quantity]=1
It’s very complex with just plain Bubble action. But not impossible (mostly because actually, there’s no “index” of the current item for a list in Bubble function)
BTW, the reason why you got the error for Cannot parsed as JSON, is because you have missing double quotes around line_items. This is a Bubble error and not API response error (I think it’s a new feature…) However, from what I know, Stripe doesn’t accept json content-type
Thanks this is great. Just to check - so my thoughts are to have a payment button which:
Gets the list of products and formats the Json
Use the plugin to serialize it
Make the API call with that serialized
However, how do you setup a form-url encoded API call that allows me to pass that dynamic list into it? From what I can see, if I add a Parameter called “line_items” then have the serialised text it’s not going to work is it?
I encountered the same problem as you at the beginning. I manage to initialize the call and receive the data. But only in the API Connector.
My initialize call is correct, I have the data displayed.
key : line_items
value : line_items[0][price]=price_1Q16iIBG8gDoGKFTHszpB2SN&line_items[0][quantity]=2&line_items[1][price]=price_1Q16ioBG8gDoGKFTt6kpNWO3&line_items[1][quantity]=10&