<commit_before>const express = require("express"),
	  app = express(),
	  crypto = require("crypto"),
	  hash = crypto.createHash("sha512")
	  request = require("request"),
	  bodyParser = require("body-parser");

/**
 * APP SETTINGS
 * ==========
 */
app.use(bodyParser.urlencoded({ extended: false }));


/**
 * Data essentials.  
 * ==========
 */ 
var key = process.env.ISHA_KEY,
  	txnid = randString(32);





/**
 * FUNCTIONS
 * ==========
 */

/**
 * Creates a random string of given length.
 * 
 * @params len {Number} Length of the resulting random string.
 * @returns r {String} A random string of given length.
 */
function randString(len) {
	var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var r = "";
	for (var i = 0; i < (len + 1); i++) {
		r += chars[Math.floor(Math.random() * chars.length)];
	}
	return r;
};

/**
 * Creates a hash out of the data.
 *
 * @param key {String} Merchant key.
 * @param txn {String} Random Txn id generated by us.
 * @param a {String} Amount to bill.
 * @param fname {Sring} Firstname of the customer.
 * @param em {String} Email Address of the customer.
 * @param ph {String} Phone.
 * @returns {Promise} Internal promise.
 */
var createHash = (function(key, txn, a, fname, em, ph) {
	var promise = new Promise((resolve, reject) => {
		hash.on("readable", () => {
			var createdHash = hash.read();
			if (createdHash !== "") resolve({
			 	key: key,
				hash: createdHash.toString("hex").toLowerCase(),			 	
			 	txnid: txn,
			 	amount: a,
			 	firstname: fname,
			 	email: em,
			 	phone: ph
			 });
		});			

		hash.write(key + "|" + txn + "|" + a + "|" + "None" + "|" + fname + "|" + em + "|||||||||||" + process.env.ISHA_SALT);
		hash.end();
	});
	return promise;
}).bind(null, key, txnid);



/**
 * ROUTES
 * =========
 */

// CHECKOUT FORM ROUTE
app.post("/checkout", (req, res) => {
	app.locals.a = req.body.amount;
	res.render("form.ejs", {amount: app.locals.a});
});

// PAYMENTS ROUTE
app.post("/payment", (req, res) => {	
	// Get data from the body.
	var fname = req.body.firstname,
		em = req.body.email,
		ph = req.body.phone;

	// Pass hash a, fname, em, ph to create hash.
	createHash(app.locals.a, fname, em, ph).then(function(obj) {				
		console.log(JSON.stringify(obj));
		// Add to object.
		obj.productinfo = "None";
		obj.service_provider = "payu_paisa";<commit_msg>Changed names of environment varialbes<commit_after>const express = require("express"),
	  app = express(),
	  crypto = require("crypto"),
	  hash = crypto.createHash("sha512")
	  request = require("request"),
	  bodyParser = require("body-parser");

/**
 * APP SETTINGS
 * ==========
 */
app.use(bodyParser.urlencoded({ extended: false }));


/**
 * Data essentials.  
 * ==========
 */ 
var key = process.env.PAYU_KEY,
  	txnid = randString(32);





/**
 * FUNCTIONS
 * ==========
 */

/**
 * Creates a random string of given length.
 * 
 * @params len {Number} Length of the resulting random string.
 * @returns r {String} A random string of given length.
 */
function randString(len) {
	var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var r = "";
	for (var i = 0; i < (len + 1); i++) {
		r += chars[Math.floor(Math.random() * chars.length)];
	}
	return r;
};

/**
 * Creates a hash out of the data.
 *
 * @param key {String} Merchant key.
 * @param txn {String} Random Txn id generated by us.
 * @param a {String} Amount to bill.
 * @param fname {Sring} Firstname of the customer.
 * @param em {String} Email Address of the customer.
 * @param ph {String} Phone.
 * @returns {Promise} Internal promise.
 */
var createHash = (function(key, txn, a, fname, em, ph) {
	var promise = new Promise((resolve, reject) => {
		hash.on("readable", () => {
			var createdHash = hash.read();
			if (createdHash !== "") resolve({
			 	key: key,
				hash: createdHash.toString("hex").toLowerCase(),			 	
			 	txnid: txn,
			 	amount: a,
			 	firstname: fname,
			 	email: em,
			 	phone: ph
			 });
		});			

		hash.write(key + "|" + txn + "|" + a + "|" + "None" + "|" + fname + "|" + em + "|||||||||||" + process.env.PAYU_SALT);
		hash.end();
	});
	return promise;
}).bind(null, key, txnid);



/**
 * ROUTES
 * =========
 */

// CHECKOUT FORM ROUTE
app.post("/checkout", (req, res) => {
	app.locals.a = req.body.amount;
	res.render("form.ejs", {amount: app.locals.a});
});

// PAYMENT ROUTE
app.post("/payment", (req, res) => {	
	// Get data from the body.
	var fname = req.body.firstname,
		em = req.body.email,
		ph = req.body.phone;

	// Pass hash a, fname, em, ph to create hash.
	createHash(app.locals.a, fname, em, ph).then(function(obj) {				
		console.log(JSON.stringify(obj));
		// Add to object.
		obj.productinfo = "None";
		obj.service_provider = "payu_paisa";
{'fraction_non_alphanumeric': 0.19353484466834592, 'fraction_numerical': 0.007136859781696054, 'mean_word_length': 3.213085764809903, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3977682', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1722, 'n_words': 439}