I just integrated the stripe webhook in node.
I am able to implement simple webhook endpoint and it is working absolutely fine.
But if I tried "Check webhook signature" I am getting the error: " Cannot read property 'type' of undefined"
My code looks just as provided by stripe:
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
// event = request.body;
} catch (err) {
response.status(400).send(`Webhook Error: ${err.message}`);
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log('PaymentIntent was successful!');
break;
default:
console.log(`Unhandled event type ${event.type}`);
// Unexpected event type
return response.status(400).end();
}
// Return a 200 response to acknowledge receipt of the event
response.json({ received: true });
});
I am not getting anything in the "event"
Please help me!!!