node-paytmpg 6.4.7 → 7.0.1

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.
Files changed (58) hide show
  1. package/README.MD +132 -182
  2. package/app/views/layouts/index.hbs +7 -7
  3. package/app/views/result.hbs +1 -1
  4. package/dist/app/controllers/adapters/open_money.js +400 -0
  5. package/dist/app/controllers/adapters/paytm.js +34 -0
  6. package/{app → dist/app}/controllers/adapters/payu.js +208 -239
  7. package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
  8. package/dist/app/controllers/checksum/checksum.js +158 -0
  9. package/dist/app/controllers/checksum/crypt.js +117 -0
  10. package/dist/app/controllers/checksum/server.js +130 -0
  11. package/dist/app/controllers/payment.controller.js +985 -0
  12. package/dist/app/controllers/static/loadingsvg.js +54 -0
  13. package/dist/app/controllers/user.controller.js +53 -0
  14. package/dist/app/models/index.js +2 -0
  15. package/dist/app/routes/payment_route.js +46 -0
  16. package/dist/app/utils/buildConfig.js +210 -0
  17. package/dist/app/utils/utils.js +20 -0
  18. package/dist/app/views/home.hbs +22 -0
  19. package/dist/app/views/init.hbs +98 -0
  20. package/dist/app/views/layouts/index.hbs +53 -0
  21. package/dist/app/views/result.hbs +33 -0
  22. package/dist/index.js +119 -0
  23. package/dist/package.json +67 -0
  24. package/dist/public/css/style.css +455 -0
  25. package/dist/public/js/index.js +283 -0
  26. package/dist/public/layer_checkout.js +38 -0
  27. package/dist/public/pay.png +0 -0
  28. package/dist/public/start.png +0 -0
  29. package/dist/public/start2.png +0 -0
  30. package/dist/public/stat.png +0 -0
  31. package/dist/public/test.html +24 -0
  32. package/dist/public/test.html~ +24 -0
  33. package/package.json +29 -6
  34. package/public/test.html~ +24 -0
  35. package/.github/workflows/codeql-analysis.yml +0 -71
  36. package/.github/workflows/nodejs.yml +0 -24
  37. package/.github/workflows/npm-publish.yml +0 -23
  38. package/Dockerfile +0 -9
  39. package/app/controllers/adapters/open_money.js +0 -515
  40. package/app/controllers/checksum/PaytmChecksum.js +0 -94
  41. package/app/controllers/checksum/checksum.js +0 -154
  42. package/app/controllers/checksum/crypt.js +0 -98
  43. package/app/controllers/checksum/server.js +0 -132
  44. package/app/controllers/np_user.controller.js +0 -89
  45. package/app/controllers/payment_controller.js +0 -1295
  46. package/app/models/np_multidbplugin.js +0 -111
  47. package/app/models/np_transaction.model.js +0 -16
  48. package/app/models/np_user.model.js +0 -12
  49. package/app/routes/payment_route.js +0 -73
  50. package/app.yaml +0 -18
  51. package/example.js +0 -34
  52. package/index.js +0 -90
  53. package/lib/config/buildConfig.js +0 -113
  54. package/lib/config/defaults.js +0 -37
  55. package/lib/config/validator.js +0 -103
  56. package/lib/services/database.service.js +0 -153
  57. package/lib/utils/id-generator.js +0 -30
  58. package/lib/utils/sanitizer.js +0 -25
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.genchecksum = genchecksum;
40
+ exports.genchecksumbystring = genchecksumbystring;
41
+ exports.verifychecksum = verifychecksum;
42
+ exports.verifychecksumbystring = verifychecksumbystring;
43
+ exports.genchecksumforrefund = genchecksumforrefund;
44
+ exports.checkRazorSignature = checkRazorSignature;
45
+ const crypto = __importStar(require("crypto"));
46
+ const crypt = __importStar(require("./crypt"));
47
+ const PaytmChecksum_1 = __importDefault(require("./PaytmChecksum"));
48
+ // Note: some code referenced a `mandatoryParams` variable in the original JS. If your app
49
+ // defines it globally, this will pick it up; otherwise default to empty array.
50
+ const mandatoryParams = global.mandatoryParams || [];
51
+ function paramsToString(params, mandatoryflag) {
52
+ let data = '';
53
+ const tempKeys = Object.keys(params);
54
+ tempKeys.sort();
55
+ tempKeys.forEach(function (key) {
56
+ if (!params[key]) {
57
+ return;
58
+ }
59
+ try {
60
+ const n = String(params[key]).includes('REFUND');
61
+ const m = String(params[key]).includes('|');
62
+ if (n === true) {
63
+ params[key] = '';
64
+ }
65
+ if (m === true) {
66
+ params[key] = '';
67
+ }
68
+ }
69
+ catch (e) {
70
+ params[key] = '';
71
+ console.log(e);
72
+ }
73
+ if (key !== 'CHECKSUMHASH') {
74
+ if (params[key] === 'null')
75
+ params[key] = '';
76
+ if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
77
+ data += (params[key] + '|');
78
+ }
79
+ }
80
+ });
81
+ return data;
82
+ }
83
+ function genchecksum(params, key, cb) {
84
+ const checksumPromise = PaytmChecksum_1.default.generateSignature(params, key).then(checksum => {
85
+ cb(undefined, checksum);
86
+ }).catch(err => cb(err));
87
+ return checksumPromise;
88
+ }
89
+ function genchecksumbystring(params, key, cb) {
90
+ crypt.gen_salt(4).then(salt => {
91
+ const sha256 = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
92
+ const check_sum = sha256 + salt;
93
+ const encrypted = crypt.encrypt(check_sum, key);
94
+ const CHECKSUMHASH = encrypted;
95
+ cb(undefined, CHECKSUMHASH);
96
+ }).catch(err => cb(err));
97
+ }
98
+ function verifychecksum(params, key, checksumhash) {
99
+ return PaytmChecksum_1.default.verifySignature(params, key, checksumhash);
100
+ }
101
+ function verifychecksumbystring(params, key, checksumhash) {
102
+ const checksum = crypt.decrypt(checksumhash, key);
103
+ const salt = checksum.substr(checksum.length - 4);
104
+ const sha256 = checksum.substr(0, checksum.length - 4);
105
+ const hash = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
106
+ if (hash === sha256) {
107
+ return true;
108
+ }
109
+ else {
110
+ console.log('checksum is wrong');
111
+ return false;
112
+ }
113
+ }
114
+ function genchecksumforrefund(params, key, cb) {
115
+ const data = paramsToStringrefund(params);
116
+ crypt.gen_salt(4).then(salt => {
117
+ const sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
118
+ const check_sum = sha256 + salt;
119
+ const encrypted = crypt.encrypt(check_sum, key);
120
+ params.CHECKSUM = encodeURIComponent(encrypted);
121
+ cb(undefined, params);
122
+ }).catch(err => cb(err));
123
+ }
124
+ function paramsToStringrefund(params, mandatoryflag) {
125
+ let data = '';
126
+ const tempKeys = Object.keys(params);
127
+ tempKeys.sort();
128
+ tempKeys.forEach(function (key) {
129
+ const m = String(params[key]).includes('|');
130
+ if (m == true) {
131
+ params[key] = '';
132
+ }
133
+ if (key !== 'CHECKSUMHASH') {
134
+ if (params[key] === 'null')
135
+ params[key] = '';
136
+ if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
137
+ data += (params[key] + '|');
138
+ }
139
+ }
140
+ });
141
+ return data;
142
+ }
143
+ function checkRazorSignature(razorpayOrderId, razorpayPaymentId, secret, razorpay_signature) {
144
+ const hmac = crypto.createHmac('sha256', secret);
145
+ hmac.update(razorpayOrderId + '|' + razorpayPaymentId);
146
+ const generatedSignature = hmac.digest('hex');
147
+ const isSignatureValid = generatedSignature == razorpay_signature;
148
+ return isSignatureValid;
149
+ }
150
+ // CommonJS compatibility
151
+ exports.default = {
152
+ genchecksum,
153
+ verifychecksum,
154
+ verifychecksumbystring,
155
+ genchecksumbystring,
156
+ genchecksumforrefund,
157
+ checkRazorSignature,
158
+ };
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.iv = void 0;
40
+ exports.encrypt = encrypt;
41
+ exports.decrypt = decrypt;
42
+ exports.gen_salt = gen_salt;
43
+ exports.md5sum = md5sum;
44
+ exports.sha256sum = sha256sum;
45
+ const crypto = __importStar(require("crypto"));
46
+ const util_1 = __importDefault(require("util"));
47
+ exports.iv = '@@@@&&&&####$$$$';
48
+ function encrypt(data, custom_key) {
49
+ const key = custom_key;
50
+ let algo = '256';
51
+ switch (key.length) {
52
+ case 16:
53
+ algo = '128';
54
+ break;
55
+ case 24:
56
+ algo = '192';
57
+ break;
58
+ case 32:
59
+ algo = '256';
60
+ break;
61
+ }
62
+ const cipher = crypto.createCipheriv('AES-' + algo + '-CBC', key, exports.iv);
63
+ let encrypted = cipher.update(data, 'binary', 'base64');
64
+ encrypted += cipher.final('base64');
65
+ return encrypted;
66
+ }
67
+ function decrypt(data, custom_key) {
68
+ const key = custom_key;
69
+ let algo = '256';
70
+ switch (key.length) {
71
+ case 16:
72
+ algo = '128';
73
+ break;
74
+ case 24:
75
+ algo = '192';
76
+ break;
77
+ case 32:
78
+ algo = '256';
79
+ break;
80
+ }
81
+ const decipher = crypto.createDecipheriv('AES-' + algo + '-CBC', key, exports.iv);
82
+ let decrypted = decipher.update(data, 'base64', 'binary');
83
+ try {
84
+ decrypted += decipher.final('binary');
85
+ }
86
+ catch (e) {
87
+ console.log(util_1.default.inspect(e));
88
+ }
89
+ return decrypted;
90
+ }
91
+ function gen_salt(length) {
92
+ return new Promise((resolve, reject) => {
93
+ crypto.randomBytes((length * 3.0) / 4.0, function (err, buf) {
94
+ if (!err) {
95
+ resolve(buf.toString('base64'));
96
+ }
97
+ else {
98
+ reject(err);
99
+ }
100
+ });
101
+ });
102
+ }
103
+ function md5sum(salt, data) {
104
+ return crypto.createHash('md5').update(salt + data).digest('hex');
105
+ }
106
+ function sha256sum(salt, data) {
107
+ return crypto.createHash('sha256').update(data + salt).digest('hex');
108
+ }
109
+ // CommonJS compatibility
110
+ exports.default = {
111
+ iv: exports.iv,
112
+ encrypt,
113
+ decrypt,
114
+ gen_salt,
115
+ md5sum,
116
+ sha256sum,
117
+ };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const http = __importStar(require("http"));
37
+ const https = __importStar(require("https"));
38
+ const qs = __importStar(require("querystring"));
39
+ const checksum_1 = require("./checksum");
40
+ const port = 8080;
41
+ const PaytmConfig = {
42
+ mid: 'XXXXXXXXXXXXXXXXXXXX',
43
+ key: 'XXXXXXXXXXXXXXXX',
44
+ website: 'XXXXXXXXXX',
45
+ };
46
+ http.createServer(function (req, res) {
47
+ switch (req.url) {
48
+ case '/': {
49
+ const params = {};
50
+ params['MID'] = PaytmConfig.mid;
51
+ params['WEBSITE'] = PaytmConfig.website;
52
+ params['CHANNEL_ID'] = 'WEB';
53
+ params['INDUSTRY_TYPE_ID'] = 'Retail';
54
+ params['ORDER_ID'] = 'TEST_' + new Date().getTime();
55
+ params['CUST_ID'] = 'Customer001';
56
+ params['TXN_AMOUNT'] = '1.00';
57
+ params['CALLBACK_URL'] = 'http://localhost:' + port + '/callback';
58
+ params['EMAIL'] = 'abc@mailinator.com';
59
+ params['MOBILE_NO'] = '7777777777';
60
+ (0, checksum_1.genchecksum)(params, PaytmConfig.key, function (err, checksum) {
61
+ const txn_url = 'https://securegw-stage.paytm.in/theia/processTransaction';
62
+ let form_fields = '';
63
+ for (const x in params) {
64
+ form_fields += "<input type='hidden' name='" + x + "' value='" + params[x] + "' >";
65
+ }
66
+ form_fields += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "' >";
67
+ res.writeHead(200, { 'Content-Type': 'text/html' });
68
+ 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>');
69
+ res.end();
70
+ });
71
+ break;
72
+ }
73
+ case '/callback': {
74
+ let body = '';
75
+ req.on('data', function (data) {
76
+ body += data;
77
+ });
78
+ req.on('end', function () {
79
+ let html = '';
80
+ const post_data = qs.parse(body);
81
+ console.log('Callback Response: ', post_data, '\n');
82
+ html += '<b>Callback Response</b><br>';
83
+ for (const x in post_data) {
84
+ html += x + ' => ' + post_data[x] + '<br/>';
85
+ }
86
+ html += '<br/><br/>';
87
+ const checksumhash = post_data.CHECKSUMHASH;
88
+ const result = (0, checksum_1.verifychecksum)(post_data, PaytmConfig.key, checksumhash);
89
+ console.log('Checksum Result => ', result, '\n');
90
+ html += '<b>Checksum Result</b> => ' + (result ? 'True' : 'False');
91
+ html += '<br/><br/>';
92
+ const params = { MID: PaytmConfig.mid, ORDERID: post_data.ORDERID };
93
+ (0, checksum_1.genchecksum)(params, PaytmConfig.key, function (err, checksum) {
94
+ params.CHECKSUMHASH = checksum;
95
+ const postData = 'JsonData=' + JSON.stringify(params);
96
+ const options = {
97
+ hostname: 'securegw-stage.paytm.in',
98
+ port: 443,
99
+ path: '/merchant-status/getTxnStatus',
100
+ method: 'POST',
101
+ headers: {
102
+ 'Content-Type': 'application/x-www-form-urlencoded',
103
+ 'Content-Length': Buffer.byteLength(postData),
104
+ },
105
+ };
106
+ let response = '';
107
+ const post_req = https.request(options, function (post_res) {
108
+ post_res.on('data', function (chunk) {
109
+ response += chunk;
110
+ });
111
+ post_res.on('end', function () {
112
+ console.log('S2S Response: ', response, '\n');
113
+ const _result = JSON.parse(response);
114
+ html += '<b>Status Check Response</b><br>';
115
+ for (const x in _result) {
116
+ html += x + ' => ' + _result[x] + '<br/>';
117
+ }
118
+ res.writeHead(200, { 'Content-Type': 'text/html' });
119
+ res.write(html);
120
+ res.end();
121
+ });
122
+ });
123
+ post_req.write(postData);
124
+ post_req.end();
125
+ });
126
+ });
127
+ break;
128
+ }
129
+ }
130
+ }).listen(port);