node-paytmpg 7.5.6 → 7.5.8

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.
@@ -74,6 +74,7 @@
74
74
  </div>
75
75
 
76
76
  <button id="pay-button" type="submit" class="button">{{BUTTON}}</button>
77
+ <input type="hidden" name="CLIENT_ID" value="{{CLIENT_ID}}" {{readonly}} />
77
78
 
78
79
  <input type="hidden" name="MID" value="{{MID}}" {{readonly}} />
79
80
  <input type="hidden" name="WEBSITE" value="{{WEBSITE}}" {{readonly}} />
@@ -1,4 +1,7 @@
1
1
  import { MultiDbORM } from 'multi-db-orm';
2
+ import RazorPay from 'razorpay';
3
+ import OpenMoney from './adapters/open_money';
4
+ import PayU from './adapters/payu';
2
5
  import { Request, Response } from 'express';
3
6
  import { NPConfig, NPTableNames } from '../models';
4
7
  export declare class PaymentController {
@@ -8,12 +11,10 @@ export declare class PaymentController {
8
11
  private tableNames;
9
12
  private useController;
10
13
  private viewPath;
11
- private payuInstance;
12
- private openMoneyInstance;
13
- private razorPayInstance;
14
14
  constructor(baseConfig: NPConfig, db: MultiDbORM, callbacks?: any, tableNames?: NPTableNames);
15
15
  encodeTxnDataForUrl(txnDataJson: any, req: Request): string;
16
16
  decodeTxnDataFromUrl(encodedStr: string, req?: Request): any;
17
+ getProviderInstance(providerName: string, config: NPConfig): PayU | OpenMoney | typeof RazorPay | null;
17
18
  private configure;
18
19
  private insertTransactionInDb;
19
20
  private generateChecksum;
@@ -135,18 +135,23 @@ class PaymentController {
135
135
  }
136
136
  }
137
137
  }
