-
Notifications
You must be signed in to change notification settings - Fork 31
/
router.js
75 lines (72 loc) · 2.75 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
var paytm_config = require('./paytm/paytm_config').paytm_config;
var paytm_checksum = require('./paytm/checksum');
var querystring = require('querystring');
function route(request,response){
switch(request.url){
case '/':
console.log("/ has started");
response.writeHead(200 , {'Content-type':'text/html'});
response.write('<html><head><title>Paytmdddddd</title></head><body>');
response.write('</body></html>');
response.end();
break;
case '/generate_checksum':
if(request.method == 'POST'){
var paramarray = {};
paramarray['MID'] = 'xxxxxxxxxxxxxx'; //Provided by Paytm
paramarray['ORDER_ID'] = 'ORDER00001'; //unique OrderId for every request
paramarray['CUST_ID'] = 'CUST0001'; // unique customer identifier
paramarray['INDUSTRY_TYPE_ID'] = 'xxxxxxxxx'; //Provided by Paytm
paramarray['CHANNEL_ID'] = 'WAP'; //Provided by Paytm
paramarray['TXN_AMOUNT'] = '1.00'; // transaction amount
paramarray['WEBSITE'] = 'xxxxxxxxxxxx'; //Provided by Paytm
paramarray['CALLBACK_URL'] = 'https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp';//Provided by Paytm
paramarray['EMAIL'] = '[email protected]'; // customer email id
paramarray['MOBILE_NO'] = '9999999999'; // customer 10 digit mobile no.
paytm_checksum.genchecksum(paramarray, paytm_config.MERCHANT_KEY, function (err, res) {
response.writeHead(200, {'Content-type' : 'text/json','Cache-Control': 'no-cache'});
response.write(JSON.stringify(res));
response.end();
});
} else {
response.writeHead(200, {'Content-type' : 'text/json'});
response.end();
}
break;
case '/verify_checksum':
if(request.method == 'POST'){
var fullBody = '';
request.on('data', function(chunk) {
fullBody += chunk.toString();
});
request.on('end', function() {
var decodedBody = querystring.parse(fullBody);
response.writeHead(200, {'Content-type' : 'text/html','Cache-Control': 'no-cache'});
if(paytm_checksum.verifychecksum(decodedBody, paytm_config.MERCHANT_KEY)) {
console.log("true");
}else{
console.log("false");
}
// if checksum is validated Kindly verify the amount and status
// if transaction is successful
// kindly call Paytm Transaction Status API and verify the transaction amount and status.
// If everything is fine then mark that transaction as successful into your DB.
response.end();
});
}else{
response.writeHead(200, {'Content-type' : 'text/json'});
response.end();
}
break;
}
}
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
exports.route = route;