node-paytmpg 7.5.11 → 7.5.13

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.
package/README.MD CHANGED
@@ -25,9 +25,9 @@ const config = {
25
25
  host_url: "http://127.0.0.1:5544",
26
26
  path_prefix: "pay",
27
27
  homepage: "/",
28
-
29
28
  // enable one gateway
30
29
  payu_url: "https://test.payu.in/_payment",
30
+ // payu_url: "https://secure.payu.in/_payment",
31
31
  // paytm_url: 'https://securegw-stage.paytm.in',
32
32
  // razor_url: 'https://api.razorpay.com/',
33
33
  // open_money_url: 'https://sandbox-icp-api.bankopen.co/api',
@@ -1,3 +1,4 @@
1
+ import { NPConfig, NPTransaction } from '../../models';
1
2
  type Dict = Record<string, any>;
2
3
  interface PayUConfig {
3
4
  key: string;
@@ -6,22 +7,24 @@ interface PayUConfig {
6
7
  paymentUrl: string;
7
8
  verifyUrl: string;
8
9
  }
9
- interface PayURequestLike {
10
+ type PayURequestLike = {
10
11
  body?: Dict;
11
12
  query?: Dict;
12
13
  rawBody?: any;
13
14
  headers?: Dict;
14
- }
15
- interface PayUResponseLike {
15
+ } & any;
16
+ type PayUResponseLike = {
16
17
  writeHead: (status: number, headers: Dict) => void;
17
18
  write: (chunk: string) => void;
18
19
  end: () => void;
19
- status: (code: number) => void;
20
+ status: (code: number) => PayUResponseLike;
20
21
  send: (body: any) => void;
21
- }
22
+ };
22
23
  declare class PayU {
23
24
  config: PayUConfig;
24
- constructor(npconfig: Dict);
25
+ baseConfig: NPConfig;
26
+ constructor(npconfig: NPConfig);
27
+ initParams(npconfig: NPConfig & Dict): void;
25
28
  normalizeAmount(amount: any): string;
26
29
  buildRequestHash(payload: Dict): string;
27
30
  buildResponseHash(data: Dict): string;
@@ -36,6 +39,12 @@ declare class PayU {
36
39
  checkBqrTxnStatus(transactionId: string): Promise<Dict>;
37
40
  renderProcessingPage(params: Dict, paymentReq: Dict, res: PayUResponseLike, loadingSVG: string): void;
38
41
  renderError(params: Dict, error: any, res: PayUResponseLike): void;
39
- processWebhook(req: PayURequestLike, res: PayUResponseLike, updateTransaction: Function): void;
42
+ /**
43
+ *
44
+ * @param req.body {"amount":"10.00","paymentMode":"UPICC","udf5":"","udf3":"","split_info":"","udf4":"","udf1":"user_SGnPOmzPxi","udf2":"payu_b2ThO9ra4e","customerName":"test","productInfo":"TEST","customerPhone":"","additionalCharges":"","paymentId":"27778865835","customerEmail":"test@gmail.com","merchantTransactionId":"payu_b2ThO9ra4e","error_Message":"No Error","notificationId":"12345","bankRefNum":"161058882264","hash":"12345","key":"2ETh7I","status":"Success","field4":""}
45
+ * @param res
46
+ * @param updateTransaction
47
+ */
48
+ processWebhook(req: PayURequestLike, res: PayUResponseLike, updateTransaction: Function, getOrder: (req: Request, orderId?: string) => Promise<NPTransaction | null>): Promise<void>;
40
49
  }
41
50
  export default PayU;
@@ -5,8 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const crypto_1 = __importDefault(require("crypto"));
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const buildConfig_1 = require("../../utils/buildConfig");
8
9
  class PayU {
9
10
  constructor(npconfig) {
11
+ this.initParams(npconfig);
12
+ }
13
+ initParams(npconfig) {
14
+ this.baseConfig = npconfig;
10
15
  const baseUrl = (npconfig.payu_url || '').replace(/\/$/, '');
11
16
  const isSandbox = baseUrl.indexOf('test.payu.in') > -1;
12
17
  const verifyUrl = npconfig.payu_verify_url || (isSandbox
@@ -196,9 +201,32 @@ class PayU {
196
201
  res.write(html);
197
202
  res.end();
198
203
  }
199
- processWebhook(req, res, updateTransaction) {
200
- res.status(201);
201
- res.send({ message: 'Webhook not implemented for PayU' });
204
+ /**
205
+ *
206
+ * @param req.body {"amount":"10.00","paymentMode":"UPICC","udf5":"","udf3":"","split_info":"","udf4":"","udf1":"user_SGnPOmzPxi","udf2":"payu_b2ThO9ra4e","customerName":"test","productInfo":"TEST","customerPhone":"","additionalCharges":"","paymentId":"27778865835","customerEmail":"test@gmail.com","merchantTransactionId":"payu_b2ThO9ra4e","error_Message":"No Error","notificationId":"12345","bankRefNum":"161058882264","hash":"12345","key":"2ETh7I","status":"Success","field4":""}
207
+ * @param res
208
+ * @param updateTransaction
209
+ */
210
+ async processWebhook(req, res, updateTransaction, getOrder) {
211
+ var _a;
212
+ let body = ((_a = req.body) === null || _a === void 0 ? void 0 : _a.event_payload) || req.body;
213
+ let orderId = (body === null || body === void 0 ? void 0 : body.merchantTransactionId) || (body === null || body === void 0 ? void 0 : body.udf2);
214
+ if (!orderId) {
215
+ console.log('PayU Webhook: Missing order identifier in payload', body);
216
+ res.status(200).send({ error: 'Missing order identifier' });
217
+ return;
218
+ }
219
+ let originalOrder = await getOrder(req, orderId);
220
+ let updatedConfig = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, originalOrder);
221
+ this.initParams(updatedConfig);
222
+ const payuRest = await this.verifyResult(req);
223
+ let result = !!payuRest.STATUS;
224
+ req.body.STATUS = payuRest.STATUS;
225
+ req.body.TXNID = payuRest.TXNID;
226
+ req.body.ORDERID = payuRest.ORDERID || req.query.order_id;
227
+ req.body.extras = payuRest.data;
228
+ let isCancelled = !!payuRest.cancelled;
229
+ updateTransaction(req, res, true);
202
230
  }
203
231
  }
204
232
  exports.default = PayU;
@@ -209,6 +209,7 @@ class PaymentController {
209
209
  req.body.PRODUCT_NAME = toData.PRODUCT_NAME;
210
210
  req.body.RETURN_URL = toData.RETURN_URL;
211
211
  req.body.CLIENT_ID = toData.CLIENT_ID;
212
+ req.body.STATE = toData.STATE;
212
213
  }
213
214
  const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
214
215
  utils_1.Utils.sanitizeRequest(req.body);
@@ -387,6 +388,7 @@ class PaymentController {
387
388
  INDUSTRY_TYPE_ID: params['INDUSTRY_TYPE_ID'],
388
389
  CHANNEL_ID: params['CHANNEL_ID'],
389
390
  CALLBACK_URL: params['CALLBACK_URL'],
391
+ STATE: params['STATE'],
390
392
  CHECKSUMHASH: checksum,
391
393
  CLIENT_ID: params['CLIENT_ID'] || txnData.clientId || config.client_id || ''
392
394
  });
@@ -415,6 +417,7 @@ class PaymentController {
415
417
  extra: '',
416
418
  returnUrl: req.body.RETURN_URL || '',
417
419
  webhookUrl: req.body.WEBHOOK_URL || '',
420
+ state: req.body.STATE || '',
418
421
  clientId: req.body.CLIENT_ID || ''
419
422
  };
420
423
  try {
@@ -501,6 +504,7 @@ class PaymentController {
501
504
  CHANNEL_ID: config.CHANNEL_ID,
502
505
  CALLBACK_URL: config.CALLBACK_URL,
503
506
  CHECKSUMHASH: '',
507
+ STATE: (req.body.STATE === undefined ? '' : req.body.STATE),
504
508
  CLIENT_ID: config.client_id || req.body.CLIENT_ID || ''
505
509
  });
506
510
  }
@@ -633,8 +637,6 @@ class PaymentController {
633
637
  return objForUpdate;
634
638
  }
635
639
  async callback(req, res) {
636
- const payuInstance = this.getProviderInstance('PayU', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
637
- const openMoneyInstance = this.getProviderInstance('OpenMoney', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
638
640
  console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
639
641
  // Normalize common order id and txn id field names (support ORDER_ID, ORDERID, etc.)
640
642
  try {
@@ -655,6 +657,8 @@ class PaymentController {
655
657
  let isCancelled = false;
656
658
  const objForUpdate = await this.getOrder(req);
657
659
  const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, objForUpdate);
660
+ const payuInstance = this.getProviderInstance('PayU', (0, buildConfig_1.withClientConfigOverrides)(config, req, objForUpdate));
661
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', (0, buildConfig_1.withClientConfigOverrides)(config, req, objForUpdate));
658
662
  if (config.paytm_url) {
659
663
  const checksumhash = req.body.CHECKSUMHASH;
660
664
  if (checksumhash) {
@@ -816,11 +820,11 @@ class PaymentController {
816
820
  return;
817
821
  }
818
822
  if (serviceUsed === 'PayU') {
819
- payuInstance.processWebhook(req, res, this.updateTransaction);
823
+ payuInstance.processWebhook(req, res, this.updateTransaction, this.getOrder);
820
824
  return;
821
825
  }
822
826
  if (serviceUsed === 'OpenMoney') {
823
- openMoneyInstance.processWebhook(req, res, this.updateTransaction);
827
+ openMoneyInstance.processWebhook(req, res, this.updateTransaction, this.getOrder);
824
828
  }
825
829
  }
826
830
  catch (e) {
@@ -885,6 +889,7 @@ class PaymentController {
885
889
  returnUrl: req.body.RETURN_URL || '',
886
890
  webhookUrl: req.body.WEBHOOK_URL || '',
887
891
  extra: (req.body.EXTRA || ''),
892
+ state: req.body.STATE || '',
888
893
  clientId: req.body.CLIENT_ID || ''
889
894
  };
890
895
  const txn = await this.insertTransactionInDb(txnTask);
@@ -899,6 +904,7 @@ class PaymentController {
899
904
  PRODUCT_NAME: txn.pname,
900
905
  clientId: txn.clientId,
901
906
  CLIENT_ID: txn.clientId,
907
+ STATE: txn.state,
902
908
  }), req);
903
909
  txn.payurl = config.host_url + '/' + config.path_prefix + '/init?to=' + urlData64;
904
910
  if (txn.clientId) {
@@ -939,6 +945,8 @@ class PaymentController {
939
945
  status: 'status',
940
946
  mobile_no: 'phone',
941
947
  CLIENT_ID: 'clientId',
948
+ state: 'state',
949
+ STATE: 'state',
942
950
  clientId: 'clientId',
943
951
  WEBHOOK_URL: 'webhookUrl',
944
952
  webhookUrl: 'webhookUrl',
@@ -970,11 +978,6 @@ class PaymentController {
970
978
  }
971
979
  }
972
980
  async status(req, res) {
973
- const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
974
- const callbacks = this.callbacks;
975
- const payuInstance = this.getProviderInstance('PayU', config);
976
- const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
977
- const razorPayInstance = this.getProviderInstance('Razorpay', config);
978
981
  if (!req.body.ORDERID && req.query.ORDERID) {
979
982
  req.body.ORDERID = req.query.ORDERID;
980
983
  }
@@ -993,6 +996,11 @@ class PaymentController {
993
996
  res.send(err);
994
997
  return null;
995
998
  });
999
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, orderData);
1000
+ const callbacks = this.callbacks;
1001
+ const payuInstance = this.getProviderInstance('PayU', config);
1002
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
1003
+ const razorPayInstance = this.getProviderInstance('Razorpay', config);
996
1004
  if (!orderData) {
997
1005
  if (!res.headersSent) {
998
1006
  res.send({ message: "Order Not Found or not initiated yet!", ORDER_ID: req.body.ORDER_ID });
@@ -27,6 +27,7 @@ export interface NPTransaction {
27
27
  readonly?: string;
28
28
  txnId?: string;
29
29
  clientId: string;
30
+ state?: string;
30
31
  returnUrl: string;
31
32
  webhookUrl: string;
32
33
  }
@@ -37,7 +37,7 @@ const paymentRoute = function (app, express, callbacks) {
37
37
  router.all('/', pc.init);
38
38
  router.all('/init', pc.init);
39
39
  router.all('/callback', pc.callback);
40
- router.all('/api/webhook', pc.webhook);
40
+ router.all(['/api/webhook', '/api/webhook/*'], pc.webhook);
41
41
  router.all('/api/status', pc.status);
42
42
  router.all('/api/createTxn/token', pc.createTxnToken);
43
43
  router.all('/api/createTxn', pc.createTxn);
package/dist/index.js CHANGED
@@ -94,7 +94,7 @@ function createPaymentMiddleware(app, userConfig, db, callbacks, authenticationM
94
94
  subApp.all('/callback', authenticationMiddleware, (req, res) => {
95
95
  pc.callback(req, res);
96
96
  });
97
- subApp.all('/api/webhook', authenticationMiddleware, (req, res) => {
97
+ subApp.all(['/api/webhook', '/api/webhook/*'], authenticationMiddleware, (req, res) => {
98
98
  pc.webhook(req, res);
99
99
  });
100
100
  subApp.all('/api/status', authenticationMiddleware, (req, res) => {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.5.11",
3
+ "version": "7.5.13",
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.11",
3
+ "version": "7.5.13",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",