Commit 635fc54bfa32e6e5f6067765e23dc54329a3db6d

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

Field command pada report

Showing 2 changed files with 3 additions and 1 deletions Inline Diff

lib/core-callback/sender.js
1 const MODULE_NAME = 'CORE-CALLBACK-SENDER'; 1 const MODULE_NAME = 'CORE-CALLBACK-SENDER';
2 const MAX_RETRY = 10; 2 const MAX_RETRY = 10;
3 const SLEEP_BEFORE_RETRY_MS = 60 * 1000; 3 const SLEEP_BEFORE_RETRY_MS = 60 * 1000;
4 4
5 const axios = require('axios').default; 5 const axios = require('axios').default;
6 const logger = require('komodo-sdk/logger'); 6 const logger = require('komodo-sdk/logger');
7 7
8 const sleep = require('../sleep'); 8 const sleep = require('../sleep');
9 const urlConcatQs = require('../url-concat-qs'); 9 const urlConcatQs = require('../url-concat-qs');
10 10
11 const sender = async (data, xid, retry) => { 11 const sender = async (data, xid, retry) => {
12 if (!data.reverse_url) return; 12 if (!data.reverse_url) return;
13 13
14 const params = { 14 const params = {
15 httpgetx_xid: xid, 15 httpgetx_xid: xid,
16 command: data.command,
16 request_id: data.request_id && data.request_id.toString(), 17 request_id: data.request_id && data.request_id.toString(),
17 transaction_id: data.transaction_id && data.transaction_id.toString(), 18 transaction_id: data.transaction_id && data.transaction_id.toString(),
18 transaction_date: data.transaction_date, 19 transaction_date: data.transaction_date,
19 store_name: data.store_name, 20 store_name: data.store_name,
20 terminal_name: data.terminal_name, 21 terminal_name: data.terminal_name,
21 product_name: data.product_name, 22 product_name: data.product_name,
22 destination: data.destination, 23 destination: data.destination,
23 rc: data.rc, 24 rc: data.rc,
24 sn: data.sn, 25 sn: data.sn,
25 message: data.message, 26 message: data.message,
26 amount: data.amount, 27 amount: data.amount,
27 ending_balance: data.ending_balance, 28 ending_balance: data.ending_balance,
28 amount_to_charge: data.amount_to_charge, 29 amount_to_charge: data.amount_to_charge,
29 }; 30 };
30 31
31 const fullUrl = urlConcatQs(data.reverse_url, params); 32 const fullUrl = urlConcatQs(data.reverse_url, params);
32 logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, { 33 logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, {
33 xid, retry, params, fullUrl, 34 xid, retry, params, fullUrl,
34 }); 35 });
35 36
36 try { 37 try {
37 const result = await axios.get(data.reverse_url, { 38 const result = await axios.get(data.reverse_url, {
38 params, 39 params,
39 timeout: 60 * 1000, 40 timeout: 60 * 1000,
40 }); 41 });
41 42
42 logger.info(`${MODULE_NAME} 3641FBD7: CORE-CALLBACK has been sent to PARTNER successfully`, { 43 logger.info(`${MODULE_NAME} 3641FBD7: CORE-CALLBACK has been sent to PARTNER successfully`, {
43 xid, retry, fullUrl, body: result && result.data, 44 xid, retry, fullUrl, body: result && result.data,
44 }); 45 });
45 } catch (e) { 46 } catch (e) {
46 logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending CORE-CALLBACK to PARTNER`, { 47 logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending CORE-CALLBACK to PARTNER`, {
47 xid, 48 xid,
48 retry, 49 retry,
49 maxRetry: MAX_RETRY, 50 maxRetry: MAX_RETRY,
50 errCode: e.code, 51 errCode: e.code,
51 errMessage: e.message, 52 errMessage: e.message,
52 reverseUrl: data.reverse_url, 53 reverseUrl: data.reverse_url,
53 fullUrl, 54 fullUrl,
54 httpStatus: e.response && e.response.status, 55 httpStatus: e.response && e.response.status,
55 body: e.response && e.response.data, 56 body: e.response && e.response.data,
56 }); 57 });
57 58
58 if ((retry || 0) < MAX_RETRY) { 59 if ((retry || 0) < MAX_RETRY) {
59 await sleep(SLEEP_BEFORE_RETRY_MS); 60 await sleep(SLEEP_BEFORE_RETRY_MS);
60 logger.verbose(`${MODULE_NAME} D8958695: Going to retry sending CORE-CALLBACK TO PARTNER`, { 61 logger.verbose(`${MODULE_NAME} D8958695: Going to retry sending CORE-CALLBACK TO PARTNER`, {
61 xid, sleepTime: SLEEP_BEFORE_RETRY_MS, 62 xid, sleepTime: SLEEP_BEFORE_RETRY_MS,
62 }); 63 });
63 sender(data, xid, (retry || 0) + 1); 64 sender(data, xid, (retry || 0) + 1);
64 } 65 }
65 } 66 }
66 }; 67 };
67 68
68 module.exports = sender; 69 module.exports = sender;
69 70
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(); 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 command: result.data.command,
64 request_id: result.data.request_id && result.data.request_id.toString(), 65 request_id: result.data.request_id && result.data.request_id.toString(),
65 transaction_id: result.data.transaction_id && result.data.transaction_id.toString(), 66 transaction_id: result.data.transaction_id && result.data.transaction_id.toString(),
66 transaction_date: result.data.transaction_date, 67 transaction_date: result.data.transaction_date,
67 store_name: result.data.store_name, 68 store_name: result.data.store_name,
68 terminal_name: result.data.terminal_name, 69 terminal_name: result.data.terminal_name,
69 product_name: result.data.product_name, 70 product_name: result.data.product_name,
70 destination: result.data.destination, 71 destination: result.data.destination,
71 rc: result.data.rc, 72 rc: result.data.rc,
72 sn: result.data.sn, 73 sn: result.data.sn,
73 // detail: result.data.detail,
74 message: result.data.message, 74 message: result.data.message,
75 amount: result.data.amount, 75 amount: result.data.amount,
76 ending_balance: result.data.ending_balance, 76 ending_balance: result.data.ending_balance,
77 amount_to_charge: result.data.amount_to_charge, 77 amount_to_charge: result.data.amount_to_charge,
78 }; 78 };
79 79
80 logger.verbose('Forwarding CORE direct-response to partner', { 80 logger.verbose('Forwarding CORE direct-response to partner', {
81 xid, 81 xid,
82 resultForPartner, 82 resultForPartner,
83 }); 83 });
84 84
85 res.json(resultForPartner); 85 res.json(resultForPartner);
86 } catch (e) { 86 } catch (e) {
87 logger.warn('EXCEPTION on forwarding INQUIRY request to CORE', { 87 logger.warn('EXCEPTION on forwarding INQUIRY request to CORE', {
88 xid, 88 xid,
89 errCode: e.code, 89 errCode: e.code,
90 errMessage: e.message, 90 errMessage: e.message,
91 }); 91 });
92 92
93 res.json({ 93 res.json({
94 httpgetx_xid: xid, 94 httpgetx_xid: xid,
95 command: 'INQUIRY',
95 request_id: requestId, 96 request_id: requestId,
96 terminal_name: terminalName, 97 terminal_name: terminalName,
97 product_name: productName, 98 product_name: productName,
98 destination, 99 destination,
99 rc: '68', 100 rc: '68',
100 message: 'CORE tidak merespon dengan benar, tidak dapat mengetahui status request anda', 101 message: 'CORE tidak merespon dengan benar, tidak dapat mengetahui status request anda',
101 }); 102 });
102 } 103 }
103 }; 104 };
104 105
105 router.all('/', mainHandler); 106 router.all('/', mainHandler);