#djk3600

1 messages ยท Page 1 of 1 (latest)

grizzled socketBOT
obtuse summit
#

Hello ๐Ÿ‘‹
How can I help? ๐Ÿ™‚

tender lantern
#

Hey Hanzo, so I was speaking to your colleaugue Pompey earlier for quite some time

#

This was his last piece of advice for me

#

however

#

this causes an error

#

what do you reckon??

obtuse summit
#

can you change it to shipping_options: [{"shipping_rate": "shr_xxxx"}] and try?

#

you're also missing a comma ๐Ÿ™‚

tender lantern
#
    shipping_options: [{ shipping_rate: "shr_1LhDIRK7ED5S47qKPckAuvZu" }],
#

vscode automatically gets rid of the speech marks

#

but error has gone

#

so lets give it a try!

#
 message: "No such shipping rate: 'shr_1LhDIRK7ED5S47qKPckAuvZu'; a similar object exists in live mode, but a test mode key was used to make this request.
#

assuming I need to make it live then

obtuse summit
#

Yup or you could create a Shipping rate in test mode ๐Ÿ™‚

tender lantern
#

is this the right place??

#

ahhh but then I tick test mode!

obtuse summit
#

do you have the test mode toggle on? yup

tender lantern
#

yeah I just did

#

and its giving a much friendleir error!!!

#

WOOOOO]

#

Okay we are getting close

#

message: 'The default currency of your line items (usd) must match the default currency of your shipping rate (gbp).',

#

switch it to gbp then

#

mate

#

it worked

#

I may just cry of happiness

#

okay last question

#

please

#

I originally set the quantity to 1

#

because it was giving me this annoying error

#

how do I work around this error?

obtuse summit
#

Where are you setting the quantity 1 exactly?

tender lantern
#
 message: 'Quantity is required. Add `quantity` to `line_items[0]`'

and my code:

    quantity: item.quantity,
#

and the bigger picture,

 const transformedItems = items.map((item) => ({
    price_data: {
      currency: "gbp",
      unit_amount: item.price * 100,
      product_data: {
        name: item.title,
        description: item.description,
      },
    },
    quantity: item.quantity,
  }));
#

any ideas??

obtuse summit
#

and how/where do you use transformedItems?

tender lantern
#
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ["card"],
    shipping_options: [{ shipping_rate: "shr_1Lg3ngK7ED5S47qKjg24WcnP" }],
    shipping_address_collection: {
      allowed_countries: ["GB", "US", "CA"],
    },
    line_items: transformedItems,
    mode: "payment",
    success_url: `${process.env.HOST}/success`,
    cancel_url: `${process.env.HOST}/checkout`,
    metadata: {
      email,
    },
  });
#

if you see line_items

obtuse summit
#

As far as I know quantity is required ๐Ÿค”

#

let me double check

#

yeah quantity is a required field, I don't know why we say optional on the API ref (looks like a bug in the docs)