138
+ getProviderInstance(providerName, config) {
139
+ switch (providerName) {
140
+ case 'PayU':
141
+ return new payu_1.default(config);
142
+ case 'OpenMoney':
143
+ return new open_money_1.default(config);
144
+ case 'RazorPay':
145
+ return new razorpay_1.default({ key_id: config.KEY, key_secret: config.SECRET });
146
+ default:
147
+ return null;
148
+ }
149
+ }
138
150
  configure(config) {
139
151
  const viewRoot = config.templateDir
140
152
  ? config.templateDir
141
153
  : path_1.default.join(__dirname, '..', 'views');
142
154
  this.viewPath = viewRoot.endsWith(path_1.default.sep) ? viewRoot : viewRoot + path_1.default.sep;
143
- if (config.payu_url)
144
- this.payuInstance = new payu_1.default(config);
145
- if (config.open_money_url)
146
- this.openMoneyInstance = new open_money_1.default(config);
147
- if (config.razor_url) {
148
- this.razorPayInstance = new razorpay_1.default({ key_id: config.KEY, key_secret: config.SECRET });
149
- }
150
155
  const sample = {
151
156
  orderId: "string",
152
157
  cusId: "string",
@@ -188,7 +193,6 @@ class PaymentController {
188
193
  var _a;
189
194
  const callbacks = this.callbacks;
190
195
  const vp = this.viewPath;
191
- const razorPayInstance = this.razorPayInstance;
192
196
  if (!req.body.ORDER_ID && !req.body.EMAIL && ((_a = req.query) === null || _a === void 0 ? void 0 : _a.to)) {
193
197
  let toData = {};
194
198
  try {
@@ -318,13 +322,15 @@ class PaymentController {
318
322
  return (0, htmlhelper_1.renderRazorpayCheckout)(req, res, params, config, loadingsvg_1.LoadingSVG);
319
323
  }
320
324
  else if (config.payu_url) {
321
- const payuRequest = this.payuInstance.generatePaymentRequest(params);
322
- this.payuInstance.renderProcessingPage(params, payuRequest, res, loadingsvg_1.LoadingSVG);
325
+ const payuInstance = this.getProviderInstance('PayU', config);
326
+ const payuRequest = payuInstance.generatePaymentRequest(params);
327
+ payuInstance.renderProcessingPage(params, payuRequest, res, loadingsvg_1.LoadingSVG);
323
328
  }
324
329
  else if (config.open_money_url) {
330
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
325
331
  try {
326
- let pmttoken = await this.openMoneyInstance.generatePaymentToken(params);
327
- this.openMoneyInstance.renderProcessingPage(params, pmttoken, res, loadingsvg_1.LoadingSVG);
332
+ let pmttoken = await openMoneyInstance.generatePaymentToken(params);
333
+ openMoneyInstance.renderProcessingPage(params, pmttoken, res, loadingsvg_1.LoadingSVG);
328
334
  var myquery = { orderId: params['ORDER_ID'] };
329
335
  const objForUpdate = await this.db.getOne(this.tableNames.TRANSACTION, myquery);
330
336
  if (objForUpdate) {
@@ -335,7 +341,7 @@ class PaymentController {
335
341
  }
336
342
  }
337
343
  catch (e) {
338
- this.openMoneyInstance.renderError(params, e, res);
344
+ openMoneyInstance.renderError(params, e, res);
339
345
  }
340
346
  }
341
347
  if (this.callbacks && typeof this.callbacks.onStart === 'function') {
@@ -381,7 +387,8 @@ class PaymentController {
381
387
  INDUSTRY_TYPE_ID: params['INDUSTRY_TYPE_ID'],
382
388
  CHANNEL_ID: params['CHANNEL_ID'],
383
389
  CALLBACK_URL: params['CALLBACK_URL'],
384
- CHECKSUMHASH: checksum
390
+ CHECKSUMHASH: checksum,
391
+ CLIENT_ID: params['CLIENT_ID'] || txnData.clientId || config.client_id || ''
385
392
  });
386
393
  };
387
394
  if (config.paytm_url) {
@@ -452,6 +459,7 @@ class PaymentController {
452
459
  receipt: user.id + '_' + Date.now()
453
460
  };
454
461
  try {
462
+ const razorPayInstance = this.getProviderInstance('RazorPay', config);
455
463
  const order = await razorPayInstance.orders.create(options);
456
464
  orderId = order.id;
457
465
  await onOrder(orderId);
@@ -492,7 +500,8 @@ class PaymentController {
492
500
  INDUSTRY_TYPE_ID: config.INDUSTRY_TYPE_ID,
493
501
  CHANNEL_ID: config.CHANNEL_ID,
494
502
  CALLBACK_URL: config.CALLBACK_URL,
495
- CHECKSUMHASH: ''
503
+ CHECKSUMHASH: '',
504
+ CLIENT_ID: config.client_id || req.body.CLIENT_ID || ''
496
505
  });
497
506
  }
498
507
  }
@@ -614,8 +623,8 @@ class PaymentController {
614
623
  return objForUpdate;
615
624
  }
616
625
  async callback(req, res) {
617
- const payuInstance = this.payuInstance;
618
- const openMoneyInstance = this.openMoneyInstance;
626
+ const payuInstance = this.getProviderInstance('PayU', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
627
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
619
628
  console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
620
629
  // Normalize common order id and txn id field names (support ORDER_ID, ORDERID, etc.)
621
630
  try {
@@ -658,7 +667,7 @@ class PaymentController {
658
667
  let orderid = req.body.razorpay_order_id || req.query.ORDERID || req.query.order_id;
659
668
  let liveResonse = null;
660
669
  if (orderid) {
661
- liveResonse = await this.razorPayInstance.orders.fetch(orderid).catch(() => null);
670
+ liveResonse = await this.getProviderInstance('Razorpay', config).orders.fetch(orderid).catch(() => null);
662
671
  req.body.extras = liveResonse;
663
672
  }
664
673
  if (req.body.razorpay_payment_id) {
@@ -729,8 +738,8 @@ class PaymentController {
729
738
  async webhook(req, res) {
730
739
  try {
731
740
  let config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
732
- const payuInstance = this.payuInstance;
733
- const openMoneyInstance = this.openMoneyInstance;
741
+ const payuInstance = this.getProviderInstance('PayU', config);
742
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
734
743
  console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
735
744
  console.log("request_data rawBody", req.originalUrl, req.rawBody);
736
745
  console.log("request_headers ", req.originalUrl, JSON.stringify(req.headers));
@@ -814,7 +823,6 @@ class PaymentController {
814
823
  }
815
824
  async createTxn(req, res) {
816
825
  const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
817
- const razorPayInstance = this.razorPayInstance;
818
826
  // mandayory field
819
827
  const requiredFields = ['NAME', 'EMAIL',
820
828
  // 'MOBILE_NO',
@@ -843,6 +851,7 @@ class PaymentController {
843
851
  currency: "INR",
844
852
  receipt: user.id + '_' + Date.now()
845
853
  };
854
+ const razorPayInstance = this.getProviderInstance('Razorpay', config);
846
855
  const order = await razorPayInstance.orders.create(options);
847
856
  id = order.id;
848
857
  }
@@ -882,6 +891,9 @@ class PaymentController {
882
891
  CLIENT_ID: txn.clientId,
883
892
  }), req);
884
893
  txn.payurl = config.host_url + '/' + config.path_prefix + '/init?to=' + urlData64;
894
+ if (txn.clientId) {
895
+ txn.payurl += `&client_id=${txn.clientId}`;
896
+ }
885
897
  res.send(txn);
886
898
  }
887
899
  catch (err) {
@@ -950,9 +962,9 @@ class PaymentController {
950
962
  async status(req, res) {
951
963
  const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
952
964
  const callbacks = this.callbacks;
953
- const payuInstance = this.payuInstance;
954
- const openMoneyInstance = this.openMoneyInstance;
955
- const razorPayInstance = this.razorPayInstance;
965
+ const payuInstance = this.getProviderInstance('PayU', config);
966
+ const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
967
+ const razorPayInstance = this.getProviderInstance('Razorpay', config);
956
968
  if (!req.body.ORDERID && req.query.ORDERID) {
957
969
  req.body.ORDERID = req.query.ORDERID;
958
970
  }
@@ -74,6 +74,7 @@
74
74
  </div>
75
75
 
76
76
  <button id="pay-button" type="submit" class="button">{{BUTTON}}</button>
77
+ <input type="hidden" name="CLIENT_ID" value="{{CLIENT_ID}}" {{readonly}} />
77
78
 
78
79
  <input type="hidden" name="MID" value="{{MID}}" {{readonly}} />
79
80
  <input type="hidden" name="WEBSITE" value="{{WEBSITE}}" {{readonly}} />
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.5.6",
3
+ "version": "7.5.8",
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.6",
3
+ "version": "7.5.8",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",