Skip to content

Instantly share code, notes, and snippets.

@500friends
Last active December 16, 2015 12:59
Show Gist options
  • Save 500friends/5438314 to your computer and use it in GitHub Desktop.
Save 500friends/5438314 to your computer and use it in GitHub Desktop.
node.js implementation of secure 500friends api.
var crypto = require('crypto');
var SECRET_KEY = "SECRET_KEY"; // Your secret
var params = { email: "CUSTOMER_EMAIL", uuid: "ACCOUNT_ID" };
var keys = []; for (var key in params) { if (params.hasOwnProperty(key)) { keys.push(key) } };
keys.sort();
var string_to_hash = SECRET_KEY;
for (var i=0; i<keys.length; i++){
string_to_hash += key[i]+params[key[i]];
}
params.sig = crypto.createHash('md5').update(string_to_hash).digest("hex");
var api_url = "http://loyalty.500friends.com/api/enroll.gif?";
for (var key in params) {
api_url += key+"="+encodeURIComponent(params[key])+"&";
}
console.log(api_url) // Url of the api call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment