Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda