node-paytmpg 5.1.3 → 5.2.0

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.
@@ -8,7 +8,7 @@ class OpenMoney {
8
8
  npconfig.accesskey = npconfig.KEY
9
9
  npconfig.secretkey = npconfig.SECRET
10
10
  npconfig.url = npconfig.open_money_url
11
- npconfig.script_url = (npconfig.url.indexOf("sandbox") == -1) ? "https://payments.open.money/layer" : "https://sandbox-payments.open.money/layer"
11
+ npconfig.script_url = (npconfig.url && npconfig.url.indexOf("sandbox") == -1) ? "https://payments.open.money/layer" : "https://sandbox-payments.open.money/layer"
12
12
  this.config = npconfig;
13
13
 
14
14
  }
@@ -185,7 +185,7 @@ class OpenMoney {
185
185
  processWebhook(req, res, updateTransaction) {
186
186
  let config = this.config;
187
187
  let events = [
188
- "payment_captured", "payment_pending",
188
+ "payment_captured", "payment_pending",
189
189
  "payment_failed",
190
190
  "payment_cancelled"]
191
191
  if (req.body.event && events.indexOf(req.body.event) > -1) {
@@ -282,11 +282,11 @@ class OpenMoney {
282
282
  })
283
283
  }
284
284
 
285
- renderProcessingPage(params, pmttoken, res) {
285
+ renderProcessingPage(params, pmttoken, res, loadingSVG) {
286
286
  res.writeHead(200, { 'Content-Type': 'text/html' });
287
287
  res.write(`<html><head><title>Merchant Checkout Page</title>
288
288
  <script src="${this.config.script_url}"></script>
289
- </head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${pmttoken.html}<br></center><script>triggerLayer();</script></body></html>`);
289
+ </head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${pmttoken.html}<br><br>${loadingSVG}</center><script>triggerLayer();</script></body></html>`);
290
290
  res.end();
291
291
  }
292
292
 
@@ -511,4 +511,4 @@ function ksort(obj) {
511
511
  }
512
512
 
513
513
 
514
- module.exports = OpenMoney;
514
+ module.exports = OpenMoney;
@@ -10,6 +10,57 @@ const PaytmChecksum = require('./checksum/PaytmChecksum.js');
10
10
  const { stat } = require('fs');
11
11
  const { config } = require('process');
12
12
 
13
+ let loadingSVG = ` <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin:auto;background:#fff;display:block;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
14
+ <g transform="rotate(0 50 50)">
15
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
16
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.9166666666666666s" repeatCount="indefinite"></animate>
17
+ </rect>
18
+ </g><g transform="rotate(30 50 50)">
19
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
20
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.8333333333333334s" repeatCount="indefinite"></animate>
21
+ </rect>
22
+ </g><g transform="rotate(60 50 50)">
23
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
24
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.75s" repeatCount="indefinite"></animate>
25
+ </rect>
26
+ </g><g transform="rotate(90 50 50)">
27
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
28
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.6666666666666666s" repeatCount="indefinite"></animate>
29
+ </rect>
30
+ </g><g transform="rotate(120 50 50)">
31
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
32
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5833333333333334s" repeatCount="indefinite"></animate>
33
+ </rect>
34
+ </g><g transform="rotate(150 50 50)">
35
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
36
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5s" repeatCount="indefinite"></animate>
37
+ </rect>
38
+ </g><g transform="rotate(180 50 50)">
39
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
40
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.4166666666666667s" repeatCount="indefinite"></animate>
41
+ </rect>
42
+ </g><g transform="rotate(210 50 50)">
43
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
44
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.3333333333333333s" repeatCount="indefinite"></animate>
45
+ </rect>
46
+ </g><g transform="rotate(240 50 50)">
47
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
48
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.25s" repeatCount="indefinite"></animate>
49
+ </rect>
50
+ </g><g transform="rotate(270 50 50)">
51
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
52
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.16666666666666666s" repeatCount="indefinite"></animate>
53
+ </rect>
54
+ </g><g transform="rotate(300 50 50)">
55
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
56
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.08333333333333333s" repeatCount="indefinite"></animate>
57
+ </rect>
58
+ </g><g transform="rotate(330 50 50)">
59
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
60
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animate>
61
+ </rect>
62
+ </g>
63
+ </svg>`
13
64
 
14
65
  function sanitizeRequest(body) {
15
66
 
@@ -165,6 +216,18 @@ module.exports = function (app, callbacks) {
165
216
  body.body.resultInfo &&
166
217
  body.body.resultInfo.resultStatus == "S") {
167
218
 
219
+ let paytmJsToken = {}
220
+ paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
221
+ paytmJsToken.ORDERID = params['ORDER_ID']
222
+ paytmJsToken.ORDER_ID = params['ORDER_ID']
223
+ paytmJsToken.CANCELLED = "cancelled"
224
+ paytmJsToken.TOKEN = body.body.txnToken
225
+ paytmJsToken.TXN_AMOUNT = params['TXN_AMOUNT']
226
+ paytmJsToken.MID = params['MID']
227
+ paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
228
+ paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
229
+
230
+
168
231
 
169
232
  let paytmJsCheckouHtml = `<html>
170
233
  <head>
@@ -175,57 +238,7 @@ module.exports = function (app, callbacks) {
175
238
  <body>
176
239
  <center>
177
240
  <h1>Please donot close this page or press the back button. Processing...</h1>
178
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin:auto;background:#fff;display:block;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
179
- <g transform="rotate(0 50 50)">
180
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
181
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.9166666666666666s" repeatCount="indefinite"></animate>
182
- </rect>
183
- </g><g transform="rotate(30 50 50)">
184
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
185
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.8333333333333334s" repeatCount="indefinite"></animate>
186
- </rect>
187
- </g><g transform="rotate(60 50 50)">
188
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
189
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.75s" repeatCount="indefinite"></animate>
190
- </rect>
191
- </g><g transform="rotate(90 50 50)">
192
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
193
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.6666666666666666s" repeatCount="indefinite"></animate>
194
- </rect>
195
- </g><g transform="rotate(120 50 50)">
196
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
197
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5833333333333334s" repeatCount="indefinite"></animate>
198
- </rect>
199
- </g><g transform="rotate(150 50 50)">
200
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
201
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5s" repeatCount="indefinite"></animate>
202
- </rect>
203
- </g><g transform="rotate(180 50 50)">
204
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
205
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.4166666666666667s" repeatCount="indefinite"></animate>
206
- </rect>
207
- </g><g transform="rotate(210 50 50)">
208
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
209
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.3333333333333333s" repeatCount="indefinite"></animate>
210
- </rect>
211
- </g><g transform="rotate(240 50 50)">
212
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
213
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.25s" repeatCount="indefinite"></animate>
214
- </rect>
215
- </g><g transform="rotate(270 50 50)">
216
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
217
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.16666666666666666s" repeatCount="indefinite"></animate>
218
- </rect>
219
- </g><g transform="rotate(300 50 50)">
220
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
221
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.08333333333333333s" repeatCount="indefinite"></animate>
222
- </rect>
223
- </g><g transform="rotate(330 50 50)">
224
- <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
225
- <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animate>
226
- </rect>
227
- </g>
228
- </svg>
241
+ ${loadingSVG}
229
242
  </center>
230
243
  <form id="cancelform" action="${params['CALLBACK_URL']}" method="post">
231
244
  <input type="hidden" name="TXNID" value="na"/>
@@ -323,6 +336,9 @@ module.exports = function (app, callbacks) {
323
336
 
324
337
  </body>
325
338
  </html>`
339
+ if (res.token) {
340
+ res.token(paytmJsToken)
341
+ }
326
342
  return res.send(paytmJsCheckouHtml)
327
343
 
328
344
  }
@@ -340,7 +356,9 @@ module.exports = function (app, callbacks) {
340
356
  form_fields += "<input type='hidden' name='" + x + "' value='" + errorResp[x] + "' >";
341
357
  }
342
358
  form_fields += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "' >";
343
-
359
+ if (res.token) {
360
+ res.token(undefined)
361
+ }
344
362
  res.writeHead(200, { 'Content-Type': 'text/html' });
345
363
  res.write(`<html>
346
364
 
@@ -404,14 +422,14 @@ module.exports = function (app, callbacks) {
404
422
  </script>`;
405
423
 
406
424
  res.writeHead(200, { 'Content-Type': 'text/html' });
407
- res.write(`<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${html}<br>${fail}</center></body></html>`);
425
+ res.write(`<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${html}<br>${fail}<br>${loadingSVG}</center></body></html>`);
408
426
  res.end();
409
427
 
410
428
  }
411
429
  else if (config.open_money_url) {
412
430
  try {
413
431
  let pmttoken = await openMoneyInstance.generatePaymentToken(params);
414
- openMoneyInstance.renderProcessingPage(params, pmttoken, res);
432
+ openMoneyInstance.renderProcessingPage(params, pmttoken, res, loadingSVG);
415
433
 
416
434
  var myquery = { orderId: params['ORDER_ID'] };
417
435
  Transaction.findOne(myquery, function (err, objForUpdate) {
@@ -794,7 +812,7 @@ module.exports = function (app, callbacks) {
794
812
  let order = await razorPayInstance.orders.create(options);
795
813
  id = order.id;
796
814
  }
797
- else if(config.open_money_url){
815
+ else if (config.open_money_url) {
798
816
  id = "pay_" + makeid(config.id_length || IDLEN)
799
817
  }
800
818
 
@@ -837,6 +855,66 @@ module.exports = function (app, callbacks) {
837
855
 
838
856
 
839
857
 
858
+ };
859
+
860
+ module.createTxnToken = (req, res) => {
861
+
862
+
863
+ module.createTxn(req, {
864
+ send: function (createTxnResult) {
865
+
866
+ // console.log(createTxnResult)
867
+
868
+ req.body.NAME = createTxnResult.name
869
+ req.body.EMAIL = createTxnResult.email
870
+ req.body.MOBILE_NO = createTxnResult.phone
871
+ req.body.ORDER_ID = createTxnResult.orderId
872
+ module.init(req, {
873
+ render: (renderPath, initResultRender) => {
874
+ // console.log(initResultRender)
875
+ req.body = initResultRender
876
+
877
+ module.init(req, {
878
+ send: (initResult) => {
879
+
880
+ },
881
+ status: (status) => {
882
+ console.log('status', status)
883
+
884
+ },
885
+ token: (tokenData) => {
886
+ if (!tokenData) {
887
+ res.status(500)
888
+ res.send('Something went wrong. Please try again later.')
889
+ }
890
+ else
891
+ {
892
+ tokenData.payurl = createTxnResult.payurl;
893
+ res.send(tokenData)
894
+ }
895
+ },
896
+ render: (renderPath2, init2ResultRender) => {
897
+ console.log('init2ResultRender', init2ResultRender)
898
+ },
899
+ end: (initResultWrite) => {
900
+ console.log('initResultWrite', initResultWrite)
901
+ },
902
+ write: (initResultWrite) => {
903
+ console.log('initResultWrite', initResultWrite)
904
+ },
905
+ writeHead: (initResultWriteHead) => {
906
+ console.log('initResultWriteHead', initResultWriteHead)
907
+ }
908
+
909
+ })
910
+
911
+ }
912
+ })
913
+ },
914
+ redirect: res.redirect
915
+ })
916
+
917
+
840
918
  };
841
919
 
842
920
 
@@ -65,6 +65,7 @@ module.exports = (app, express, callbacks) => {
65
65
  router.all('/callback', pc.callback)
66
66
  router.all('/api/webhook', pc.webhook)
67
67
  router.all('/api/status', pc.status)
68
+ router.all('/api/createTxn/token', pc.createTxnToken)
68
69
  router.all('/api/createTxn', pc.createTxn)
69
70
 
70
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "5.1.3",
3
+ "version": "5.2.0",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {