#cookernetes
1 messages ยท Page 1 of 1 (latest)
I think the shipping_cost property would show that though I have not been able to test to check that right now. https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-shipping_cost
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Can you test this to see if that property shows the customer's selection? If it does not, can you send me the ID of the Checkout Session (cs_test_1234) so I can take a look?
I don't have an example to hand, however I just want to get the type/name from when the checkout session was created
E.g. when it was added to the checkout session when being created like this:
shipping_options: [
{
shipping_rate_data: {
display_name: "Yodel Delivery (Yodel Direct)",
type: "fixed_amount",
fixed_amount: { amount: postageTotal, currency: "gbp" },
delivery_estimate: {
maximum: { unit: "business_day", value: 3 },
},
},
},
How would I be able to either get the display name, or find a way to get the display name?
This must be an option exposed by the API
@gilded steeple
Ah - do I expand the shipping rate?
I think if you expand the shipping_cost.shipping_rate property that should include the display name.
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-shipping_cost-shipping_rate
The API ref shows how to use expansion, you would pass shipping_cost.shipping_rate to the expand parameter array to get the full object back when retrieving the Checkout Session
https://stripe.com/docs/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So I'd just put shipping_cost.shipping_rate into the expansion string array when I'm getting the checkout session? (NODEJS)
And exactly that and then I'd get the data?
If so, why when I put that in am I not getting autofill/intellisense that there could be that data ๐ค
Which part is intellisense not filling in? I think intellisense would know about the expand parameter but that param is just an array of strings so it doesn't know what strings can go there
Yeah it doesn't show me the data object that should be there
Would it be shipping_details that could be ShippingDetails | null?
@gilded steeple
Within the expand array?
After I've put it in the array, and I want to get the selected one from the session after fetching that session with the right bit expanded like you told me to expand
How would I get that data/the name/ID of the shipping option?
Trying to put it after that, and this is the code to fetch that session:
const session = await stripe.checkout.sessions.retrieve(sessionID, {
expand: ["line_items", "shipping_cost.shipping_rate"],
});
It should be at session.shipping_code.shipping_rate
Looking at the API ref again, it mentions that before API Version 2022-08-01 this would be at session.shipping_rate
I'd reccommend just running the code and printing out the full object
Intellesense can be weird with recognizing what is available in some libraries
The version I'm using is 2022-11-15
Yeah gotcha
Right, ok
Ah - it's (session.shipping_options[0].shipping_rate as ShippingRate).displayName
:)
Had to do a manual TS cast
Thanks, @gilded steeple for all your help!
Have a lovely day.
Actually, I think shipping_options lists all the options, not just the one that the user chose
Did you check session.shipping_code.shipping_rate?
There isn't shipping_code for some reason - and I can't run it and try and get the data as this is in live mode and it would take a bit of time to run it in test mode
This is the shipping stuff
It shouldn't take too long to try this in test mode. You should be able to use the same code but just with test mode prices
Yeah ok I'll take a look.
And if you don't already have test prices here, you can use the price_data hash to quickly define one-off prices https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-unit_amount_decimal
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Oh whoops, I now see I kept typing shipping_code instead of shipping_cost ๐คฆโโ๏ธ