Commit 2ac95e6d067113ee2edfcec709897fddb19876e7

Authored by Adhidarma Hadiwinoto
1 parent 4ebc7c840f
Exists in master

Include struk pada report

Showing 1 changed file with 1 additions and 0 deletions Inline Diff

lib/callback/handler-postpaid.js
1 const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID'; 1 const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID';
2 2
3 const logger = require('komodo-sdk/logger'); 3 const logger = require('komodo-sdk/logger');
4 const report = require('../report/postpaid'); 4 const report = require('../report/postpaid');
5 const getFromReq = require('../get-from-params-body-qs'); 5 const getFromReq = require('../get-from-params-body-qs');
6 const translateRc = require('../translate-rc'); 6 const translateRc = require('../translate-rc');
7 7
8 module.exports = (req, res) => { 8 module.exports = (req, res) => {
9 const { xid } = res.locals; 9 const { xid } = res.locals;
10 res.json({ 10 res.json({
11 status: 'OK', 11 status: 'OK',
12 error: null, 12 error: null,
13 ts: new Date(), 13 ts: new Date(),
14 xid, 14 xid,
15 }); 15 });
16 16
17 const reportCommand = getFromReq(req, 'command'); 17 const reportCommand = getFromReq(req, 'command');
18 if (!reportCommand) { 18 if (!reportCommand) {
19 logger.warn(`${MODULE_NAME} C7A4A26C: Unknown command`, { xid }); 19 logger.warn(`${MODULE_NAME} C7A4A26C: Unknown command`, { xid });
20 return; 20 return;
21 } 21 }
22 22
23 const isInquiry = reportCommand === 'INQUIRY'; 23 const isInquiry = reportCommand === 'INQUIRY';
24 24
25 const rcFromRequest = getFromReq(req, 'rc'); 25 const rcFromRequest = getFromReq(req, 'rc');
26 const translatedRc = rcFromRequest && (translateRc[rcFromRequest] || rcFromRequest); 26 const translatedRc = rcFromRequest && (translateRc[rcFromRequest] || rcFromRequest);
27 logger.verbose(`${MODULE_NAME} 475DA596: RC translated`, { 27 logger.verbose(`${MODULE_NAME} 475DA596: RC translated`, {
28 xid, 28 xid,
29 reportCommand, 29 reportCommand,
30 rcFromRequest, 30 rcFromRequest,
31 translatedRc, 31 translatedRc,
32 }); 32 });
33 33
34 const struk = getFromReq(req, 'struk'); 34 const struk = getFromReq(req, 'struk');
35 if (struk) { 35 if (struk) {
36 logger.verbose(`${MODULE_NAME} 2E480E83: Got a struk`, { 36 logger.verbose(`${MODULE_NAME} 2E480E83: Got a struk`, {
37 xid, 37 xid,
38 typeofStruk: typeof struk, 38 typeofStruk: typeof struk,
39 }); 39 });
40 } 40 }
41 41
42 report(xid, { 42 report(xid, {
43 command: reportCommand, 43 command: reportCommand,
44 trx_id: getFromReq(req, 'request_id'), 44 trx_id: getFromReq(req, 'request_id'),
45 rc: translatedRc 45 rc: translatedRc
46 || (isInquiry && '90') 46 || (isInquiry && '90')
47 || '68', 47 || '68',
48 sn: getFromReq(req, 'sn'), 48 sn: getFromReq(req, 'sn'),
49 amount: Number(getFromReq(req, 'amount')) || undefined, 49 amount: Number(getFromReq(req, 'amount')) || undefined,
50 balance: Number(getFromReq(req, 'ending_balance')) || undefined, 50 balance: Number(getFromReq(req, 'ending_balance')) || undefined,
51 51
52 amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge'))) 52 amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge')))
53 || undefined, 53 || undefined,
54 bill_count: Number(getFromReq(req, 'bill_count')) || undefined, 54 bill_count: Number(getFromReq(req, 'bill_count')) || undefined,
55 base_bill_amount: Number(getFromReq(req, 'bill_amount')) || Number(getFromReq(req, 'base_bill_amount')) || undefined, 55 base_bill_amount: Number(getFromReq(req, 'bill_amount')) || Number(getFromReq(req, 'base_bill_amount')) || undefined,
56 56
57 message: { 57 message: {
58 xid, 58 xid,
59 CALLBACK: { 59 CALLBACK: {
60 ip: req.ip, 60 ip: req.ip,
61 method: req.method, 61 method: req.method,
62 body: req.body, 62 body: req.body,
63 qs: req.query, 63 qs: req.query,
64 }, 64 },
65 }, 65 },
66 66
67 struk: struk || undefined,
67 }); 68 });
68 }; 69 };
69 70