node-paytmpg 5.3.0 → 5.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codeql-analysis.yml +71 -71
- package/.github/workflows/nodejs.yml +24 -24
- package/.github/workflows/npm-publish.yml +23 -23
- package/Dockerfile +8 -8
- package/LICENSE +674 -674
- package/README.MD +245 -245
- package/app/controllers/adapters/open_money.js +515 -514
- package/app/controllers/checksum/checksum.js +154 -154
- package/app/controllers/checksum/crypt.js +98 -98
- package/app/controllers/checksum/server.js +132 -132
- package/app/controllers/np_user.controller.js +79 -79
- package/app/controllers/payment_controller.js +1067 -1067
- package/app/models/np_multidbplugin.js +101 -101
- package/app/models/np_transaction.model.js +16 -16
- package/app/models/np_user.model.js +11 -11
- package/app/routes/payment_route.js +73 -73
- package/app/views/home.hbs +21 -21
- package/app/views/init.hbs +92 -92
- package/app/views/layouts/index.hbs +57 -57
- package/app/views/result.hbs +49 -49
- package/app.yaml +18 -18
- package/example.js +51 -51
- package/index.js +23 -23
- package/package.json +42 -41
- package/public/css/style.css +268 -268
- package/public/js/index.js +282 -282
- package/public/layer_checkout.js +38 -38
- package/public/test.html +24 -24
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
const http = require('http');
|
|
2
|
-
const https = require('https');
|
|
3
|
-
const qs = require('querystring');
|
|
4
|
-
const port = 8080;
|
|
5
|
-
const checksum_lib = require('./checksum.js');
|
|
6
|
-
|
|
7
|
-
var PaytmConfig = {
|
|
8
|
-
mid: "XXXXXXXXXXXXXXXXXXXX",
|
|
9
|
-
key: "XXXXXXXXXXXXXXXX",
|
|
10
|
-
website: "XXXXXXXXXX"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
http.createServer(function (req, res) {
|
|
15
|
-
|
|
16
|
-
switch(req.url){
|
|
17
|
-
case "/":
|
|
18
|
-
var params = {};
|
|
19
|
-
params['MID'] = PaytmConfig.mid;
|
|
20
|
-
params['WEBSITE'] = PaytmConfig.website;
|
|
21
|
-
params['CHANNEL_ID'] = 'WEB';
|
|
22
|
-
params['INDUSTRY_TYPE_ID'] = 'Retail';
|
|
23
|
-
params['ORDER_ID'] = 'TEST_' + new Date().getTime();
|
|
24
|
-
params['CUST_ID'] = 'Customer001';
|
|
25
|
-
params['TXN_AMOUNT'] = '1.00';
|
|
26
|
-
params['CALLBACK_URL'] = 'http://localhost:'+port+'/callback';
|
|
27
|
-
params['EMAIL'] = 'abc@mailinator.com';
|
|
28
|
-
params['MOBILE_NO'] = '7777777777';
|
|
29
|
-
|
|
30
|
-
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
31
|
-
|
|
32
|
-
var txn_url = "https://securegw-stage.paytm.in/theia/processTransaction"; // for staging
|
|
33
|
-
// var txn_url = "https://securegw.paytm.in/theia/processTransaction"; // for production
|
|
34
|
-
|
|
35
|
-
var form_fields = "";
|
|
36
|
-
for(var x in params){
|
|
37
|
-
form_fields += "<input type='hidden' name='"+x+"' value='"+params[x]+"' >";
|
|
38
|
-
}
|
|
39
|
-
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='"+checksum+"' >";
|
|
40
|
-
|
|
41
|
-
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
42
|
-
res.write('<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Please do not refresh this page...</h1></center><form method="post" action="'+txn_url+'" name="f1">'+form_fields+'</form><script type="text/javascript">document.f1.submit();</script></body></html>');
|
|
43
|
-
res.end();
|
|
44
|
-
});
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case "/callback":
|
|
48
|
-
|
|
49
|
-
var body = '';
|
|
50
|
-
|
|
51
|
-
req.on('data', function (data) {
|
|
52
|
-
body += data;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
req.on('end', function () {
|
|
56
|
-
var html = "";
|
|
57
|
-
var post_data = qs.parse(body);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// received params in callback
|
|
61
|
-
console.log('Callback Response: ', post_data, "\n");
|
|
62
|
-
html += "<b>Callback Response</b><br>";
|
|
63
|
-
for(var x in post_data){
|
|
64
|
-
html += x + " => " + post_data[x] + "<br/>";
|
|
65
|
-
}
|
|
66
|
-
html += "<br/><br/>";
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// verify the checksum
|
|
70
|
-
var checksumhash = post_data.CHECKSUMHASH;
|
|
71
|
-
// delete post_data.CHECKSUMHASH;
|
|
72
|
-
var result = checksum_lib.verifychecksum(post_data, PaytmConfig.key, checksumhash);
|
|
73
|
-
console.log("Checksum Result => ", result, "\n");
|
|
74
|
-
html += "<b>Checksum Result</b> => " + (result? "True" : "False");
|
|
75
|
-
html += "<br/><br/>";
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Send Server-to-Server request to verify Order Status
|
|
80
|
-
var params = {"MID": PaytmConfig.mid, "ORDERID": post_data.ORDERID};
|
|
81
|
-
|
|
82
|
-
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
83
|
-
|
|
84
|
-
params.CHECKSUMHASH = checksum;
|
|
85
|
-
post_data = 'JsonData='+JSON.stringify(params);
|
|
86
|
-
|
|
87
|
-
var options = {
|
|
88
|
-
hostname: 'securegw-stage.paytm.in', // for staging
|
|
89
|
-
// hostname: 'securegw.paytm.in', // for production
|
|
90
|
-
port: 443,
|
|
91
|
-
path: '/merchant-status/getTxnStatus',
|
|
92
|
-
method: 'POST',
|
|
93
|
-
headers: {
|
|
94
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
|
-
'Content-Length': post_data.length
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Set up the request
|
|
101
|
-
var response = "";
|
|
102
|
-
var post_req = https.request(options, function(post_res) {
|
|
103
|
-
post_res.on('data', function (chunk) {
|
|
104
|
-
response += chunk;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
post_res.on('end', function(){
|
|
108
|
-
console.log('S2S Response: ', response, "\n");
|
|
109
|
-
|
|
110
|
-
var _result = JSON.parse(response);
|
|
111
|
-
html += "<b>Status Check Response</b><br>";
|
|
112
|
-
for(var x in _result){
|
|
113
|
-
html += x + " => " + _result[x] + "<br/>";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
117
|
-
res.write(html);
|
|
118
|
-
res.end();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// post the data
|
|
123
|
-
post_req.write(post_data);
|
|
124
|
-
post_req.end();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}).listen(port);
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const qs = require('querystring');
|
|
4
|
+
const port = 8080;
|
|
5
|
+
const checksum_lib = require('./checksum.js');
|
|
6
|
+
|
|
7
|
+
var PaytmConfig = {
|
|
8
|
+
mid: "XXXXXXXXXXXXXXXXXXXX",
|
|
9
|
+
key: "XXXXXXXXXXXXXXXX",
|
|
10
|
+
website: "XXXXXXXXXX"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
http.createServer(function (req, res) {
|
|
15
|
+
|
|
16
|
+
switch(req.url){
|
|
17
|
+
case "/":
|
|
18
|
+
var params = {};
|
|
19
|
+
params['MID'] = PaytmConfig.mid;
|
|
20
|
+
params['WEBSITE'] = PaytmConfig.website;
|
|
21
|
+
params['CHANNEL_ID'] = 'WEB';
|
|
22
|
+
params['INDUSTRY_TYPE_ID'] = 'Retail';
|
|
23
|
+
params['ORDER_ID'] = 'TEST_' + new Date().getTime();
|
|
24
|
+
params['CUST_ID'] = 'Customer001';
|
|
25
|
+
params['TXN_AMOUNT'] = '1.00';
|
|
26
|
+
params['CALLBACK_URL'] = 'http://localhost:'+port+'/callback';
|
|
27
|
+
params['EMAIL'] = 'abc@mailinator.com';
|
|
28
|
+
params['MOBILE_NO'] = '7777777777';
|
|
29
|
+
|
|
30
|
+
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
31
|
+
|
|
32
|
+
var txn_url = "https://securegw-stage.paytm.in/theia/processTransaction"; // for staging
|
|
33
|
+
// var txn_url = "https://securegw.paytm.in/theia/processTransaction"; // for production
|
|
34
|
+
|
|
35
|
+
var form_fields = "";
|
|
36
|
+
for(var x in params){
|
|
37
|
+
form_fields += "<input type='hidden' name='"+x+"' value='"+params[x]+"' >";
|
|
38
|
+
}
|
|
39
|
+
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='"+checksum+"' >";
|
|
40
|
+
|
|
41
|
+
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
42
|
+
res.write('<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Please do not refresh this page...</h1></center><form method="post" action="'+txn_url+'" name="f1">'+form_fields+'</form><script type="text/javascript">document.f1.submit();</script></body></html>');
|
|
43
|
+
res.end();
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
|
|
47
|
+
case "/callback":
|
|
48
|
+
|
|
49
|
+
var body = '';
|
|
50
|
+
|
|
51
|
+
req.on('data', function (data) {
|
|
52
|
+
body += data;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
req.on('end', function () {
|
|
56
|
+
var html = "";
|
|
57
|
+
var post_data = qs.parse(body);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// received params in callback
|
|
61
|
+
console.log('Callback Response: ', post_data, "\n");
|
|
62
|
+
html += "<b>Callback Response</b><br>";
|
|
63
|
+
for(var x in post_data){
|
|
64
|
+
html += x + " => " + post_data[x] + "<br/>";
|
|
65
|
+
}
|
|
66
|
+
html += "<br/><br/>";
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// verify the checksum
|
|
70
|
+
var checksumhash = post_data.CHECKSUMHASH;
|
|
71
|
+
// delete post_data.CHECKSUMHASH;
|
|
72
|
+
var result = checksum_lib.verifychecksum(post_data, PaytmConfig.key, checksumhash);
|
|
73
|
+
console.log("Checksum Result => ", result, "\n");
|
|
74
|
+
html += "<b>Checksum Result</b> => " + (result? "True" : "False");
|
|
75
|
+
html += "<br/><br/>";
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// Send Server-to-Server request to verify Order Status
|
|
80
|
+
var params = {"MID": PaytmConfig.mid, "ORDERID": post_data.ORDERID};
|
|
81
|
+
|
|
82
|
+
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
83
|
+
|
|
84
|
+
params.CHECKSUMHASH = checksum;
|
|
85
|
+
post_data = 'JsonData='+JSON.stringify(params);
|
|
86
|
+
|
|
87
|
+
var options = {
|
|
88
|
+
hostname: 'securegw-stage.paytm.in', // for staging
|
|
89
|
+
// hostname: 'securegw.paytm.in', // for production
|
|
90
|
+
port: 443,
|
|
91
|
+
path: '/merchant-status/getTxnStatus',
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
|
+
'Content-Length': post_data.length
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// Set up the request
|
|
101
|
+
var response = "";
|
|
102
|
+
var post_req = https.request(options, function(post_res) {
|
|
103
|
+
post_res.on('data', function (chunk) {
|
|
104
|
+
response += chunk;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
post_res.on('end', function(){
|
|
108
|
+
console.log('S2S Response: ', response, "\n");
|
|
109
|
+
|
|
110
|
+
var _result = JSON.parse(response);
|
|
111
|
+
html += "<b>Status Check Response</b><br>";
|
|
112
|
+
for(var x in _result){
|
|
113
|
+
html += x + " => " + _result[x] + "<br/>";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
117
|
+
res.write(html);
|
|
118
|
+
res.end();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// post the data
|
|
123
|
+
post_req.write(post_data);
|
|
124
|
+
post_req.end();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
}).listen(port);
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
var User ;
|
|
2
|
-
var Transaction = require('../models/np_transaction.model.js');
|
|
3
|
-
var IDLEN = 10 ;
|
|
4
|
-
function makeid(length) {
|
|
5
|
-
var text = "";
|
|
6
|
-
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
7
|
-
|
|
8
|
-
for (var i = 0; i < length; i++)
|
|
9
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
10
|
-
|
|
11
|
-
return text;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = function (app, callbacks) {
|
|
15
|
-
var module = {};
|
|
16
|
-
var config = (app.get('np_config'))
|
|
17
|
-
|
|
18
|
-
let usingMultiDbOrm = false;
|
|
19
|
-
if (config.db_url) {
|
|
20
|
-
User = require('../models/np_user.model.js');
|
|
21
|
-
usingMultiDbOrm = false;
|
|
22
|
-
} else if (app.multidborm) {
|
|
23
|
-
User = require('../models/np_multidbplugin.js')('npusers',app.multidborm);
|
|
24
|
-
User.db=app.multidborm;
|
|
25
|
-
User.modelname='npusers'
|
|
26
|
-
User.idFieldName='id'
|
|
27
|
-
app.NPUser = User;
|
|
28
|
-
usingMultiDbOrm = true;
|
|
29
|
-
}
|
|
30
|
-
module.create = (userData, cb) => {
|
|
31
|
-
|
|
32
|
-
User.findOne({ email: userData.email }, function (err, user) {
|
|
33
|
-
if (user) {
|
|
34
|
-
|
|
35
|
-
// console.log("User Update : ",userData.name );
|
|
36
|
-
var myquery = { email: userData.email };
|
|
37
|
-
|
|
38
|
-
var objForUpdate = user;
|
|
39
|
-
|
|
40
|
-
if (userData.email && userData.email.indexOf("@") !== -1) objForUpdate.email = userData.email;
|
|
41
|
-
if (userData.phone && userData.phone.length > 2) objForUpdate.phone = userData.phone;
|
|
42
|
-
if (userData.name && userData.name.length > 2) objForUpdate.name = userData.name;
|
|
43
|
-
delete objForUpdate._id ;
|
|
44
|
-
var newvalues = { $set: objForUpdate };
|
|
45
|
-
//console.log("User Old : ",userData.name);
|
|
46
|
-
User.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
47
|
-
if (err) cb({
|
|
48
|
-
message: err.message || "Some error occurred while updating users."
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// console.log("Sendiing callback")
|
|
52
|
-
cb(user);
|
|
53
|
-
// console.log("sent callback")
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
|
|
59
|
-
// console.log("User New : ",userData.name);
|
|
60
|
-
|
|
61
|
-
userData.id = "user_"+makeid(IDLEN);
|
|
62
|
-
var userTask = new User(userData);
|
|
63
|
-
userTask.save()
|
|
64
|
-
.then(user => {
|
|
65
|
-
// console.log("Sendiing callback")
|
|
66
|
-
cb(user);
|
|
67
|
-
// console.log("sent callback")
|
|
68
|
-
|
|
69
|
-
}).catch(err => {
|
|
70
|
-
return cb(err);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
},usingMultiDbOrm ? User : undefined);
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
return module;
|
|
79
|
-
|
|
1
|
+
var User ;
|
|
2
|
+
var Transaction = require('../models/np_transaction.model.js');
|
|
3
|
+
var IDLEN = 10 ;
|
|
4
|
+
function makeid(length) {
|
|
5
|
+
var text = "";
|
|
6
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
7
|
+
|
|
8
|
+
for (var i = 0; i < length; i++)
|
|
9
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
10
|
+
|
|
11
|
+
return text;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = function (app, callbacks) {
|
|
15
|
+
var module = {};
|
|
16
|
+
var config = (app.get('np_config'))
|
|
17
|
+
|
|
18
|
+
let usingMultiDbOrm = false;
|
|
19
|
+
if (config.db_url) {
|
|
20
|
+
User = require('../models/np_user.model.js');
|
|
21
|
+
usingMultiDbOrm = false;
|
|
22
|
+
} else if (app.multidborm) {
|
|
23
|
+
User = require('../models/np_multidbplugin.js')('npusers',app.multidborm);
|
|
24
|
+
User.db=app.multidborm;
|
|
25
|
+
User.modelname='npusers'
|
|
26
|
+
User.idFieldName='id'
|
|
27
|
+
app.NPUser = User;
|
|
28
|
+
usingMultiDbOrm = true;
|
|
29
|
+
}
|
|
30
|
+
module.create = (userData, cb) => {
|
|
31
|
+
|
|
32
|
+
User.findOne({ email: userData.email }, function (err, user) {
|
|
33
|
+
if (user) {
|
|
34
|
+
|
|
35
|
+
// console.log("User Update : ",userData.name );
|
|
36
|
+
var myquery = { email: userData.email };
|
|
37
|
+
|
|
38
|
+
var objForUpdate = user;
|
|
39
|
+
|
|
40
|
+
if (userData.email && userData.email.indexOf("@") !== -1) objForUpdate.email = userData.email;
|
|
41
|
+
if (userData.phone && userData.phone.length > 2) objForUpdate.phone = userData.phone;
|
|
42
|
+
if (userData.name && userData.name.length > 2) objForUpdate.name = userData.name;
|
|
43
|
+
delete objForUpdate._id ;
|
|
44
|
+
var newvalues = { $set: objForUpdate };
|
|
45
|
+
//console.log("User Old : ",userData.name);
|
|
46
|
+
User.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
47
|
+
if (err) cb({
|
|
48
|
+
message: err.message || "Some error occurred while updating users."
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// console.log("Sendiing callback")
|
|
52
|
+
cb(user);
|
|
53
|
+
// console.log("sent callback")
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
} else {
|
|
58
|
+
|
|
59
|
+
// console.log("User New : ",userData.name);
|
|
60
|
+
|
|
61
|
+
userData.id = "user_"+makeid(IDLEN);
|
|
62
|
+
var userTask = new User(userData);
|
|
63
|
+
userTask.save()
|
|
64
|
+
.then(user => {
|
|
65
|
+
// console.log("Sendiing callback")
|
|
66
|
+
cb(user);
|
|
67
|
+
// console.log("sent callback")
|
|
68
|
+
|
|
69
|
+
}).catch(err => {
|
|
70
|
+
return cb(err);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
},usingMultiDbOrm ? User : undefined);
|
|
76
|
+
|
|
77
|
+
};
|
|
78
|
+
return module;
|
|
79
|
+
|
|
80
80
|
}
|