Commit 4ebc7c840f2c628f6aa75ebd5d4ed05ec1ce78e1

Authored by Adhidarma Hadiwinoto
1 parent fd31573763
Exists in master

debug struk pada callback

Showing 1 changed file with 9 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');
35 if (struk) {
36 logger.verbose(`${MODULE_NAME} 2E480E83: Got a struk`, {
37 xid,
38 typeofStruk: typeof struk,
39 });
40 }
41
34 report(xid, { 42 report(xid, {
35 command: reportCommand, 43 command: reportCommand,
36 trx_id: getFromReq(req, 'request_id'), 44 trx_id: getFromReq(req, 'request_id'),
37 rc: translatedRc 45 rc: translatedRc
38 || (isInquiry && '90') 46 || (isInquiry && '90')
39 || '68', 47 || '68',
40 sn: getFromReq(req, 'sn'), 48 sn: getFromReq(req, 'sn'),
41 amount: Number(getFromReq(req, 'amount')) || undefined, 49 amount: Number(getFromReq(req, 'amount')) || undefined,
42 balance: Number(getFromReq(req, 'ending_balance')) || undefined, 50 balance: Number(getFromReq(req, 'ending_balance')) || undefined,
43 51
44 amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge'))) 52 amount_to_charge: (isInquiry && Number(getFromReq(req, 'amount_to_charge')))
45 || undefined, 53 || undefined,
46 bill_count: Number(getFromReq(req, 'bill_count')) || undefined, 54 bill_count: Number(getFromReq(req, 'bill_count')) || undefined,
47 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,
48 56
49 message: { 57 message: {
50 xid, 58 xid,
51 CALLBACK: { 59 CALLBACK: {
52 ip: req.ip, 60 ip: req.ip,
53 method: req.method, 61 method: req.method,
54 body: req.body, 62 body: req.body,
55 qs: req.query, 63 qs: req.query,
56 }, 64 },
57 }, 65 },
66
58 }); 67 });
59 }; 68 };
60 69