handler-postpaid.js
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID';
const logger = require('tektrans-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,
});
const struk = getFromReq(req, 'struk');
if (struk) {
logger.verbose(`${MODULE_NAME} 2E480E83: Got a struk`, {
xid,
typeofStruk: typeof struk,
});
}
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, 'bill_amount')) || Number(getFromReq(req, 'base_bill_amount')) || undefined,
message: {
xid,
CALLBACK: {
ip: req.ip,
method: req.method,
body: req.body,
qs: req.query,
},
},
struk: struk || undefined,
});
};