Created
October 28, 2018 10:49
-
-
Save OffS3c/fd9d95eb7d743b49b82e1e2c01f5ebf9 to your computer and use it in GitHub Desktop.
Revisions
-
OffS3c created this gist
Oct 28, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,97 @@ /* 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 -------