Skip to content

Instantly share code, notes, and snippets.

@rickithadi
Created September 8, 2023 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickithadi/a646ce4bf232edd8dbd472221373ad5a to your computer and use it in GitHub Desktop.
Save rickithadi/a646ce4bf232edd8dbd472221373ad5a to your computer and use it in GitHub Desktop.
dpay webhook signature verification
try {
let hmac = crypto
.createHmac(
"sha256",
process.env.NODE_ENV === "production"
? process.env.LIVE_DPAY_KEY
: process.env.STAGING_DPAY_KEY
)
.update(`${data.id}|${data.amount_str}`)
.digest("hex");
const signatureOk = data.signature === hmac;
if (!signatureOk) {
console.log("signatures dont tally \n", data.signature, "\n", hmac);
return res.send("Error, signature verification failed").status(420);
}
} catch (e) {
console.log("cannot get signature", e);
return res.send("Error, signature verification failed").status(420);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment