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(
|
|
222
|
+
res.status(200);
|
|
223
223
|
res.send({ message: 'Missing payment_token' });
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
else {
|
|
227
|
-
res.status(
|
|
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
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
if (req.body.
|
|
739
|
-
req.body.payload
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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
|
-
|
|
768
|
-
|
|
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 {
|
|
771
|
-
|
|
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(
|
|
785
|
+
res.status(200).send({ message: "Invalid Payload" });
|
|
781
786
|
}
|
|
782
787
|
}
|
|
783
788
|
else {
|
|
784
|
-
res.status(
|
|
789
|
+
res.status(200).send({ message: "Unsupported event : " + req.body.event });
|
|
785
790
|
}
|
|
791
|
+
return;
|
|
786
792
|
}
|
|
787
|
-
|
|
788
|
-
|
|
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
|
-
|
|
797
|
-
|
|
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
package/package.json
CHANGED