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

144
Views
stripe unit_amount bespoke charge in express with error TypeError: Cannot read properties of undefined

I have an Express route and in the req.body I receive the below object that includes the price I wish to charge my customer.

{
  UniqueId: 1636295687144,
  cakeSize: 12,
  cakeShape: '',
  sponge: 'plain',
  butterCream: 'none',
  icing: false,
  specialDecoration: '',
  cakeMessage: '',
  dateTime: '',
  price: 18
}

Here is my create-checkout-session route for Stripe

app.post("/create-checkout-session", async (req, res) => {

  const session = await stripe.checkout.sessions.create({
    payment_method_types: ["card"],
    line_items: [
      {
        price_data: {
          currency: "gbp",
          unit_amount: req.body[0].price,
          //errors with "TypeError: Cannot read properties of undefined (reading 'price')"
          product_data: {
            name: "CakeItOrLeaveIt",
            // description: "", cake it or leave it description
            // images: [], cake it or leave it logo
          },
        },
        quantity: 1,
      },
    ],
    mode: "payment",
    success_url: `http://localhost:4242/success.html`,
    cancel_url: `http://localhost:4242/cancel.html`,
  });

  console.log(req.body[0]);

  //logs this obejct
  // {
  //   UniqueId: 1636294926748,
  //   cakeSize: 6,
  //   cakeShape: '',
  //   sponge: 'plain',
  //   butterCream: 'none',
  //   icing: false,
  //   specialDecoration: '',
  //   cakeMessage: '',
  //   dateTime: '',
  //   price: 7
  // }

  console.log(req.body[0].price);

  res.redirect(303, session.url);
});

The problem is when I try to pass the req.body[0].price into stripes object to charge the customer a custom amount I get the error

/Users/calumbradley/Development/cakeitorleaveit/cakeitorleaveit/server/server.js:61
  console.log(req.body[0].price);
                          ^

TypeError: Cannot read properties of undefined (reading 'price')
    at /Users/calumbradley/Development/cakeitorleaveit/cakeitorleaveit/server/server.js:61:27
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Thanks in advance

about 4 years ago · Juan Pablo Isaza
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!