Paypal checkout doesn't send PAYMENT.SALE.COMPLETED on purchase to my webhook

karlito1501
New Community Member

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');
    }
});
Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.