so I've recently dealt with some stripe code and I've decided that it's time for webhooks. I looked at the webhooks page on the stripe webpage, copied the source code and it doesn't work.
client.post('/webhook', express.raw({ type: 'application/json' }), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = exports.stripe.webhooks.constructEvent(request.body, sig, code);
}
catch (err) {
response.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log(paymentIntent);
break;
// ... handle other event types
default:
console.log(`Unhandled event type ${event.type}`);
}
// Return a 200 response to acknowledge receipt of the event
response.send();
});
I've checked multiple times if my code is the same but it is. Can someone tell me what's wrong? I'm listening on port 3001 as well if that's the case.