node-paytmpg 5.3.0 → 5.3.2
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/.github/workflows/codeql-analysis.yml +71 -71
- package/.github/workflows/nodejs.yml +24 -24
- package/.github/workflows/npm-publish.yml +23 -23
- package/Dockerfile +8 -8
- package/LICENSE +674 -674
- package/README.MD +245 -245
- package/app/controllers/adapters/open_money.js +515 -514
- package/app/controllers/checksum/checksum.js +154 -154
- package/app/controllers/checksum/crypt.js +98 -98
- package/app/controllers/checksum/server.js +132 -132
- package/app/controllers/np_user.controller.js +79 -79
- package/app/controllers/payment_controller.js +1067 -1067
- package/app/models/np_multidbplugin.js +101 -101
- package/app/models/np_transaction.model.js +16 -16
- package/app/models/np_user.model.js +11 -11
- package/app/routes/payment_route.js +73 -73
- package/app/views/home.hbs +21 -21
- package/app/views/init.hbs +92 -92
- package/app/views/layouts/index.hbs +57 -57
- package/app/views/result.hbs +49 -49
- package/app.yaml +18 -18
- package/example.js +51 -51
- package/index.js +23 -23
- package/package.json +42 -41
- package/public/css/style.css +268 -268
- package/public/js/index.js +282 -282
- package/public/layer_checkout.js +38 -38
- package/public/test.html +24 -24
|
@@ -1,514 +1,515 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
npconfig.
|
|
10
|
-
npconfig.
|
|
11
|
-
npconfig.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
config.
|
|
32
|
-
config.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
html
|
|
70
|
-
html += "<input type='hidden' name='
|
|
71
|
-
html += "<input type='hidden' name='
|
|
72
|
-
html += "<input type='hidden'
|
|
73
|
-
html += "<input type='hidden' id='
|
|
74
|
-
html += "<input type='hidden' name='
|
|
75
|
-
html += "<
|
|
76
|
-
html += "
|
|
77
|
-
html += "
|
|
78
|
-
html +=
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
var
|
|
103
|
-
var
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
'
|
|
123
|
-
'
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
status
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
"
|
|
190
|
-
"
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let
|
|
196
|
-
let
|
|
197
|
-
let
|
|
198
|
-
let
|
|
199
|
-
let
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
// '
|
|
207
|
-
// '
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
req.body.
|
|
217
|
-
req.body.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
req.body.
|
|
224
|
-
req.body.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
status
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
req.body.
|
|
254
|
-
req.body.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
res.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
res.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
res.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
res.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
<
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
'
|
|
340
|
-
'
|
|
341
|
-
'
|
|
342
|
-
'
|
|
343
|
-
'
|
|
344
|
-
'
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
'
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
resp.
|
|
436
|
-
|
|
437
|
-
var
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
})
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
cryp.
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
var crypto = require('crypto');
|
|
3
|
+
const { resolve } = require('path');
|
|
4
|
+
var reqpost = require('request');
|
|
5
|
+
|
|
6
|
+
class OpenMoney {
|
|
7
|
+
config
|
|
8
|
+
constructor(npconfig) {
|
|
9
|
+
npconfig.accesskey = npconfig.KEY
|
|
10
|
+
npconfig.secretkey = npconfig.SECRET
|
|
11
|
+
npconfig.url = npconfig.open_money_url
|
|
12
|
+
npconfig.script_url = (npconfig.url && npconfig.url.indexOf("sandbox") == -1) ? "https://payments.open.money/layer" : "https://sandbox-payments.open.money/layer"
|
|
13
|
+
this.config = npconfig;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
generatePaymentToken(params) {
|
|
18
|
+
|
|
19
|
+
let config = this.config;
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var payment_token_data;
|
|
22
|
+
let open_txn = {
|
|
23
|
+
"amount": params['TXN_AMOUNT'],
|
|
24
|
+
"currency": params['CURRENCY'] || "INR",
|
|
25
|
+
"name": params['NAME'],
|
|
26
|
+
"email_id": params['EMAIL'],
|
|
27
|
+
"contact_number": ("" + params['MOBILE_NO']).replace("+91", ""),
|
|
28
|
+
"mtx": params['ORDER_ID']
|
|
29
|
+
}
|
|
30
|
+
create_payment_token(open_txn,
|
|
31
|
+
config.accesskey,
|
|
32
|
+
config.secretkey,
|
|
33
|
+
config.url, function (layer_payment_token_data) {
|
|
34
|
+
/*Object.keys(layer_payment_token_data).forEach(function(key) {
|
|
35
|
+
console.log(key + layer_payment_token_data[key]);
|
|
36
|
+
});*/
|
|
37
|
+
|
|
38
|
+
if (typeof layer_payment_token_data['error'] != 'undefined')
|
|
39
|
+
return reject(JSON.stringify('E55 Payment error. ' + layer_payment_token_data['error']));
|
|
40
|
+
|
|
41
|
+
if (typeof layer_payment_token_data["id"] == 'undefined' || !layer_payment_token_data["id"])
|
|
42
|
+
return reject(JSON.stringify('Payment error. ' + 'Layer token ID cannot be empty.'));
|
|
43
|
+
|
|
44
|
+
if (typeof layer_payment_token_data["id"] != 'undefined') {
|
|
45
|
+
|
|
46
|
+
get_payment_token(layer_payment_token_data["id"], config.accesskey, config.secretkey, config.url, function (payment_token_data) {
|
|
47
|
+
|
|
48
|
+
if (payment_token_data.error) {
|
|
49
|
+
return reject({
|
|
50
|
+
error: payment_token_data.error
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
payment_token_data = JSON.parse(payment_token_data);
|
|
54
|
+
|
|
55
|
+
if (typeof payment_token_data['error'] != 'undefined')
|
|
56
|
+
return reject({ error: (JSON.stringify('E56 Payment error. ' + payment_token_data['error'])) })
|
|
57
|
+
if (typeof payment_token_data['status'] != 'undefined' && payment_token_data['status'] == "paid")
|
|
58
|
+
return reject({ error: (JSON.stringify("Layer: this order has already been paid.")) })
|
|
59
|
+
if (parseFloat(payment_token_data['amount']) != parseFloat(params['TXN_AMOUNT']))
|
|
60
|
+
return reject({ error: (JSON.stringify("Layer: an amount mismatch occurred.")) })
|
|
61
|
+
|
|
62
|
+
var hash = create_hash({
|
|
63
|
+
'layer_pay_token_id': payment_token_data['id'],
|
|
64
|
+
'layer_order_amount': payment_token_data['amount'],
|
|
65
|
+
'tranid': params['ORDER_ID'],
|
|
66
|
+
}, config.accesskey, config.secretkey);
|
|
67
|
+
params['CHECKSUM'] = hash;
|
|
68
|
+
|
|
69
|
+
var html = `<form action='${params['CALLBACK_URL']}' method='post' style='display: none' name='layer_payment_int_form'>`;
|
|
70
|
+
html += "<input type='hidden' name='layer_pay_token_id' value='" + payment_token_data['id'] + "'>";
|
|
71
|
+
html += "<input type='hidden' name='tranid' value='" + params['ORDER_ID'] + "'>";
|
|
72
|
+
html += "<input type='hidden' name='layer_order_amount' value='" + payment_token_data['amount'] + "'>";
|
|
73
|
+
html += "<input type='hidden' id='layer_payment_id' name='layer_payment_id' value=''>";
|
|
74
|
+
html += "<input type='hidden' id='fallback_url' name='fallback_url' value=''>";
|
|
75
|
+
html += "<input type='hidden' name='hash' value='" + hash + "'></form>";
|
|
76
|
+
html += "<script>";
|
|
77
|
+
html += "var layer_params = {payment_token_id:'" + payment_token_data['id'] + "',accesskey:'" + config.accesskey + "'};";
|
|
78
|
+
html += "</script>";
|
|
79
|
+
html += `<script src="layer_checkout.js"></script>`;
|
|
80
|
+
|
|
81
|
+
return resolve({
|
|
82
|
+
html: html,
|
|
83
|
+
params: params,
|
|
84
|
+
data: config,
|
|
85
|
+
tokenid: payment_token_data['id'],
|
|
86
|
+
amount: payment_token_data['amount'],
|
|
87
|
+
hash: hash
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
verifyResult(req) {
|
|
96
|
+
let config = this.config;
|
|
97
|
+
return new Promise((resolve, reje) => {
|
|
98
|
+
|
|
99
|
+
var txnid = "";
|
|
100
|
+
var amount = "";
|
|
101
|
+
var status = "";
|
|
102
|
+
var msg = "";
|
|
103
|
+
var tokenid = "";
|
|
104
|
+
var paymentid = "";
|
|
105
|
+
var payment_data = {};
|
|
106
|
+
|
|
107
|
+
if (!req.body.layer_payment_id) {
|
|
108
|
+
return resolve({
|
|
109
|
+
STATUS: 'TXN_FAILURE',
|
|
110
|
+
ORDERID: txnid,
|
|
111
|
+
TXNID: paymentid,
|
|
112
|
+
reason: 'invalid response'
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
txnid = req.body.tranid;
|
|
117
|
+
amount = req.body.layer_order_amount;
|
|
118
|
+
tokenid = req.body.layer_pay_token_id;
|
|
119
|
+
paymentid = req.body.layer_payment_id;
|
|
120
|
+
}
|
|
121
|
+
var data = {
|
|
122
|
+
'layer_pay_token_id': tokenid,
|
|
123
|
+
'layer_order_amount': amount,
|
|
124
|
+
'tranid': txnid,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (verify_hash(data, req.body.hash, config.accesskey, config.secretkey, config.url)) {
|
|
128
|
+
get_payment_details(paymentid, config.accesskey, config.secretkey, config.url, function (response) {
|
|
129
|
+
if (response === "{}") {
|
|
130
|
+
|
|
131
|
+
return resolve({
|
|
132
|
+
STATUS: 'TXN_FAILURE',
|
|
133
|
+
ORDERID: txnid,
|
|
134
|
+
TXNID: paymentid,
|
|
135
|
+
message: 'Invalid Response',
|
|
136
|
+
data: payment_data
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
payment_data = JSON.parse(response);
|
|
142
|
+
if (!payment_data['payment_token'] || payment_data['payment_token']['id'] != tokenid) {
|
|
143
|
+
return resolve({
|
|
144
|
+
STATUS: 'TXN_FAILURE',
|
|
145
|
+
ORDERID: txnid,
|
|
146
|
+
TXNID: paymentid,
|
|
147
|
+
message: 'received layer_pay_token_id and collected layer_pay_token_id doesnt match',
|
|
148
|
+
data: payment_data
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
let status = ""
|
|
153
|
+
if (payment_data.status == "captured" ||
|
|
154
|
+
payment_data.status == "late_authorized") {
|
|
155
|
+
status = 'TXN_SUCCESS'
|
|
156
|
+
}
|
|
157
|
+
else if (payment_data.status == "pending") {
|
|
158
|
+
status = 'TXN_PENDING'
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
status = 'TXN_FAILURE'
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return resolve({
|
|
165
|
+
STATUS: status,
|
|
166
|
+
ORDERID: txnid,
|
|
167
|
+
TXNID: paymentid,
|
|
168
|
+
data: (payment_data)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
return resolve({
|
|
177
|
+
STATUS: 'TXN_FAILURE',
|
|
178
|
+
ORDERID: txnid,
|
|
179
|
+
TXNID: paymentid,
|
|
180
|
+
message: 'Invalid Response'
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
processWebhook(req, res, updateTransaction) {
|
|
187
|
+
let config = this.config;
|
|
188
|
+
let events = [
|
|
189
|
+
"payment_captured", "payment_pending",
|
|
190
|
+
"payment_failed",
|
|
191
|
+
"payment_cancelled"]
|
|
192
|
+
if (req.body.event && events.indexOf(req.body.event) > -1) {
|
|
193
|
+
if (req.body.payment_token) {
|
|
194
|
+
|
|
195
|
+
let payment_token = req.body.payment_token;
|
|
196
|
+
let orderId = payment_token.mtx
|
|
197
|
+
let paymentid = req.body.id
|
|
198
|
+
let tokenid = payment_token.id
|
|
199
|
+
let payment_data = {}
|
|
200
|
+
let amount = req.body.amount;
|
|
201
|
+
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
|
|
204
|
+
req.body.layer_pay_token_id = tokenid;
|
|
205
|
+
// var data = {
|
|
206
|
+
// 'layer_pay_token_id': tokenid,
|
|
207
|
+
// 'layer_order_amount': amount,
|
|
208
|
+
// 'tranid': orderId,
|
|
209
|
+
// };
|
|
210
|
+
|
|
211
|
+
// if (verify_hash(data, req.headers['x-webhook-signature'], config.accesskey, config.secretkey, config.url)) {
|
|
212
|
+
// console.log('TODO verify signature')
|
|
213
|
+
// }
|
|
214
|
+
get_payment_details(paymentid, config.accesskey, config.secretkey, config.url, function (response) {
|
|
215
|
+
if (response === "{}") {
|
|
216
|
+
req.body.STATUS = 'TXN_FAILURE';
|
|
217
|
+
req.body.ORDERID = orderId;
|
|
218
|
+
req.body.TXNID = paymentid;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
payment_data = JSON.parse(response);
|
|
222
|
+
if (!payment_data['payment_token'] || payment_data['payment_token']['id'] != tokenid) {
|
|
223
|
+
req.body.STATUS = 'TXN_FAILURE';
|
|
224
|
+
req.body.ORDERID = orderId;
|
|
225
|
+
req.body.TXNID = paymentid;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
let status = "INITIATED"
|
|
229
|
+
if (payment_data.status == "captured" ||
|
|
230
|
+
payment_data.status == "late_authorized") {
|
|
231
|
+
status = 'TXN_SUCCESS'
|
|
232
|
+
}
|
|
233
|
+
else if (payment_data.status == "pending") {
|
|
234
|
+
status = 'TXN_PENDING'
|
|
235
|
+
}
|
|
236
|
+
// else {
|
|
237
|
+
// status = 'TXN_FAILURE'
|
|
238
|
+
// }
|
|
239
|
+
|
|
240
|
+
if (status != 'TXN_SUCCESS') {
|
|
241
|
+
if (req.body.status == "paid" || req.body.status == 'captured') {
|
|
242
|
+
status = 'TXN_SUCCESS'
|
|
243
|
+
}
|
|
244
|
+
// else if (req.body.status == 'failed') {
|
|
245
|
+
// status = 'TXN_FAILURE'
|
|
246
|
+
// }
|
|
247
|
+
else if (req.body.status == 'pending') {
|
|
248
|
+
status = 'TXN_PENDING'
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
console.log(`Open Money ${req.body.event} webhook for order=${payment_token.mtx} payid=${paymentid} status=${req.body.status} || ${status}`)
|
|
252
|
+
|
|
253
|
+
req.body.STATUS = status;
|
|
254
|
+
req.body.ORDERID = orderId;
|
|
255
|
+
req.body.TXNID = paymentid;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
updateTransaction(req, res)
|
|
260
|
+
|
|
261
|
+
});
|
|
262
|
+
}, 3000)
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
res.status(401)
|
|
266
|
+
res.send({ message: "Missing payment_token" })
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
res.status(201)
|
|
271
|
+
res.send({ message: "Webhook not supported" })
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
getPaymentStatus(paymentTokenId, cb) {
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
get_payment_token_details(paymentTokenId, this.config.accesskey, this.config.secretkey, this.config.url, (data) => {
|
|
278
|
+
resolve(data)
|
|
279
|
+
if (cb) {
|
|
280
|
+
cb(data)
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
renderProcessingPage(params, pmttoken, res, loadingSVG) {
|
|
287
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
288
|
+
res.write(`<html><head><title>Merchant Checkout Page</title>
|
|
289
|
+
<script src="${this.config.script_url}"></script>
|
|
290
|
+
</head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${pmttoken.html}<br><br>${loadingSVG}</center><script>triggerLayer();</script></body></html>`);
|
|
291
|
+
res.end();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
renderError(params, error, res) {
|
|
295
|
+
|
|
296
|
+
console.log('ERROR:::', error, '\n');
|
|
297
|
+
res.status(500)
|
|
298
|
+
var form_fields = "";
|
|
299
|
+
let errorResp = {
|
|
300
|
+
TXNID: "na",
|
|
301
|
+
STATUS: "TXN_FAILURE",
|
|
302
|
+
CANCELLED: "cancelled",
|
|
303
|
+
ORDERID: params["ORDER_ID"]
|
|
304
|
+
}
|
|
305
|
+
for (var x in errorResp) {
|
|
306
|
+
form_fields += "<input type='hidden' name='" + x + "' value='" + errorResp[x] + "' >";
|
|
307
|
+
}
|
|
308
|
+
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='" + params["CHECKSUM"] + "' >";
|
|
309
|
+
|
|
310
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
311
|
+
res.write(`<html>
|
|
312
|
+
|
|
313
|
+
<head>
|
|
314
|
+
<title>Merchant Checkout Error</title>
|
|
315
|
+
</head>
|
|
316
|
+
|
|
317
|
+
<body>
|
|
318
|
+
<center>
|
|
319
|
+
<h1>Something went wrong. Please wait you will be redirected automatically...</h1>
|
|
320
|
+
</center>
|
|
321
|
+
<form method="post" action="${params['CALLBACK_URL']}" name="f1">${form_fields}</form>
|
|
322
|
+
<script type="text/javascript">document.f1.submit();</script>
|
|
323
|
+
</body>
|
|
324
|
+
|
|
325
|
+
</html>`);
|
|
326
|
+
res.end();
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
//Layer functions
|
|
336
|
+
function create_payment_token(data, accesskey, secretkey, baseurl, callback) {
|
|
337
|
+
try {
|
|
338
|
+
var pay_token_request_data = {
|
|
339
|
+
'amount': (data['amount']) ? data['amount'] : null,
|
|
340
|
+
'currency': (data['currency']) ? data['currency'] : null,
|
|
341
|
+
'name': (data['name']) ? data['name'] : null,
|
|
342
|
+
'email_id': (data['email_id']) ? data['email_id'] : null,
|
|
343
|
+
'contact_number': (data['contact_number']) ? data['contact_number'] : null,
|
|
344
|
+
'mtx': (data['mtx']) ? data['mtx'] : null,
|
|
345
|
+
'udf': (data['udf']) ? data['udf'] : null,
|
|
346
|
+
};
|
|
347
|
+
http_post(pay_token_request_data, "payment_token", accesskey, secretkey, baseurl, function (response) {
|
|
348
|
+
return callback(response);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
} catch (e) {
|
|
352
|
+
return callback({
|
|
353
|
+
'error': e
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function get_payment_token(payment_token_id, accesskey, secretkey, url, callback) {
|
|
359
|
+
if (!payment_token_id) {
|
|
360
|
+
throw new Error("payment_token_id cannot be empty");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
http_get("payment_token/" + payment_token_id, accesskey, secretkey, url, function (response) {
|
|
365
|
+
return callback(response);
|
|
366
|
+
});
|
|
367
|
+
} catch (e) {
|
|
368
|
+
return callback({
|
|
369
|
+
'error': e
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function get_payment_token_details(payment_tokenid, accesskey, secretkey, baseurl, callback) {
|
|
375
|
+
|
|
376
|
+
if (!payment_tokenid) {
|
|
377
|
+
throw new Error("payment_id cannot be empty");
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
http_get("payment_token/" + payment_tokenid + '/payment', accesskey, secretkey, baseurl, function (response) {
|
|
381
|
+
return callback(response);
|
|
382
|
+
});
|
|
383
|
+
} catch (e) {
|
|
384
|
+
callback({
|
|
385
|
+
'error': e
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function get_payment_details(payment_id, accesskey, secretkey, baseurl, callback) {
|
|
391
|
+
|
|
392
|
+
if (!payment_id) {
|
|
393
|
+
throw new Error("payment_id cannot be empty");
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
http_get("payment/" + payment_id, accesskey, secretkey, baseurl, function (response) {
|
|
397
|
+
return callback(response);
|
|
398
|
+
});
|
|
399
|
+
} catch (e) {
|
|
400
|
+
callback({
|
|
401
|
+
'error': e
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function http_post(data, route, accesskey, secretkey, baseurl, callback) {
|
|
407
|
+
Object.keys(data).forEach(function (key) {
|
|
408
|
+
if (data[key] === null)
|
|
409
|
+
delete data[key];
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
var url = baseurl + "/" + route;
|
|
413
|
+
|
|
414
|
+
var options = {
|
|
415
|
+
method: 'POST',
|
|
416
|
+
uri: url,
|
|
417
|
+
json: true,
|
|
418
|
+
form: {
|
|
419
|
+
amount: data['amount'],
|
|
420
|
+
currency: data['currency'],
|
|
421
|
+
name: data['name'],
|
|
422
|
+
email_id: data['email_id'],
|
|
423
|
+
contact_number: data['contact_number'],
|
|
424
|
+
mtx: data['mtx']
|
|
425
|
+
},
|
|
426
|
+
headers: {
|
|
427
|
+
'Content-Type': 'application/json',
|
|
428
|
+
'Authorization': 'Bearer ' + accesskey + ':' + secretkey
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
reqpost(options)
|
|
433
|
+
.on('response', function (resp) {
|
|
434
|
+
//console.log('STATUS:'+resp.statusCode);
|
|
435
|
+
resp.setEncoding('utf8');
|
|
436
|
+
resp.on('data', function (chunk) {
|
|
437
|
+
var data = JSON.parse(chunk);
|
|
438
|
+
var rdata = "";
|
|
439
|
+
if ("error" in data) {
|
|
440
|
+
Object.keys(data).forEach(function (key) {
|
|
441
|
+
if (key == "error_data") {
|
|
442
|
+
var obj = data[key];
|
|
443
|
+
Object.keys(obj).forEach(function (k) {
|
|
444
|
+
rdata += obj[k] + ' ';
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
return callback({ "error": rdata });
|
|
449
|
+
}
|
|
450
|
+
else
|
|
451
|
+
return callback(data);
|
|
452
|
+
|
|
453
|
+
});
|
|
454
|
+
})
|
|
455
|
+
.on('error', function (err) {
|
|
456
|
+
return callback(err);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function http_get(route, accesskey, secretkey, baseurl, callback) {
|
|
461
|
+
|
|
462
|
+
var url = baseurl + "/" + route;
|
|
463
|
+
|
|
464
|
+
var options = {
|
|
465
|
+
method: 'GET',
|
|
466
|
+
uri: url,
|
|
467
|
+
url: url,
|
|
468
|
+
headers: {
|
|
469
|
+
'Content-Type': 'application/json',
|
|
470
|
+
'Authorization': 'Bearer ' + accesskey + ':' + secretkey
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// console.log('Axios Calling API: ' + url)
|
|
475
|
+
axios(options).then((d) => {
|
|
476
|
+
// console.log('Axios Response API: ' + url + " >>> " + JSON.stringify(d.data))
|
|
477
|
+
|
|
478
|
+
callback(JSON.stringify(d.data))
|
|
479
|
+
}).catch((e) => {
|
|
480
|
+
// console.log('Axios Response API Error. ' + url + " >>> " + e.message)
|
|
481
|
+
callback("{}")
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function create_hash(data, accesskey, secretkey) {
|
|
486
|
+
data = ksort(data);
|
|
487
|
+
hash_string = accesskey;
|
|
488
|
+
Object.keys(data).forEach(function (key) {
|
|
489
|
+
hash_string += '|' + data[key];
|
|
490
|
+
});
|
|
491
|
+
var cryp = crypto.createHash('sha256', secretkey);
|
|
492
|
+
cryp.update(hash_string);
|
|
493
|
+
return cryp.digest('hex');
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function verify_hash(data, rec_hash, accesskey, secretkey) {
|
|
497
|
+
var gen_hash = create_hash(data, accesskey, secretkey);
|
|
498
|
+
if (gen_hash === rec_hash) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function ksort(obj) {
|
|
505
|
+
var keys = Object.keys(obj).sort(), sortedObj = {};
|
|
506
|
+
|
|
507
|
+
for (var i in keys) {
|
|
508
|
+
sortedObj[keys[i]] = obj[keys[i]];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return sortedObj;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
module.exports = OpenMoney;
|