Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
stripe invalid integer NaN REACTJS

I keep getting this error and I'm not sure why. I'm sure I'm following the documentation correctly. Have I missed something here? why can stripe not pick up the value?

https://stripe.com/docs/api/payment_intents/update. https://stripe.com/docs/payments/accept-a-payment

stripe session

    const stripe = require("stripe")(process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY);

console.log(process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY);

export default async (req, res) => {
  //
  const { items} = req.body;
  console.log(items);

  

  const session = await stripe.checkout.sessions.create({
    payment_method_types: ["card"],
    line_items: [
      {
        price_data: {
          currency: 'pln',
          product_data: {
            name: items.name,
          },
          unit_amount: items.price * 100,
        },
        quantity: 1,
      },
    ],
    mode: "payment",

    success_url: "http://localhost:3000/Success",
    cancel_url: "http://localhost:3000/Cancel",
   
  });
  res.status(200).json({ id: session.id });
};

Items - this also appears in the console.

{
    "name": "poznan",
    "description": "hey",
    "price": 9.99
}

checkout session error

[ { name: 'poznan', description: 'hey', price: 9.99 } ]
error - Error: Invalid integer: NaN

stripe log

    parameter_invalid_integer - line_items[0][price_data][unit_amount]
    
    {
  "payment_method_types": {
    "0": "card"
  },
  "line_items": {
    "0": {
      "price_data": {
        "currency": "pln",
        "unit_amount": "NaN"
      },
      "quantity": "1"
    }
  },
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think your items variable is an array and since you're trying to access the field price on an array items.price * 100 is evaluated as undefined * 100 giving you the NaN value for unit_amount. You either need to access items[0].price instead of items.price or if you’re receiving multiple items why not map your array into line_items like so:

line_items: items.map((item)=> ({
      price_data: {
        currency: 'pln',
        product_data: {
          name: item.name,
        },
        unit_amount: item.price * 100,
      },
      quantity: 1,
    },
})),
about 4 years ago · Juan Pablo Isaza Report

0

Needed to map through the objects and do an implicit return

export default async (req, res) => {
  //
  const { items} = req.body;
  console.log(items);

 const transformedItems = items.map(item => ({
   description: item.description,
   quantity: 1,
   price_data: {
     currency: 'gbp',
     unit_amount: item.price * 100,
     product_data: {
       name: item.name,

     },
   }
 }));

  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: transformedItems,
    mode: "payment",
    
    success_url: "http://localhost:3000/Success",
    cancel_url: "http://localhost:3000/Cancel",
   
  });
  res.status(200).json({ id: session.id });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!