curl https://api.stripe.com/v1/checkout/sessions \
-u sk_test_: \
-d success_url="https://example.com/success" \
-d cancel_url="https://example.com/cancel" \
-d "line_items[0][price]"=price_H5ggYwtDq4fbrJ \
-d "line_items[0][quantity]"=2 \
-d mode=payment
Can someone help me visualize just how would I go about making the line items an array in api connector?
1 Like
Sending an array in a stripe api call requires a bit of a hack.
you’ll have to build the entire array as a string value
So if you want to add the parameter line_items[0][price]=price_abcd
It will have to be the value of another key that you define.
So in the API connector, you can do
https://api.stripe.com/v1/checkout/sessions?[param1]
where param1’s value is line_items[0][price]=price_abcd
It’s not ideal by any stretch but that’s what I’ve resorted to in such cases.
Else I’d just use a plugin that has this functionality built in. I think the stripe.js 2 plugin has these things set up.
@atomicfusion Yea, but if there’s multiple line items? That’s where I’m having trouble.
It would look like this for multiple:
line_items[0][price]=price_H5ggYwtDq4fbrJ
line_items[0][quantity]=2
line_items[1][price]=price_H5ggYwtDq4fbrJ
line_items[1][quantity]=2
line_items[2][price]=price_H5ggYwtDq4fbrJ
line_items[2][quantity]=2
Etc. increasing the count in the key.
Yea I figured that should be the case. But how would that exactly look as a querystring?
Each query parameter (key + value) would have to be inserted as a value.
So instead of using <api_path>?paramName=[myVal]
And then defining [myVal] as the parameter’s value
You define the entire “paramName=paramValue” substring as a value to another key
So it looks like <api_path>?[paramString1]
where [paramString1] takes the value “paramName=paramValue”
You can manipulate the way Bubble’s API connector lets you directly insert a string into the URL.
But you’ll have to do this for each property of each line item in your case.
so [paramString1] would be "line_items[0][price]=price_xyz"
so [paramString2] would be "line_items[0][quantity]=2"
so [paramString3] would be "line_items[1][price]=price_abc"
so [paramString2] would be "line_items[1][quantity]=2"
and so on
and your URL would look like <api_path>?[paramString1]&[paramString2]&[paramString3]&[paramString4]
Cheers,
Ranjit from Atomic Fusion
Explore and reuse the community’s Bubble assets & Accelerate your Bubble development with Atomic Fusion
1 Like
Roger that. Seems maybe a checkout session might not be ideal for my situation in Bubble.
1 Like
understandable
Wish there was a better way to do this!
so in your apps you use arbitrary text (I assume) to build these strings to be able to have a flexible mixed cart?