Commit 864191b219fffb968d9b6a9edab6ec25929d58d8

Authored by Adhidarma Hadiwinoto
1 parent f2c18879a9
Exists in master and in 1 other branch dev

terminal name tidak di-uppercase

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

lib/listener-partner/routers/inquiry.js
1 const axios = require('axios').default; 1 const axios = require('axios').default;
2 const express = require('express'); 2 const express = require('express');
3 const coreUrl = require('komodo-sdk/core-url'); 3 const coreUrl = require('komodo-sdk/core-url');
4 4
5 const config = require('komodo-sdk/config'); 5 const config = require('komodo-sdk/config');
6 const logger = require('komodo-sdk/logger'); 6 const logger = require('komodo-sdk/logger');
7 7
8 const getFromBodyQsParams = require('../../get-from-body-qs-params'); 8 const getFromBodyQsParams = require('../../get-from-body-qs-params');
9 const ipv6ToIpv4 = require('../../ipv6-to-ipv4'); 9 const ipv6ToIpv4 = require('../../ipv6-to-ipv4');
10 10
11 const router = express.Router(); 11 const router = express.Router();
12 module.exports = router; 12 module.exports = router;
13 13
14 const CORE_ENDPOINT = `${coreUrl}/postpaid2/inquiry`; 14 const CORE_ENDPOINT = `${coreUrl}/postpaid2/inquiry`;
15 15
16 const mainHandler = async (req, res) => { 16 const mainHandler = async (req, res) => {
17 const { xid } = res.locals; 17 const { xid } = res.locals;
18 18
19 const requestId = (getFromBodyQsParams(req, 'request_id') || '').toString().trim(); 19 const requestId = (getFromBodyQsParams(req, 'request_id') || '').toString().trim();
20 const terminalNameWithoutIp = (getFromBodyQsParams(req, 'terminal_name') || '').toString().trim().toUpperCase(); 20 const terminalNameWithoutIp = (getFromBodyQsParams(req, 'terminal_name') || '').toString().trim();
21 const terminalName = `${terminalNameWithoutIp}@${ipv6ToIpv4(req.ip)}`; 21 const terminalName = `${terminalNameWithoutIp}@${ipv6ToIpv4(req.ip)}`;
22 const productName = (getFromBodyQsParams(req, 'product_name') || '').trim().toUpperCase(); 22 const productName = (getFromBodyQsParams(req, 'product_name') || '').trim().toUpperCase();
23 const destination = (getFromBodyQsParams(req, 'destination') || '').toString().trim(); 23 const destination = (getFromBodyQsParams(req, 'destination') || '').toString().trim();
24 const password = getFromBodyQsParams(req, 'password'); 24 const password = getFromBodyQsParams(req, 'password');
25 const reverseUrl = getFromBodyQsParams(req, 'reverse_url'); 25 const reverseUrl = getFromBodyQsParams(req, 'reverse_url');
26 26
27 if (!requestId || !terminalNameWithoutIp || !productName || !destination) { 27 if (!requestId || !terminalNameWithoutIp || !productName || !destination) {
28 res.end('INVALID REQUEST. Missing request_id or terminal_name or product_name or destination.'); 28 res.end('INVALID REQUEST. Missing request_id or terminal_name or product_name or destination.');
29 return; 29 return;
30 } 30 }
31 31
32 const params = { 32 const params = {
33 origin: config.name, 33 origin: config.name,
34 report_ip: config.listener.core.from_ip, 34 report_ip: config.listener.core.from_ip,
35 report_port: config.listener.core.port || 25614, 35 report_port: config.listener.core.port || 25614,
36 request_id: requestId, 36 request_id: requestId,
37 terminal_name: terminalName, 37 terminal_name: terminalName,
38 product_name: productName, 38 product_name: productName,
39 destination, 39 destination,
40 terminal_password: password, 40 terminal_password: password,
41 reverse_url: reverseUrl, 41 reverse_url: reverseUrl,
42 }; 42 };
43 43
44 logger.info('Forwarding INQUIRY request to CORE', { xid, params }); 44 logger.info('Forwarding INQUIRY request to CORE', { xid, params });
45 try { 45 try {
46 const result = await axios.get(CORE_ENDPOINT, { 46 const result = await axios.get(CORE_ENDPOINT, {
47 params, 47 params,
48 timeout: 10000, 48 timeout: 10000,
49 }); 49 });
50 50
51 if (!result || !result.data) { 51 if (!result || !result.data) {
52 const newError = new Error('8002EB0D: Empty CORE INQUIRY direct-response'); 52 const newError = new Error('8002EB0D: Empty CORE INQUIRY direct-response');
53 logger.warn(newError.message, { xid }); 53 logger.warn(newError.message, { xid });
54 throw newError; 54 throw newError;
55 } 55 }
56 56
57 logger.verbose('Got INQUIRY direct-response from CORE', { 57 logger.verbose('Got INQUIRY direct-response from CORE', {
58 xid, 58 xid,
59 coreResponse: result.data, 59 coreResponse: result.data,
60 }); 60 });
61 61
62 const resultForPartner = { 62 const resultForPartner = {
63 httpgetx_xid: xid, 63 httpgetx_xid: xid,
64 request_id: result.data.request_id && result.data.request_id.toString(), 64 request_id: result.data.request_id && result.data.request_id.toString(),
65 transaction_id: result.data.transaction_id && result.data.transaction_id.toString(), 65 transaction_id: result.data.transaction_id && result.data.transaction_id.toString(),
66 transaction_date: result.data.transaction_date,
66 store_name: result.data.store_name, 67 store_name: result.data.store_name,
67 terminal_name: result.data.terminal_name, 68 terminal_name: result.data.terminal_name,
68 product_name: result.data.product_name, 69 product_name: result.data.product_name,
69 destination: result.data.destination, 70 destination: result.data.destination,
70 rc: result.data.rc, 71 rc: result.data.rc,
71 sn: result.data.sn, 72 sn: result.data.sn,
72 // detail: result.data.detail, 73 // detail: result.data.detail,
73 message: result.data.message, 74 message: result.data.message,
74 amount: result.data.amount, 75 amount: result.data.amount,
75 ending_balance: result.data.ending_balance, 76 ending_balance: result.data.ending_balance,
76 amount_to_charge: result.data.amount_to_charge, 77 amount_to_charge: result.data.amount_to_charge,
77 }; 78 };
78 79
79 logger.verbose('Forwarding CORE direct-response to partner', { 80 logger.verbose('Forwarding CORE direct-response to partner', {
80 xid, 81 xid,
81 resultForPartner, 82 resultForPartner,
82 }); 83 });
83 84
84 res.json(resultForPartner); 85 res.json(resultForPartner);
85 } catch (e) { 86 } catch (e) {
86 logger.warn('EXCEPTION on forwarding INQUIRY request to CORE', { 87 logger.warn('EXCEPTION on forwarding INQUIRY request to CORE', {
87 xid, 88 xid,
88 errCode: e.code, 89 errCode: e.code,
89 errMessage: e.message, 90 errMessage: e.message,
90 }); 91 });
91 92
92 res.json({ 93 res.json({
93 httpgetx_xid: xid, 94 httpgetx_xid: xid,
94 request_id: requestId, 95 request_id: requestId,
95 terminal_name: terminalName, 96 terminal_name: terminalName,
96 product_name: productName, 97 product_name: productName,
97 destination, 98 destination,
98 rc: '68', 99 rc: '68',
99 message: 'CORE tidak merespon dengan benar, tidak dapat mengetahui status request anda', 100 message: 'CORE tidak merespon dengan benar, tidak dapat mengetahui status request anda',
100 }); 101 });
101 } 102 }
102 }; 103 };
103 104
104 router.all('/', mainHandler); 105 router.all('/', mainHandler);
105 106