Safepay logo
Docs
Safepay logo
Launch Safepay

Consuming Webhooks - Signature

How to verify the signature included in the response.


This guide goes into further detail on how to process a webhook payload for an event.

How to verify the signature

Safepay will attach the signature to the request via the X-SFPY-Signature header. In order to verify that the request is indeed from Safepay, you should reconstruct the signature using your webhook secret. This should match the signature in the request. Samples are presented below:

const crypto = require(‘crypto’);
var payload = {
token:C5A5APSBCV41R2QF2MHG,
client_id: “sec_55ca6960 - e2ea - 4643 - b0cf - 7 cd65a4d3112”,
type: “payment: created”,
endpoint: “http: //127.0.0.1:9000”,
notification: {
tracker: “tracker_c5a5apsbcv41om3fg0u0 ",
reference:514087,
intent:PAYFAST,
fee:4.92,
net:145.08 ",
user: “johndoe @gmail.com”,
state:PAID,
amount:150,
currency:PKR,
metadata: {
order_id:XG102312,
source: “shopify”
}
},
delivery_attempts: 1,
resource: “notification”,
next_attempt_at:2021 - 10 - 01 T09: 05: 33 Z,
created_at:2021 - 09 - 29 T12: 00: 40 Z
};
const data = Buffer.from(JSON.stringify(payload));
const secret =86 f63866a6e9b27f8f48a2d0a2946171b03639ea2e5000213e641da781a87d6e’;
const hash = crypto.createHmac(‘sha512’, secret)
.update(data)
.digest(‘hex’);
console.log(hash);
Previous
Basics
Next
Payloads