node-paytmpg 5.2.3 → 5.2.5

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.
@@ -3,6 +3,7 @@
3
3
  var crypt = require('./crypt');
4
4
  var util = require('util');
5
5
  var crypto = require('crypto');
6
+ const PaytmChecksum = require('./PaytmChecksum.js');
6
7
 
7
8
  //mandatory flag: when it set, only mandatory parameters are added to checksum
8
9
 
@@ -11,14 +12,24 @@ function paramsToString(params, mandatoryflag) {
11
12
  var tempKeys = Object.keys(params);
12
13
  tempKeys.sort();
13
14
  tempKeys.forEach(function (key) {
14
- var n = params[key].includes("REFUND");
15
- var m = params[key].includes("|");
16
- if (n == true) {
17
- params[key] = "";
15
+ if (!params[key]) {
16
+ return
18
17
  }
19
- if (m == true) {
18
+ try {
19
+ var n = params[key].includes("REFUND");
20
+ var m = params[key].includes("|");
21
+ if (n == true) {
22
+ params[key] = "";
23
+ }
24
+ if (m == true) {
25
+ params[key] = "";
26
+ }
27
+ } catch (e) {
20
28
  params[key] = "";
29
+ console.log(e)
21
30
  }
31
+
32
+
22
33
  if (key !== 'CHECKSUMHASH') {
23
34
  if (params[key] === 'null') params[key] = '';
24
35
  if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
@@ -31,6 +42,9 @@ function paramsToString(params, mandatoryflag) {
31
42
 
32
43
 
33
44
  function genchecksum(params, key, cb) {
45
+ let checksum = PaytmChecksum.generateSignature(params, key);
46
+ cb(undefined, checksum)
47
+ return checksum;
34
48
  var data = paramsToString(params);
35
49
  crypt.gen_salt(4, function (err, salt) {
36
50
  var sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
@@ -53,6 +67,7 @@ function genchecksumbystring(params, key, cb) {
53
67
  }
54
68
 
55
69
  function verifychecksum(params, key, checksumhash) {
70
+ return PaytmChecksum.verifySignature(params, key, checksumhash)
56
71
  var data = paramsToString(params, false);
57
72
 
58
73
  //TODO: after PG fix on thier side remove below two lines
@@ -193,10 +193,10 @@ module.exports = function (app, callbacks) {
193
193
  "email": params['EMAIL']
194
194
  }
195
195
  };
196
- if(config.mode){
197
- initTxnbody["enablePaymentMode"] = JSON.parse(config.mode)
196
+ if (config.mode) {
197
+ initTxnbody["enablePaymentMode"] = JSON.parse(config.mode)
198
198
  }
199
-
199
+
200
200
  let checksum = await PaytmChecksum.generateSignature(JSON.stringify(initTxnbody), config.KEY)
201
201
  let initTxnUrl = config.paytm_url + `/theia/api/v1/initiateTransaction?mid=${params['MID']}&orderId=${params['ORDER_ID']}`;
202
202
 
@@ -676,6 +676,7 @@ module.exports = function (app, callbacks) {
676
676
  }
677
677
 
678
678
  module.callback = async (req, res) => {
679
+ console.log("request_data ", req.originalUrl, req.body)
679
680
 
680
681
  var result = false;
681
682
  let isCancelled = false;
@@ -738,6 +739,10 @@ module.exports = function (app, callbacks) {
738
739
  }
739
740
 
740
741
  module.webhook = (req, res) => {
742
+
743
+
744
+ console.log("request_data ", req.originalUrl, req.body)
745
+
741
746
  if (config.paytm_url) {
742
747
  module.callback(req, res)
743
748
  }
@@ -891,11 +896,10 @@ module.exports = function (app, callbacks) {
891
896
  res.status(500)
892
897
  res.send('Something went wrong. Please try again later.')
893
898
  }
894
- else
895
- {
896
- tokenData.payurl = createTxnResult.payurl;
897
- res.send(tokenData)
898
- }
899
+ else {
900
+ tokenData.payurl = createTxnResult.payurl;
901
+ res.send(tokenData)
902
+ }
899
903
  },
900
904
  render: (renderPath2, init2ResultRender) => {
901
905
  console.log('init2ResultRender', init2ResultRender)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {