'Razorpay.validateWebhookSignature() is not working for invoice.paid events

Razorpay.validateWebhookSignature() returns true for other webhook events but for events type "invoice.paid" it is returning false.

I am using Razorpay npm package

Here is a code snippet

    let body = req.body;
    let receivedSignature = req.get("x-razorpay-signature");
    let secret = "xxxx";

    var success = Razorpay.validateWebhookSignature(
      JSON.stringify(body),
      received_signature,
      secret
    );

success is returning true for all events except 'invoice.paid'



Solution 1:[1]

on second line you are declearing variable:

let receivedSignature = req.get("x-razorpay-signature");

and on razorpay function you are passing : received_signature, So, it is bound to work as unexpected, as received_signature is not defined.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shubham