Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ayoubjamouhi/c82128a67dc429b68a86f9b72030d6a0 to your computer and use it in GitHub Desktop.
Save ayoubjamouhi/c82128a67dc429b68a86f9b72030d6a0 to your computer and use it in GitHub Desktop.
JVZoo IPN verification function (ported from PHP one)
/*
Hello dear developers,
I ported this function for JVZoo IPN verification from PHP one at
(https://jvzoo.zendesk.com/hc/en-us/articles/206456857-JVZIPN-How-to-create-your-own-integrated-script) and
wanted to share that with all fellow devs.
REF: https://jvzoo.zendesk.com/hc/en-us/articles/206456857-JVZIPN-How-to-create-your-own-integrated-script
Kodos :)
OffS3c
*/
// the requires
var utf8 = require('utf8');
const crypto = require("crypto");
// proper sha1 generator
function sha1(data) {
return crypto.createHash("sha1").update(data, "binary").digest("hex");
}
// Function to be exported ;) modules.export ....
function isJvzipnVerified(callbackResponse) {
let secretKey = "YOUR_KEY";
let pop = "";
let ipnFields = [];
for (let key in callbackResponse) {
if (key == "cverify") {
continue;
} else {
ipnFields.push(key);
}
}
ipnFields.sort();
for (let key in ipnFields) {
pop += callbackResponse[ipnFields[key]] + "|";
}
pop += secretKey;
calcedVerify = sha1(utf8.encode(pop));
calcedVerify = (calcedVerify.substr(0,8)).toUpperCase();
return calcedVerify == callbackResponse.cverify;
}
//--------------- HOW TO USE ---------------
// printer
function __(str) {
console.log(str);
}
// data posted by JVZoo
let x = `{
"caffitid" : "",
"ccustcc" : "",
"ccustemail" : "",
"ccustname" : "",
"ccuststate" : "",
"cproditem" : "",
"cprodtitle" : "",
"cprodtype" : "",
"ctransaction" : "",
"ctransaffiliate" : "",
"ctransamount" : "",
"ctranspaymentmethod" : "",
"ctransreceipt" : "",
"ctranstime" : "",
"ctransvendor" : "",
"cupsellreceipt" : "",
"cvendthru" : "",
"cverify" : ""
}
`;
// parse as JS Object
x = JSON.parse(x);
// The REAL Deal
if (isJvzipnVerified(x)) {
__("yeah");
} else {
__("nah");
}
// ------- Thanks -------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment