How to use Stripe Shipping Options?

shippingoptions

ship2

retrieveshippingrateoutput

Could someone give me an example of how to use this? (this is a stripe checkout session server action) I cannot seem to get my stripe checkout to allow me to do shipping options. I've tried using the "list shipping rates" or "retrieve shipping rates" objects in here as well as actual stripe shipping id's, but I always get a response "invalid array" and it breaks my checkout.

I finally have everything else working except for this last thing so I would really love some help, I can't find any wappler documentation on this piece

Ideally I wan to put different retrieve shipping actions, 1 for standard shipping and 1 for expediated, and then put in both of their id's into the checkout so the user can choose which option they want.

Thanks mates!

@Teodor Could you offer some assistance? You seem to be the man with the answers I'm pretty stuck on this one :confused:

@George Hey George any insight here? I'm not trying to bug you guys I know there's lots of stuff to fix for the app connect 2 rollout but my client is really pushing me to launch this week and this is my last major issue. This stuff is beyond my understanding, I just need a hint :slight_smile:

I'm afraid I won't be much help to you as I have never set up shipping options but maybe the Stripe documentation can give you a hint if you haven't checked it out already.

I've tried having a go at this, but I have always had a hard time with custom api's when they are very complex like stripes :confused:

POST /v1/checkout/sessions
Status
400 ERR
invalid_request_error - shipping_options

Invalid array
Was this useful?

{
"submit_type": "pay",
"line_items": {
"0": {
"quantity": "1",
"price": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"1": {
"quantity": "1"
}
},
"cancel_url": "xxxxxxxxxxxxxxxxxxxxx",
"currency": "usd",
"phone_number_collection": {
"enabled": "true"
},
"automatic_tax": {
"enabled": "true"
},
"mode": "payment",
"success_url": "xxxxxxxxxxxxxxxxxxxx",
"shipping_address_collection": {
"allowed_countries": {
"0": "US"
}
},
"shipping_options": {
"active": "true",
"livemode": "false",
"type": "fixed_amount",
"id": "xxxxxxxxxxxxxxxxxxxx",
"object": "shipping_rate",
"tax_behavior": "inclusive",
"display_name": "dfgdgdfgdfgdgfdfgdfg",
"tax_code": "",
"created": "1716497996",
"fixed_amount": {
"amount": "500",
"currency": "usd"
},
"delivery_estimate": ""
},
"payment_method_types": {
"0": "card"
}
}

Response body

{
"error": {
"message": "Invalid array",
"param": "shipping_options",
"request_log_url": "Stripe Login | Sign in to the Stripe Dashboard",
"type": "invalid_request_error"
}
}

Request POST body

{
"submit_type": "pay",
"line_items": {
"0": {
"quantity": "1",
"price": "xxxxxxxxxxxxxxxxxxxxx"
},
"1": {
"quantity": "1"
}
},
"cancel_url": "xxxxxxxxxxxxxxxxxxxxx",
"currency": "usd",
"phone_number_collection": {
"enabled": "true"
},
"automatic_tax": {
"enabled": "true"
},
"mode": "payment",
"success_url": "xxxxxxxxxxxxxxxxxx",
"shipping_address_collection": {
"allowed_countries": {
"0": "US"
}
},
"shipping_options": {
"active": "true",
"livemode": "false",
"type": "fixed_amount",
"id": "xxxxxxxxxxxxxxxxxxxxxx",
"object": "shipping_rate",
"tax_behavior": "inclusive",
"display_name": "dfgdgdfgdfgdgfdfgdfg",
"tax_code": "",
"created": "1716497996",
"fixed_amount": {
"amount": "500",
"currency": "usd"
},
"delivery_estimate": ""
},
"payment_method_types": {
"0": "card"
}
}

Chatgpt gave me this response : The issue with your Stripe API request is that the shipping_options parameter is expected to be an array, but you have provided it as an object. To fix this, you need to wrap the shipping_options object inside an array.

How it was sended?

What about sending using server side array?

I tried putting it into a server array as well no luck. I spent the week doing a custom shipping page that creates the shipping as a product because I was just wasting my time trying to get the default shipping stuff to work, I feel like it has a formatting error somewhere, im not sure

Trying to figure this out now myself. I'll let you know if I have any luck

@TheBotfather Took me a bit cause I kept trying to use 'id' as the key in the array but it needs to be 'shipping_rate'.

To use the shipping rate id in the checkout shipping options follow the steps in this little tutorial I just wrote.

1 Like

You are the man! I will definitely give this a go on my next project :slight_smile:

1 Like