Blame view

lib/partner-listener/routers/trx-status.js 3.72 KB
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
1
  const MODULE_NAME = 'PARTNER-LISTENER.ROUTERS.TRX-STATUS';
ab5828535   Adhidarma Hadiwinoto   Ready to rock
2
3
4
5
6
7
8
9
10
11
12
  const express = require('express');
  const moment = require('moment');
  
  const logger = require('komodo-sdk/logger');
  
  const coreapi = require('../../coreapi');
  
  const router = express.Router();
  module.exports = router;
  
  async function pageIndex(req, res) {
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
13
      const { xid } = res.locals;
ab5828535   Adhidarma Hadiwinoto   Ready to rock
14
15
16
17
      if (!req.body) req.body = {};
  
      if (!req.body.terminal_name && !req.query.terminal_name) {
          res.json({
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
18
19
20
              httpgetx_xid: xid,
              error: true,
              message: 'Parameter terminal_name tidak terdefinisi',
ab5828535   Adhidarma Hadiwinoto   Ready to rock
21
22
23
24
25
26
          });
          return;
      }
  
      if (!req.body.password && !req.query.password) {
          res.json({
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
27
              httpgetx_xid: xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
28
29
30
31
32
33
34
35
              error: true,
              message: 'Parameter password tidak terdefinisi',
          });
          return;
      }
  
      if (!req.body.request_id && !req.query.request_id) {
          res.json({
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
36
              httpgetx_xid: xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
37
38
39
40
41
42
43
44
45
46
              error: true,
              message: 'Parameter request_id tidak terdefinisi',
          });
          return;
      }
  
      const remoteIp = req.ip.replace(/^::ffff:/, '');
      const askerTerminalName = `${req.body.terminal_name || req.query.terminal_name}@${remoteIp}`;
  
      const coreResponse = await coreapi({
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
47
          xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
48
49
50
51
52
53
54
55
56
57
          path: '/trx-status/view',
          qs: {
              asker_terminal_name: askerTerminalName,
              asker_terminal_password: req.body.password || req.query.password,
              request_id: req.body.request_id || req.query.request_id,
          },
      });
  
      if (!coreResponse || !coreResponse.status) {
          const msg = 'Status transaksi tidak dapat diketahui karena suatu kesalahan pada sistem';
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
58
59
          logger.warn(`${MODULE_NAME} 9983DB34: ${msg}`, {
              xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
60
61
62
63
64
65
              ip: req.ip,
              terminal_name: req.body.terminal_name || req.query.terminal_name,
              request_id: req.body.request_id || req.query.request_id,
          });
  
          res.json({
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
66
              httpgetx_xid: xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
              error: true,
              from_ip: remoteIp,
              terminal_name: req.body.terminal_name || req.query.terminal_name,
              full_terminal_name: askerTerminalName,
              password: req.body.password || req.query.password,
              message: msg,
          });
          return;
      }
  
      const trx = coreResponse && coreResponse.result ? {
          id: coreResponse.result.id,
          request_id: coreResponse.result.request_id,
          store_id: coreResponse.result.store_id,
          store_name: coreResponse.result.store_name,
          terminal_id: coreResponse.result.terminal_id,
          terminal_name: coreResponse.result.terminal_name,
  
          created: moment(coreResponse.result.created).format('YYYY-MM-DD HH:mm:ss'),
          modified: moment(coreResponse.result.modified).format('YYYY-MM-DD HH:mm:ss'),
  
          product_name: coreResponse.result.product_name,
          destination: coreResponse.result.destination,
          amount: coreResponse.result.amount,
          ending_balance: coreResponse.result.ending_balance,
          rc: coreResponse.result.rc,
          message: coreResponse.result.reply_message,
          sn: coreResponse.result.sn,
      }
          : null;
038a3f3ea   Adhidarma Hadiwinoto   Log result
97
      const result = {
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
98
          httpgetx_xid: xid,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
99
100
101
102
          error: coreResponse.status !== 'OK',
          from_ip: remoteIp,
          terminal_name: req.body.terminal_name || req.query.terminal_name,
          full_terminal_name: askerTerminalName,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
103
          message: coreResponse.message,
29abebf10   Adhidarma Hadiwinoto   Hapus field passw...
104
          trx_found: !!trx,
ab5828535   Adhidarma Hadiwinoto   Ready to rock
105
106
          trx,
          // original_trx: coreResponse.result,
038a3f3ea   Adhidarma Hadiwinoto   Log result
107
108
109
      };
  
      res.json(result);
12f6d059c   Adhidarma Hadiwinoto   LOG hashtag on tr...
110
111
112
113
114
      logger.info(`${MODULE_NAME} 480C4BB0: Partner request responded`, {
          xid,
          processing_time_in_ms: new Date() - res.locals.x_http_request_ts,
          result,
      });
ab5828535   Adhidarma Hadiwinoto   Ready to rock
115
116
117
  }
  
  router.get('/', pageIndex);