node-paytmpg 5.2.5 → 5.3.0

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.
@@ -42,9 +42,10 @@ function paramsToString(params, mandatoryflag) {
42
42
 
43
43
 
44
44
  function genchecksum(params, key, cb) {
45
- let checksum = PaytmChecksum.generateSignature(params, key);
46
- cb(undefined, checksum)
47
- return checksum;
45
+ let checksumPromise = PaytmChecksum.generateSignature(params, key).then(checksum => {
46
+ cb(undefined, checksum)
47
+ })
48
+ return checksumPromise;
48
49
  var data = paramsToString(params);
49
50
  crypt.gen_salt(4, function (err, salt) {
50
51
  var sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
@@ -641,7 +641,7 @@ module.exports = function (app, callbacks) {
641
641
  res.send({ message: "Transaction Not Found !", ORDERID: req.body.ORDERID, TXNID: req.body.TXNID })
642
642
  return;
643
643
  }
644
- if (objForUpdate.status != ("INITIATED") && objForUpdate.status != ("TXN_PENDING")) {
644
+ if (objForUpdate.status != ("INITIATED") && objForUpdate.status != ("TXN_PENDING") && objForUpdate.status != ("PENDING")) {
645
645
  objForUpdate.readonly = "readonly"
646
646
  objForUpdate.action = config.homepage
647
647
  res.render(vp + "result.hbs", objForUpdate);
@@ -676,13 +676,23 @@ 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
+ console.log("request_data ", req.originalUrl, JSON.stringify(req.headers), JSON.stringify(req.body))
680
680
 
681
681
  var result = false;
682
682
  let isCancelled = false;
683
683
  if (config.paytm_url) {
684
684
  var checksumhash = req.body.CHECKSUMHASH;
685
- result = checksum_lib.verifychecksum(req.body, config.KEY, checksumhash);
685
+ if (checksumhash) {
686
+ result = checksum_lib.verifychecksum(req.body, config.KEY, checksumhash);
687
+ }
688
+ else {
689
+ let liveStatus = await new Promise((resolve, reject) => {
690
+ getStatusFromPaytm(req.body, req.body.ORDERID, (paytmResponse) => {
691
+ resolve(paytmResponse)
692
+ })
693
+ })
694
+ result = liveStatus.STATUS == "TXN_SUCCESS";
695
+ }
686
696
  if (req.body.STATUS == 'TXN_FAILURE' && req.body.CANCELLED == "cancelled" && req.body.TXNID) {
687
697
  isCancelled = true;
688
698
  }
@@ -741,7 +751,8 @@ module.exports = function (app, callbacks) {
741
751
  module.webhook = (req, res) => {
742
752
 
743
753
 
744
- console.log("request_data ", req.originalUrl, req.body)
754
+
755
+ console.log("request_data ", req.originalUrl, JSON.stringify(req.headers), JSON.stringify(req.body))
745
756
 
746
757
  if (config.paytm_url) {
747
758
  module.callback(req, res)
@@ -970,26 +981,7 @@ module.exports = function (app, callbacks) {
970
981
  }
971
982
 
972
983
  if (config.paytm_url) {
973
- checksum_lib.genchecksum(params, config.KEY, function (err, checksum) {
974
-
975
- request.post(
976
- config.paytm_url + "/order/status",
977
- { json: { MID: config.MID, ORDERID: req.body.ORDER_ID, CHECKSUMHASH: checksum, } },
978
- function (error, response, body) {
979
-
980
- if (!error && response.statusCode == 200) {
981
- // console.log(body);
982
- var paytmResponse = JSON.parse(JSON.stringify(body))
983
- onStatusUpdate(paytmResponse)
984
- }
985
- else {
986
- console.log('ERROR:::', error, '\n', response);
987
- res.status(500)
988
- res.send({ message: "Error Occured !", ORDERID: req.body.ORDER_ID })
989
- }
990
- }
991
- );
992
- });
984
+ getStatusFromPaytm(params, req.body.ORDER_ID, onStatusUpdate)
993
985
  }
994
986
  else if (config.razor_url) {
995
987
  let result = await razorPayInstance.orders.fetch(req.body.ORDER_ID)
@@ -1050,5 +1042,26 @@ module.exports = function (app, callbacks) {
1050
1042
 
1051
1043
  }
1052
1044
 
1045
+ function getStatusFromPaytm(params, orderId, cb) {
1046
+ checksum_lib.genchecksum(params, config.KEY, function (err, checksum) {
1047
+
1048
+ request.post(
1049
+ config.paytm_url + "/order/status",
1050
+ { json: { MID: config.MID, ORDERID: orderId, CHECKSUMHASH: checksum, } },
1051
+ function (error, response, body) {
1052
+
1053
+ if (!error && response.statusCode == 200) {
1054
+ var paytmResponse = JSON.parse(JSON.stringify(body))
1055
+ cb(paytmResponse)
1056
+ }
1057
+ else {
1058
+ console.log('ERROR:::', error, '\n', response);
1059
+ cb({ message: "Error Occured !", ORDERID: orderId })
1060
+ }
1061
+ }
1062
+ );
1063
+ });
1064
+ }
1065
+
1053
1066
  return module;
1054
1067
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "5.2.5",
3
+ "version": "5.3.0",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {