From 525f0bf55315df0ec15350061358433ac71824ec Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <adhisimon@gmail.com> Date: Fri, 11 Jun 2021 17:57:25 +0700 Subject: [PATCH] Snapshot to test --- config.sample.json | 37 +++++++++++++++++++++++++ lib/callback/handler-postpaid.js | 59 ++++++++++++++++++++++++++++++++++++++++ lib/callback/index.js | 3 ++ lib/hit/compose-callback-url.js | 2 +- package-lock.json | 6 ++-- 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 config.sample.json create mode 100644 lib/callback/handler-postpaid.js diff --git a/config.sample.json b/config.sample.json new file mode 100644 index 0000000..3a7fe7a --- /dev/null +++ b/config.sample.json @@ -0,0 +1,37 @@ +{ + "handler_name": "KOMODO-GW-HTTPGETX", + "partner": { + "url": "http://PLEASE_CHANGE_ME:25614", + "terminal_name": "PLEASE_CHANGE_ME", + "password": "PLEASE_CHANGE_ME", + "dump_request": true, + "callback": { + "port": 14000, + "url": "http://PLEASE_CHANGE_ME:14000", + "apikey": [ + "PLEASE_CHANGE_ME" + ], + "dump_request": true + } + }, + "control_panel": { + "listen_port": 16101, + "url": "http://localhost:16101/" + }, + "apiserver": { + "port": 16102, + "apikey": "PLEASE_CHANGE_ME", + "url": "http://localhost:16102/apikey/PLEASE_CHANGE_ME" + }, + "push_server": { + "apikey": "PLEASE_CHANGE_ME", + "advice": { + "port": 16103, + "url": "http://localhost:16103/apikey/PLEASE_CHANGE_ME/advice" + } + }, + "products": [ + ], + "remote_products": {}, + "do_not_verbose_log_report": true +} \ No newline at end of file diff --git a/lib/callback/handler-postpaid.js b/lib/callback/handler-postpaid.js new file mode 100644 index 0000000..47cb70b --- /dev/null +++ b/lib/callback/handler-postpaid.js @@ -0,0 +1,59 @@ +const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID'; + +const logger = require('komodo-sdk/logger'); +const report = require('../report/postpaid'); +const getFromReq = require('../get-from-params-body-qs'); +const translateRc = require('../translate-rc'); + +module.exports = (req, res) => { + const { xid } = res.locals; + res.json({ + status: 'OK', + error: null, + ts: new Date(), + xid, + }); + + const reportCommand = getFromReq(req, 'command'); + if (!reportCommand) { + logger.warn(`${MODULE_NAME} C7A4A26C: Unknown command`, { xid }); + return; + } + + const isInquiry = reportCommand === 'INQUIRY'; + + const rcFromRequest = getFromReq(req, 'rc'); + const translatedRc = rcFromRequest && (translateRc[rcFromRequest] || rcFromRequest); + logger.verbose(`${MODULE_NAME} 475DA596: RC translated`, { + xid, + reportCommand, + rcFromRequest, + translatedRc, + }); + + report(xid, { + command: reportCommand, + trx_id: getFromReq(req, 'request_id'), + rc: translatedRc + || (isInquiry && '90') + || '68', + sn: getFromReq(req, 'sn'), + amount: Number(getFromReq(req, 'amount')) || undefined, + balance: Number(getFromReq(req, 'ending_balance')) || undefined, + + amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge'))) + || undefined, + bill_count: Number(getFromReq(req, 'bill_count')) || undefined, + base_bill_amount: Number(getFromReq(req, 'base_bill_amount')) || undefined, + + message: { + xid, + CALLBACK: { + ip: req.ip, + method: req.method, + body: req.body, + qs: req.query, + }, + }, + }); +}; diff --git a/lib/callback/index.js b/lib/callback/index.js index 5ee5a9c..44cb790 100644 --- a/lib/callback/index.js +++ b/lib/callback/index.js @@ -13,6 +13,7 @@ const rfs = require('rotating-file-stream'); const dumper = require('./dumper'); const apikeyChecker = require('./apikey-checker'); const handlerPrepaid = require('./handler-prepaid'); +const handlerPostpaid = require('./handler-postpaid'); const baseFileName = 'logs/callback_access_log'; @@ -75,6 +76,8 @@ app.use('/apikey/:apikey', express.json()); app.use('/apikey/:apikey', dumper); app.use('/apikey/:apikey/prepaid', handlerPrepaid); +app.use('/apikey/:apikey/TOPUP', handlerPrepaid); +app.use('/apikey/:apikey/:hitType', handlerPostpaid); app .listen(listenPort, () => { diff --git a/lib/hit/compose-callback-url.js b/lib/hit/compose-callback-url.js index f8344d3..9647c2d 100644 --- a/lib/hit/compose-callback-url.js +++ b/lib/hit/compose-callback-url.js @@ -16,7 +16,7 @@ module.exports = (xid, task, isPostpaid) => { 'apikey', composeApikey(xid) || '-', isPostpaid ? 'postpaid' : 'prepaid', - (task && task.trx_id) || null, + (task && task.trx_id && task.trx_id.toString()) || null, ].filter((item) => item), ); }; diff --git a/package-lock.json b/package-lock.json index 891cadf..3cd435f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1813,7 +1813,7 @@ } }, "komodo-sdk": { - "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git#4af07f8facf4d10ced4da38c4d44e1a4670a5165", + "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git#9e598d4f323f0d8dc5e60294c5257dc674cf0ad4", "from": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk.git", "requires": { "array-unique": "^0.3.2", @@ -1870,7 +1870,7 @@ } }, "komodo-sdk-postpaid": { - "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git#8fff5a84d1b8527aae4ebd32bfc8aaed2bd87f9a", + "version": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git#561ba299992db7931c05cc5dbcf7b29ca7e9c657", "from": "git+https://gitlab.kodesumber.com/komodo/komodo-sdk-postpaid.git", "requires": { "axios": "^0.19.2", @@ -1902,7 +1902,7 @@ } }, "komodo-sdk": { - "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#4af07f8facf4d10ced4da38c4d44e1a4670a5165", + "version": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git#9e598d4f323f0d8dc5e60294c5257dc674cf0ad4", "from": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", "requires": { "array-unique": "^0.3.2", -- 1.9.0