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