#djk3600
1 messages ยท Page 1 of 1 (latest)
Hello ๐
How can I help? ๐
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??
can you change it to shipping_options: [{"shipping_rate": "shr_xxxx"}] and try?
you're also missing a comma ๐
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
Yup or you could create a Shipping rate in test mode ๐
do you have the test mode toggle on? yup
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?
Where are you setting the quantity 1 exactly?
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??
and how/where do you use transformedItems?
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