Webhooks Stripe Nodejs Express

const express = require('express'); 
const formRoutes = require('./routes/formRoutes'); 
const webhookRoutes = require('./routes/webhookRoutes'); 
const userRoutes = require('./routes/userRoutes');
const webhookStripe = require('./routes/webhookStripe'); 
const cuestionarioRoutes = require('./routes/cuestionarioRoutes'); 
const cors = require('cors'); 
const app = express();

// Configurar CORS para permitir solicitudes desde cualquier origen app.use(cors());

app.use('/api/webhook', webhookStripe);

// Middleware para manejar datos JSON y URL codificada app.use(express.json()); app.use(express.urlencoded({ extended: true }));

app.use('/api/user', userRoutes);
app.use('/api', formRoutes); 
app.use('/api/webhook', webhookRoutes); 
app.use('/api/user', cuestionarioRoutes);

module.exports = app;

const express = require('express'); 
const router = express.Router(); 
const stripeController = require('../controllers/stripe/stripeController');

// Ruta para manejar eventos de webhook de Stripe con express.raw router.post('/stripe', express.raw({ type: 'application/json' }), stripeController.handleStripeWebhook);

module.exports = router;





const Stripe = require('stripe');
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET;

exports.handleStripeWebhook = async(req, res) => { const sig = req.headers['stripe-signature']; let event;

try {
    // Verificar la firma del webhook de Stripe
    event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
} catch (error) {
    console.error('⚠️ Fallo en la verificación de la firma del webhook.', error.message);
    return res.status(400).json({
        error: `Error de Webhook: ${error.message}`
    });
}

// Manejar el evento
switch (event.type) {
    case 'checkout.session.completed':
        const checkoutSessionCompleted = event.data.object;
        const userId = checkoutSessionCompleted.metadata.userId;

        try {

            await verifyAndUpdatePayment(userId, checkoutSessionCompleted.id);


            // Mostrar en consola detalles del evento
            console.log('Compra completada para el producto con ID:', userId);
            console.log({
                checkoutSessionCompleted
            });


            res.status(200).end();
        } catch (error) {
            console.error('Error al verificar y actualizar el pago:', error);
            res.status(500).json({
                error: 'Error interno al procesar el pago.'
            });
        }
        break;
    default:
        console.log(`Evento no manejado: ${event.type}`);
        res.status(200).end();
}}; 

Obtengo el error Fallo en la verificación de la firma del webhook. No signatures found matc

hing the expected signature for payload. Are you passing the raw request body you received from Stripe?

If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
error 400

version stripe: 15.12.0
express 4.19.2

alguien pudo resolver esto??