#cookernetes

1 messages ยท Page 1 of 1 (latest)

crimson summitBOT
gilded steeple
#

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?

shadow shadow
#

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?

gilded steeple
#

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

shadow shadow
#

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 ๐Ÿค”

gilded steeple
#

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

shadow shadow
#

Would it be shipping_details that could be ShippingDetails | null?

#

@gilded steeple

gilded steeple
#

Within the expand array?

shadow shadow
#

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"],
});
gilded steeple
#

It should be at session.shipping_code.shipping_rate

shadow shadow
#

Nothing there when using nodejs

gilded steeple
#

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

shadow shadow
#

The version I'm using is 2022-11-15

shadow shadow
#

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.

gilded steeple
#

Actually, I think shipping_options lists all the options, not just the one that the user chose

shadow shadow
#

Oh

#

Well then it's not done

#

Hmm

gilded steeple
#

Did you check session.shipping_code.shipping_rate?

shadow shadow
#

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

gilded steeple
#

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

shadow shadow
#

Yeah ok I'll take a look.

gilded steeple
shadow shadow
#

Ah, @gilded steeple it's Shipping Rate under Shipping Cost!

#

Intriguing

crimson summitBOT
gilded steeple
#

Oh whoops, I now see I kept typing shipping_code instead of shipping_cost ๐Ÿคฆโ€โ™‚๏ธ