Verify Webhook Signature
Signature verification is mandatory to ensure the webhook being sent is not tampered during the transit.
import sha256 from 'crypto'; //Install crypto package
const webhookSignature = webhook.signature; //Webhook payload from POST
const merchantPublic = process.env.MERCHANT_PUBLIC;
const merchantPrivate = process.env.MERCHANT_PRIVATE;
//Construct signature using your merchant_private
const string = webhook.order_id + merchantPublic + webhook.amount + webhook.hash + merchantPrivate;
const calculatedSignature = sha256(string); //hex digest
// Compare signatures
if (webhookSignature === calculatedSignature) {
// Signature verification successful
// Proceed with processing webhook data
} else {
// Signature verification failed
// Reject webhook data or take appropriate action
}Last updated