Blame view
lib/partner-listener/routers/pay.js
3.82 KB
9ced2cfdf
|
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'); |
9ced2cfdf
|
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
const router = express.Router(); module.exports = router; const CORE_ENDPOINT = `${coreUrl}/postpaid2/pay`; const mainHandler = async (req, res) => { const { xid } = res.locals; const requestId = (getFromBodyQsParams(req, 'request_id') || '').toString().trim(); const terminalNameWithoutIp = (getFromBodyQsParams(req, 'terminal_name') || '').toString().trim(); 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 |
const msg = 'INVALID REQUEST. Missing request_id or terminal_name or product_name or destination.'; res.end(msg); dumper(xid, req, msg); |
9ced2cfdf
|
32 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
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 PAY request to CORE', { xid, params }); try { const result = await axios.get(CORE_ENDPOINT, { params, timeout: 10000, }); if (!result || !result.data) { const newError = new Error('0D428E4C: Empty CORE PAY direct-response'); logger.warn(newError.message, { xid }); throw newError; } logger.verbose('Got PAY direct-response from CORE', { xid, coreResponse: result.data, }); const resultForPartner = { httpgetx_xid: xid, command: result.data.command, request_id: result.data.request_id && result.data.request_id.toString(), transaction_id: result.data.transaction_id && result.data.transaction_id.toString(), transaction_date: result.data.transaction_date, 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, message: result.data.message, amount: result.data.amount, ending_balance: result.data.ending_balance, }; logger.verbose('Forwarding CORE PAY direct-response to partner', { xid, resultForPartner, }); res.json(resultForPartner); |
732c359a7
|
88 |
dumper(xid, req, resultForPartner); |
9ced2cfdf
|
89 90 91 92 93 94 |
} catch (e) { logger.warn('EXCEPTION on forwarding PAY request to CORE', { xid, errCode: e.code, errMessage: e.message, }); |
732c359a7
|
95 |
const resultForPartner = { |
9ced2cfdf
|
96 97 98 99 100 101 102 103 |
httpgetx_xid: xid, command: 'PAY', 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
|
104 105 106 |
}; dumper(xid, req, resultForPartner); |
9ced2cfdf
|
107 108 109 110 |
} }; router.all('/', mainHandler); |