node-paytmpg 7.5.3 → 7.5.4

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
  }
@@ -721,80 +721,89 @@ class PaymentController {
721
721
  return serviceUsed;
722
722
  }
723
723
  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";
724
+ try {
725
+ let config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
726
+ const payuInstance = this.payuInstance;
727
+ const openMoneyInstance = this.openMoneyInstance;
728
+ console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
729
+ console.log("request_data rawBody", req.originalUrl, req.rawBody);
730
+ console.log("request_headers ", req.originalUrl, JSON.stringify(req.headers));
731
+ let serviceUsed = this.getServiceUsed(req, config);
732
+ if (serviceUsed === 'Paytm') {
733
+ await this.callback(req, res);
734
+ return;
735
+ }
736
+ if (serviceUsed === 'Razorpay') {
737
+ const events = ["payment.captured", "payment.pending", "payment.failed"];
738
+ if (req.body.event && events.indexOf(req.body.event) > -1) {
739
+ if (req.body.payload &&
740
+ req.body.payload.payment &&
741
+ req.body.payload.payment.entity) {
742
+ const entity = req.body.payload.payment.entity;
743
+ const razorpay_order_id = entity.order_id;
744
+ const order = await this.getOrder(undefined, razorpay_order_id);
745
+ config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, order || undefined);
746
+ const razorpay_payment_id = entity.id;
747
+ const status = entity.status;
748
+ const event = req.body.event;
749
+ console.log(`Razorpay webhook payment order=${razorpay_order_id} payid=${razorpay_payment_id} status=${status}`);
750
+ const reqBody = req.rawBody;
751
+ const signature = req.headers["x-razorpay-signature"];
752
+ console.log("Razorpay webhook signature:", signature);
753
+ if (signature === undefined) {
754
+ res.status(200).send({ message: "Missing Razorpay signature" });
755
+ return;
756
+ }
757
+ let signatureValid;
758
+ try {
759
+ signatureValid = razorpay_1.default.validateWebhookSignature(reqBody, signature, config.SECRET);
760
+ }
761
+ catch (e) {
762
+ signatureValid = false;
766
763
  }
767
- else if (event === events[1]) { //pending
768
- req.body.STATUS = "TXN_PENDING";
764
+ if (signatureValid) {
765
+ if (event === events[0]) {
766
+ req.body.STATUS = "TXN_SUCCESS";
767
+ }
768
+ else if (event === events[1]) { //pending
769
+ req.body.STATUS = "TXN_PENDING";
770
+ }
771
+ else { // failed
772
+ req.body.STATUS = "TXN_FAILURE";
773
+ }
774
+ req.body.ORDERID = razorpay_order_id;
775
+ req.body.TXNID = razorpay_payment_id;
776
+ setTimeout(() => {
777
+ this.updateTransaction(req, res);
778
+ }, 3000);
769
779
  }
770
- else { // failed
771
- req.body.STATUS = "TXN_FAILURE";
780
+ else {
781
+ res.status(200).send({ message: "Invalid Rzpay signature" });
772
782
  }
773
- req.body.ORDERID = razorpay_order_id;
774
- req.body.TXNID = razorpay_payment_id;
775
- setTimeout(() => {
776
- this.updateTransaction(req, res);
777
- }, 3000);
778
783
  }
779
784
  else {
780
- res.status(401).send({ message: "Invalid Rzpay signature" });
785
+ res.status(200).send({ message: "Invalid Payload" });
781
786
  }
782
787
  }
783
788
  else {
784
- res.status(400).send({ message: "Invalid Payload" });
789
+ res.status(200).send({ message: "Unsupported event : " + req.body.event });
785
790
  }
791
+ return;
786
792
  }
787
- else {
788
- res.status(400).send({ message: "Unsupported event : " + req.body.event });
793
+ if (serviceUsed === 'PayU') {
794
+ payuInstance.processWebhook(req, res, this.updateTransaction);
795
+ return;
796
+ }
797
+ if (serviceUsed === 'OpenMoney') {
798
+ openMoneyInstance.processWebhook(req, res, this.updateTransaction);
789
799
  }
790
- return;
791
- }
792
- if (serviceUsed === 'PayU') {
793
- payuInstance.processWebhook(req, res, this.updateTransaction);
794
- return;
795
800
  }
796
- if (serviceUsed === 'OpenMoney') {
797
- openMoneyInstance.processWebhook(req, res, this.updateTransaction);
801
+ catch (e) {
802
+ console.error("Error in webhook processing", e);
803
+ try {
804
+ res.status(200).send({ message: "Received" });
805
+ }
806
+ catch (e) { }
798
807
  }
799
808
  }
800
809
  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.4",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.5.3",
3
+ "version": "7.5.4",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -65,4 +65,4 @@
65
65
  "README.MD",
66
66
  "LICENSE"
67
67
  ]
68
- }
68
+ }