Commit 525f0bf55315df0ec15350061358433ac71824ec
1 parent
5eccae0555
Exists in
master
Snapshot to test
Showing 5 changed files with 103 additions and 4 deletions Side-by-side Diff
config.sample.json
... | ... | @@ -0,0 +1,37 @@ |
1 | +{ | |
2 | + "handler_name": "KOMODO-GW-HTTPGETX", | |
3 | + "partner": { | |
4 | + "url": "http://PLEASE_CHANGE_ME:25614", | |
5 | + "terminal_name": "PLEASE_CHANGE_ME", | |
6 | + "password": "PLEASE_CHANGE_ME", | |
7 | + "dump_request": true, | |
8 | + "callback": { | |
9 | + "port": 14000, | |
10 | + "url": "http://PLEASE_CHANGE_ME:14000", | |
11 | + "apikey": [ | |
12 | + "PLEASE_CHANGE_ME" | |
13 | + ], | |
14 | + "dump_request": true | |
15 | + } | |
16 | + }, | |
17 | + "control_panel": { | |
18 | + "listen_port": 16101, | |
19 | + "url": "http://localhost:16101/" | |
20 | + }, | |
21 | + "apiserver": { | |
22 | + "port": 16102, | |
23 | + "apikey": "PLEASE_CHANGE_ME", | |
24 | + "url": "http://localhost:16102/apikey/PLEASE_CHANGE_ME" | |
25 | + }, | |
26 | + "push_server": { | |
27 | + "apikey": "PLEASE_CHANGE_ME", | |
28 | + "advice": { | |
29 | + "port": 16103, | |
30 | + "url": "http://localhost:16103/apikey/PLEASE_CHANGE_ME/advice" | |
31 | + } | |
32 | + }, | |
33 | + "products": [ | |
34 | + ], | |
35 | + "remote_products": {}, | |
36 | + "do_not_verbose_log_report": true | |
37 | +} | |
0 | 38 | \ No newline at end of file |
lib/callback/handler-postpaid.js
... | ... | @@ -0,0 +1,59 @@ |
1 | +const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID'; | |
2 | + | |
3 | +const logger = require('komodo-sdk/logger'); | |
4 | +const report = require('../report/postpaid'); | |
5 | +const getFromReq = require('../get-from-params-body-qs'); | |
6 | +const translateRc = require('../translate-rc'); | |
7 | + | |
8 | +module.exports = (req, res) => { | |
9 | + const { xid } = res.locals; | |
10 | + res.json({ | |
11 | + status: 'OK', | |
12 | + error: null, | |
13 | + ts: new Date(), | |
14 | + xid, | |
15 | + }); | |
16 | + | |
17 | + const reportCommand = getFromReq(req, 'command'); | |
18 | + if (!reportCommand) { | |
19 | + logger.warn(`${MODULE_NAME} C7A4A26C: Unknown command`, { xid }); | |
20 | + return; | |
21 | + } | |
22 | + | |
23 | + const isInquiry = reportCommand === 'INQUIRY'; | |
24 | + | |
25 | + const rcFromRequest = getFromReq(req, 'rc'); | |
26 | + const translatedRc = rcFromRequest && (translateRc[rcFromRequest] || rcFromRequest); | |
27 | + logger.verbose(`${MODULE_NAME} 475DA596: RC translated`, { | |
28 | + xid, | |
29 | + reportCommand, | |
30 | + rcFromRequest, | |
31 | + translatedRc, | |
32 | + }); | |
33 | + | |
34 | + report(xid, { | |
35 | + command: reportCommand, | |
36 | + trx_id: getFromReq(req, 'request_id'), | |
37 | + rc: translatedRc | |
38 | + || (isInquiry && '90') | |
39 | + || '68', | |
40 | + sn: getFromReq(req, 'sn'), | |
41 | + amount: Number(getFromReq(req, 'amount')) || undefined, | |
42 | + balance: Number(getFromReq(req, 'ending_balance')) || undefined, | |
43 | + | |
44 | + amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge'))) | |
45 | + || undefined, | |
46 | + bill_count: Number(getFromReq(req, 'bill_count')) || undefined, | |
47 | + base_bill_amount: Number(getFromReq(req, 'base_bill_amount')) || undefined, | |
48 | + | |
49 | + message: { | |
50 | + xid, | |
51 | + CALLBACK: { | |
52 | + ip: req.ip, | |
53 | + method: req.method, | |
54 | + body: req.body, | |
55 | + qs: req.query, | |
56 | + }, | |
57 | + }, | |
58 | + }); | |
59 | +}; |
lib/callback/index.js
... | ... | @@ -13,6 +13,7 @@ const rfs = require('rotating-file-stream'); |
13 | 13 | const dumper = require('./dumper'); |
14 | 14 | const apikeyChecker = require('./apikey-checker'); |
15 | 15 | const handlerPrepaid = require('./handler-prepaid'); |
16 | +const handlerPostpaid = require('./handler-postpaid'); | |
16 | 17 | |
17 | 18 | const baseFileName = 'logs/callback_access_log'; |
18 | 19 | |
... | ... | @@ -75,6 +76,8 @@ app.use('/apikey/:apikey', express.json()); |
75 | 76 | |
76 | 77 | app.use('/apikey/:apikey', dumper); |
77 | 78 | app.use('/apikey/:apikey/prepaid', handlerPrepaid); |
79 | +app.use('/apikey/:apikey/TOPUP', handlerPrepaid); | |
80 | +app.use('/apikey/:apikey/:hitType', handlerPostpaid); | |
78 | 81 | |
79 | 82 | app |
80 | 83 | .listen(listenPort, () => { |
lib/hit/compose-callback-url.js
... | ... | @@ -16,7 +16,7 @@ module.exports = (xid, task, isPostpaid) => { |
16 | 16 | 'apikey', |
17 | 17 | composeApikey(xid) || '-', |
18 | 18 | isPostpaid ? 'postpaid' : 'prepaid', |
19 | - (task && task.trx_id) || null, | |
19 | + (task && task.trx_id && task.trx_id.toString()) || null, | |
20 | 20 | ].filter((item) => item), |
21 | 21 | ); |
22 | 22 | }; |
package-lock.json
... | ... | @@ -1813,7 +1813,7 @@ |
1813 | 1813 | } |
1814 | 1814 | }, |
1815 | 1815 | "komodo-sdk": { |
1816 | - "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git#4af07f8facf4d10ced4da38c4d44e1a4670a5165", | |
1816 | + "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git#9e598d4f323f0d8dc5e60294c5257dc674cf0ad4", | |
1817 | 1817 | "from": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git", |
1818 | 1818 | "requires": { |
1819 | 1819 | "array-unique": "^0.3.2", |
... | ... | @@ -1870,7 +1870,7 @@ |
1870 | 1870 | } |
1871 | 1871 | }, |
1872 | 1872 | "komodo-sdk-postpaid": { |
1873 | - "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git#8fff5a84d1b8527aae4ebd32bfc8aaed2bd87f9a", | |
1873 | + "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git#561ba299992db7931c05cc5dbcf7b29ca7e9c657", | |
1874 | 1874 | "from": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git", |
1875 | 1875 | "requires": { |
1876 | 1876 | "axios": "^0.19.2", |
... | ... | @@ -1902,7 +1902,7 @@ |
1902 | 1902 | } |
1903 | 1903 | }, |
1904 | 1904 | "komodo-sdk": { |
1905 | - "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#4af07f8facf4d10ced4da38c4d44e1a4670a5165", | |
1905 | + "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#9e598d4f323f0d8dc5e60294c5257dc674cf0ad4", | |
1906 | 1906 | "from": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", |
1907 | 1907 | "requires": { |
1908 | 1908 | "array-unique": "^0.3.2", |