I'm new to the Stripe API and I am trying to implement the prebuilt Checkout page for my ecommerce site. I want a customer to be able to purchase at most 6 items, and I want those 6 items to be featured on the checkout page.
The documentation mentions that line_items is a "list of items the customer is purchasing," so I have 6 objects in the line_items array for each product; however, stripe.sessions.create() doesn't execute and the Checkout page doesn't load. If I remove all but 1 of the objects in line_items, the session works and the page is loaded.
Below is from my backend that handles the request for creating a Checkout session. Any help is appreciated!
app.post('/create-session', async (req, res) => {
const YOUR_DOMAIN = 'http://localhost:3000/Home';
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product1',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product2',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product3',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product4',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product5',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
{
price_data: {
currency: 'usd',
product_data: {
name: 'Product6',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 1899,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}?success=true`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,
});
res.json({ id: session.id });
});
EDIT: I am using stripe-node 8.119.0.
In the Stripe developer logs, I am getting a 400 error for POST /v1/checkout/sessions. This is the response body:
{
"error": {
"code": "parameter_invalid_integer",
"doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
"message": "This value must be greater than or equal to 1.",
"param": "line_items[1][quantity]",
"type": "invalid_request_error"
}
}
On the frontend, I am getting the following in my console: error message
stripe-node
you're using and what your default API version is? – Nolan Hquantity: 1
as shown in the example above? The Stripe developer console should show what you sent as well as what they responded; does it match up? – ceejayoz