node-paytmpg 7.5.3 → 7.5.6

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.
@@ -219,12 +219,12 @@ class OpenMoney {
219
219
  }, 3000);
220
220
  }
221
221
  else {
222
- res.status(401);
222
+ res.status(200);
223
223
  res.send({ message: 'Missing payment_token' });
224
224
  }
225
225
  }
226
226
  else {
227
- res.status(201);
227
+ res.status(200);
228
228
  res.send({ message: 'Webhook not supported' });
229
229
  }
230
230
  }
@@ -190,7 +190,13 @@ class PaymentController {
190
190
  const vp = this.viewPath;
191
191
  const razorPayInstance = this.razorPayInstance;
192
192
  if (!req.body.ORDER_ID && !req.body.EMAIL && ((_a = req.query) === null || _a === void 0 ? void 0 : _a.to)) {
193
- let toData = JSON.parse(this.decodeTxnDataFromUrl(req.query.to, req));
193
+ let toData = {};
194
+ try {
195
+ toData = JSON.parse(this.decodeTxnDataFromUrl(req.query.to, req));
196
+ }
197
+ catch {
198
+ console.log("Error parsing 'to' query param data");
199
+ }
194
200
  req.body.NAME = toData.NAME;
195
201
  req.body.EMAIL = toData.EMAIL;
196
202
  req.body.TXN_AMOUNT = toData.TXN_AMOUNT;
@@ -721,80 +727,89 @@ class PaymentController {
721
727
  return serviceUsed;
722
728
  }
723
729
  async webhook(req, res) {
724
- let config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
725
- const payuInstance = this.payuInstance;
726
- const openMoneyInstance = this.openMoneyInstance;
727
- console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
728
- console.log("request_data rawBody", req.originalUrl, req.rawBody);
729
- console.log("request_headers ", req.originalUrl, JSON.stringify(req.headers));
730
- let serviceUsed = this.getServiceUsed(req, config);
731
- if (serviceUsed === 'Paytm') {
732
- await this.callback(req, res);
733
- return;
734
- }
735
- if (serviceUsed === 'Razorpay') {
736
- const events = ["payment.captured", "payment.pending", "payment.failed"];
737
- if (req.body.event && events.indexOf(req.body.event) > -1) {
738
- if (req.body.payload &&
739
- req.body.payload.payment &&
740
- req.body.payload.payment.entity) {
741
- const entity = req.body.payload.payment.entity;
742
- const razorpay_order_id = entity.order_id;
743
- const order = await this.getOrder(undefined, razorpay_order_id);
744
- config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, order || undefined);
745
- const razorpay_payment_id = entity.id;
746
- const status = entity.status;
747
- const event = req.body.event;
748
- console.log(`Razorpay webhook payment order=${razorpay_order_id} payid=${razorpay_payment_id} status=${status}`);
749
- const reqBody = req.rawBody;
750
- const signature = req.headers["x-razorpay-signature"];
751
- console.log("Razorpay webhook signature:", signature);
752
- if (signature === undefined) {
753
- res.status(400).send({ message: "Missing Razorpay signature" });
754
- return;
755
- }
756
- let signatureValid;
757
- try {
758
- signatureValid = razorpay_1.default.validateWebhookSignature(reqBody, signature, config.SECRET);
759
- }
760
- catch (e) {
761
- signatureValid = false;
762
- }
763
- if (signatureValid) {
764
- if (event === events[0]) {
765
- req.body.STATUS = "TXN_SUCCESS";
730
+ try {
731
+ let config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
732
+ const payuInstance = this.payuInstance;
733
+ const openMoneyInstance = this.openMoneyInstance;
734
+ console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
735
+ console.log("request_data rawBody", req.originalUrl, req.rawBody);
736
+ console.log("request_headers ", req.originalUrl, JSON.stringify(req.headers));
737
+ let serviceUsed = this.getServiceUsed(req, config);
738
+ if (serviceUsed === 'Paytm') {
739
+ await this.callback(req, res);
740
+ return;
741
+ }
742
+ if (serviceUsed === 'Razorpay') {
743
+ const events = ["payment.captured", "payment.pending", "payment.failed"];
744
+ if (req.body.event && events.indexOf(req.body.event) > -1) {
745
+ if (req.body.payload &&
746
+ req.body.payload.payment &&
747
+ req.body.payload.payment.entity) {
748
+ const entity = req.body.payload.payment.entity;
749
+ const razorpay_order_id = entity.order_id;
750
+ const order = await this.getOrder(undefined, razorpay_order_id);
751
+ config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, order || undefined);
752
+ const razorpay_payment_id = entity.id;
753
+ const status = entity.status;
754
+ const event = req.body.event;
755
+ console.log(`Razorpay webhook payment order=${razorpay_order_id} payid=${razorpay_payment_id} status=${status}`);
756
+ const reqBody = req.rawBody;
757
+ const signature = req.headers["x-razorpay-signature"];
758
+ console.log("Razorpay webhook signature:", signature);
759
+ if (signature === undefined) {
760
+ res.status(200).send({ message: "Missing Razorpay signature" });
761
+ return;
766
762
  }
767
- else if (event === events[1]) { //pending
768
- req.body.STATUS = "TXN_PENDING";
763
+ let signatureValid;
764
+ try {
765
+ signatureValid = razorpay_1.default.validateWebhookSignature(reqBody, signature, config.SECRET);
769
766
  }
770
- else { // failed
771
- req.body.STATUS = "TXN_FAILURE";
767
+ catch (e) {
768
+ signatureValid = false;
769
+ }
770
+ if (signatureValid) {
771
+ if (event === events[0]) {
772
+ req.body.STATUS = "TXN_SUCCESS";
773
+ }
774
+ else if (event === events[1]) { //pending
775
+ req.body.STATUS = "TXN_PENDING";
776
+ }
777
+ else { // failed
778
+ req.body.STATUS = "TXN_FAILURE";
779
+ }
780
+ req.body.ORDERID = razorpay_order_id;
781
+ req.body.TXNID = razorpay_payment_id;
782
+ setTimeout(() => {
783
+ this.updateTransaction(req, res);
784
+ }, 3000);
785
+ }
786
+ else {
787
+ res.status(200).send({ message: "Invalid Rzpay signature" });
772
788
  }
773
- req.body.ORDERID = razorpay_order_id;
774
- req.body.TXNID = razorpay_payment_id;
775
- setTimeout(() => {
776
- this.updateTransaction(req, res);
777
- }, 3000);
778
789
  }
779
790
  else {
780
- res.status(401).send({ message: "Invalid Rzpay signature" });
791
+ res.status(200).send({ message: "Invalid Payload" });
781
792
  }
782
793
  }
783
794
  else {
784
- res.status(400).send({ message: "Invalid Payload" });
795
+ res.status(200).send({ message: "Unsupported event : " + req.body.event });
785
796
  }
797
+ return;
786
798
  }
787
- else {
788
- res.status(400).send({ message: "Unsupported event : " + req.body.event });
799
+ if (serviceUsed === 'PayU') {
800
+ payuInstance.processWebhook(req, res, this.updateTransaction);
801
+ return;
802
+ }
803
+ if (serviceUsed === 'OpenMoney') {
804
+ openMoneyInstance.processWebhook(req, res, this.updateTransaction);
789
805
  }
790
- return;
791
- }
792
- if (serviceUsed === 'PayU') {
793
- payuInstance.processWebhook(req, res, this.updateTransaction);
794
- return;
795
806
  }
796
- if (serviceUsed === 'OpenMoney') {
797
- openMoneyInstance.processWebhook(req, res, this.updateTransaction);
807
+ catch (e) {
808
+ console.error("Error in webhook processing", e);
809
+ try {
810
+ res.status(200).send({ message: "Received" });
811
+ }
812
+ catch (e) { }
798
813
  }
799
814
  }
800
815
  async createTxn(req, res) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.5.3",
3
+ "version": "7.5.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "copy:public": "copyfiles -u 1 \"public/**/*\" dist/public",
13
13
  "build": "npm-run-all clean build:ts copy:views copy:public",
14
14
  "prepare": "npm run build",
15
- "prepublishOnly": "npm run build"
15
+ "prepublishOnly": "npm version patch && npm run build"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.5.3",
3
+ "version": "7.5.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "copy:public": "copyfiles -u 1 \"public/**/*\" dist/public",
13
13
  "build": "npm-run-all clean build:ts copy:views copy:public",
14
14
  "prepare": "npm run build",
15
- "prepublishOnly": "npm run build"
15
+ "prepublishOnly": "npm version patch && npm run build"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",