I’m trying to create a webhook to listen for paypal checkout purchases.
When user purchases some item paypal is supposed to send data to my server (all I need is an email)
I had created a nodejs webhook POST request using express.js and it does receive data only from webhook simulator multiple times, even when I only clicked it once (https://developer.paypal.com/dashboard/webhooksSimulator)
Here’s my source code:
app.post('/paypal-webhook', (req, res) => {
console.log('Webhook event received')
const rawBody = JSON.stringify(req.body);
console.log(rawBody)
const signature = req.headers['paypal-transmission-sig'];
console.log(req.body)
const verified = crypto.createHmac('sha256', paypalWebhookSecret)
.update(rawBody)
.digest('hex');
if (signature === verified) {
const event = req.body;
// Check if the event is a payment sale completed event
if (event.event_type === 'PAYMENT.SALE.COMPLETED') {
console.log('Payment sale completed:', event);
// Your course fulfillment logic here
}
res.status(200).send('Webhook received successfully.');
} else {
console.error('Webhook verification failed.');
res.status(403).send('Unauthorized');
}
});
The issue I’m having is that on paypal checkout when user buys something it doesn’t send anything to my webhook. It only sends data from webhooks simulator.