Hi there, I'm currently working on creating an Amazon-inspired platform and I've encountered an error while trying to integrate Stripe with the project. Can anyone provide some assistance? You can refer to the video tutorial I'm using by following this link: https://www.youtube.com/watch?v=4E0WOUYF-QI&t=4092s
The specific error message I received is as follows:
Error - StripeInvalidRequestError: You cannot use
line_items.amount
,line_items.currency
,line_items.name
,line_items.description
, orline_items.images
in this API version. Please useline_items.price
orline_items.price_data
. For more details, please visit https://stripe.com/docs/payments/checkout/migrating-prices.
Here's the code snippet where the issue arises:
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
export default async (req, res) => {
const { items, email } = req.body;
const transformedItems = items.map((item) => ({
description: item.description,
quantity: 1,
price_data: {
currency: "gbp",
unit_amount: item.price * 100,
product_data: {
name: item.title,
images: [item.image],
},
},
}));
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
shipping_rates: ["shr_1LkVMHSArY9HEMGlxjejfRWf"],
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,
images: JSON.stringify(items.map((item) => item.image)),
},
});
res.status(200).json({ id: session.id });
};