Blame view

lib/callback/handler-postpaid.js 2.01 KB
525f0bf55   Adhidarma Hadiwinoto   Snapshot to test
1
  const MODULE_NAME = 'CALLBACK.HANDLER-POSTPAID';
3d8701130   Adhidarma Hadiwinoto   Migrate to tektra...
2
  const logger = require('tektrans-logger');
525f0bf55   Adhidarma Hadiwinoto   Snapshot to test
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
  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,
      });
4ebc7c840   Adhidarma Hadiwinoto   debug struk pada ...
32
33
34
35
36
37
38
      const struk = getFromReq(req, 'struk');
      if (struk) {
          logger.verbose(`${MODULE_NAME} 2E480E83: Got a struk`, {
              xid,
              typeofStruk: typeof struk,
          });
      }
525f0bf55   Adhidarma Hadiwinoto   Snapshot to test
39
40
41
42
43
44
45
46
47
48
49
50
51
      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,
fd3157376   Adhidarma Hadiwinoto   Perbaikan dumper ...
52
          base_bill_amount: Number(getFromReq(req, 'bill_amount')) || Number(getFromReq(req, 'base_bill_amount')) || undefined,
525f0bf55   Adhidarma Hadiwinoto   Snapshot to test
53
54
55
56
57
58
59
60
61
62
  
          message: {
              xid,
              CALLBACK: {
                  ip: req.ip,
                  method: req.method,
                  body: req.body,
                  qs: req.query,
              },
          },
4ebc7c840   Adhidarma Hadiwinoto   debug struk pada ...
63

2ac95e6d0   Adhidarma Hadiwinoto   Include struk pad...
64
          struk: struk || undefined,
525f0bf55   Adhidarma Hadiwinoto   Snapshot to test
65
66
      });
  };