Commit 050d92ffb6dd14e14390cb1a370d553bc37b7a2a

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

Undefined on missing SN

Showing 2 changed files with 2 additions and 2 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 command: data.command,
17 request_id: data.request_id && data.request_id.toString(), 17 request_id: data.request_id && data.request_id.toString(),
18 transaction_id: data.transaction_id && data.transaction_id.toString(), 18 transaction_id: data.transaction_id && data.transaction_id.toString(),
19 transaction_date: data.transaction_date, 19 transaction_date: data.transaction_date,
20 store_name: data.store_name, 20 store_name: data.store_name,
21 terminal_name: data.terminal_name, 21 terminal_name: data.terminal_name,
22 product_name: data.product_name, 22 product_name: data.product_name,
23 destination: data.destination, 23 destination: data.destination,
24 rc: data.rc, 24 rc: data.rc,
25 sn: data.sn, 25 sn: data.sn || undefined,
26 amount: Number(data.amount) || undefined, 26 amount: Number(data.amount) || undefined,
27 ending_balance: Number(data.ending_balance) || undefined, 27 ending_balance: Number(data.ending_balance) || undefined,
28 message: data.message, 28 message: data.message,
29 }; 29 };
30 30
31 if (data.command === 'INQUIRY' && Number(data.amount_to_charge)) { 31 if (data.command === 'INQUIRY' && Number(data.amount_to_charge)) {
32 params.amount_to_charge = Number(data.amount_to_charge); 32 params.amount_to_charge = Number(data.amount_to_charge);
33 } 33 }
34 34
35 const fullUrl = urlConcatQs(data.reverse_url, params); 35 const fullUrl = urlConcatQs(data.reverse_url, params);
36 logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, { 36 logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, {
37 xid, retry, params, fullUrl, 37 xid, retry, params, fullUrl,
38 }); 38 });
39 39
40 try { 40 try {
41 const result = await axios.get(data.reverse_url, { 41 const result = await axios.get(data.reverse_url, {
42 params, 42 params,
43 timeout: 60 * 1000, 43 timeout: 60 * 1000,
44 }); 44 });
45 45
46 logger.info(`${MODULE_NAME} 3641FBD7: CORE-CALLBACK has been sent to PARTNER successfully`, { 46 logger.info(`${MODULE_NAME} 3641FBD7: CORE-CALLBACK has been sent to PARTNER successfully`, {
47 xid, retry, fullUrl, body: result && result.data, 47 xid, retry, fullUrl, body: result && result.data,
48 }); 48 });
49 } catch (e) { 49 } catch (e) {
50 logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending CORE-CALLBACK to PARTNER`, { 50 logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending CORE-CALLBACK to PARTNER`, {
51 xid, 51 xid,
52 retry, 52 retry,
53 maxRetry: MAX_RETRY, 53 maxRetry: MAX_RETRY,
54 errCode: e.code, 54 errCode: e.code,
55 errMessage: e.message, 55 errMessage: e.message,
56 reverseUrl: data.reverse_url, 56 reverseUrl: data.reverse_url,
57 fullUrl, 57 fullUrl,
58 httpStatus: e.response && e.response.status, 58 httpStatus: e.response && e.response.status,
59 body: e.response && e.response.data, 59 body: e.response && e.response.data,
60 }); 60 });
61 61
62 if ((retry || 0) < MAX_RETRY) { 62 if ((retry || 0) < MAX_RETRY) {
63 await sleep(SLEEP_BEFORE_RETRY_MS); 63 await sleep(SLEEP_BEFORE_RETRY_MS);
64 logger.verbose(`${MODULE_NAME} D8958695: Going to retry sending CORE-CALLBACK TO PARTNER`, { 64 logger.verbose(`${MODULE_NAME} D8958695: Going to retry sending CORE-CALLBACK TO PARTNER`, {
65 xid, sleepTime: SLEEP_BEFORE_RETRY_MS, 65 xid, sleepTime: SLEEP_BEFORE_RETRY_MS,
66 }); 66 });
67 sender(data, xid, (retry || 0) + 1); 67 sender(data, xid, (retry || 0) + 1);
68 } 68 }
69 } 69 }
70 }; 70 };
71 71
72 module.exports = sender; 72 module.exports = sender;
73 73
lib/partner-listener/routers/topup.js
1 const MODULE_NAME = 'PARTNER-LISTENER.ROUTER.TOPUP'; 1 const MODULE_NAME = 'PARTNER-LISTENER.ROUTER.TOPUP';
2 2
3 const express = require('express'); 3 const express = require('express');
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 const coreapi = require('komodo-sdk/coreapi'); 7 const coreapi = require('komodo-sdk/coreapi');
8 // const coreapi = require('../../coreapi'); 8 // const coreapi = require('../../coreapi');
9 9
10 const router = express.Router(); 10 const router = express.Router();
11 module.exports = router; 11 module.exports = router;
12 12
13 function onInvalidParameter(missingParameter, req, res) { 13 function onInvalidParameter(missingParameter, req, res) {
14 logger.verbose(`${MODULE_NAME} 1536D577: Undefined ${missingParameter} parameter`, { 14 logger.verbose(`${MODULE_NAME} 1536D577: Undefined ${missingParameter} parameter`, {
15 xid: res.locals.xid, 15 xid: res.locals.xid,
16 ip: req.ip, 16 ip: req.ip,
17 terminal_name: req.body.terminal_name || req.query.terminal_name, 17 terminal_name: req.body.terminal_name || req.query.terminal_name,
18 request_id: req.body.request_id || req.query.request_id, 18 request_id: req.body.request_id || req.query.request_id,
19 product_name: req.body.product_name || req.query.product_name, 19 product_name: req.body.product_name || req.query.product_name,
20 destination: req.body.destination || req.query.destination, 20 destination: req.body.destination || req.query.destination,
21 }); 21 });
22 res.end('INVALID REQUEST'); 22 res.end('INVALID REQUEST');
23 } 23 }
24 24
25 function pagePrerequisite(req, res, next) { 25 function pagePrerequisite(req, res, next) {
26 if (!req.body) req.body = {}; 26 if (!req.body) req.body = {};
27 27
28 if (!req.body.terminal_name && !req.query.terminal_name) { 28 if (!req.body.terminal_name && !req.query.terminal_name) {
29 onInvalidParameter('terminal_name', req, res); 29 onInvalidParameter('terminal_name', req, res);
30 return; 30 return;
31 } 31 }
32 32
33 if (!req.body.password && !req.query.password) { 33 if (!req.body.password && !req.query.password) {
34 onInvalidParameter('password', req, res); 34 onInvalidParameter('password', req, res);
35 return; 35 return;
36 } 36 }
37 37
38 if (!req.body.request_id && !req.query.request_id) { 38 if (!req.body.request_id && !req.query.request_id) {
39 onInvalidParameter('request_id', req, res); 39 onInvalidParameter('request_id', req, res);
40 return; 40 return;
41 } 41 }
42 42
43 if (!req.body.product_name && !req.query.product_name) { 43 if (!req.body.product_name && !req.query.product_name) {
44 onInvalidParameter('product_name', req, res); 44 onInvalidParameter('product_name', req, res);
45 return; 45 return;
46 } 46 }
47 47
48 if (!req.body.destination && !req.query.destination) { 48 if (!req.body.destination && !req.query.destination) {
49 onInvalidParameter('destination', req, res); 49 onInvalidParameter('destination', req, res);
50 return; 50 return;
51 } 51 }
52 52
53 next(); 53 next();
54 } 54 }
55 55
56 async function pageIndex(req, res) { 56 async function pageIndex(req, res) {
57 const { xid } = res.locals; 57 const { xid } = res.locals;
58 58
59 const terminalName = `${req.body.terminal_name || req.query.terminal_name}@${req.ip.replace(/^::ffff:/, '')}`; 59 const terminalName = `${req.body.terminal_name || req.query.terminal_name}@${req.ip.replace(/^::ffff:/, '')}`;
60 60
61 const [err, coreResponse] = await coreapi({ 61 const [err, coreResponse] = await coreapi({
62 xid, 62 xid,
63 path: '/prepaid/buy', 63 path: '/prepaid/buy',
64 qs: { 64 qs: {
65 terminal_name: terminalName, 65 terminal_name: terminalName,
66 password: req.body.password || req.query.password, 66 password: req.body.password || req.query.password,
67 request_id: req.body.request_id || req.query.request_id, 67 request_id: req.body.request_id || req.query.request_id,
68 product_name: req.body.product_name || req.query.product_name, 68 product_name: req.body.product_name || req.query.product_name,
69 destination: req.body.destination || req.query.destination, 69 destination: req.body.destination || req.query.destination,
70 origin: config.name || 'HTTPGETX', 70 origin: config.name || 'HTTPGETX',
71 report_ip: config.listener.core.ip || null, 71 report_ip: config.listener.core.ip || null,
72 report_port: config.listener.core.port, 72 report_port: config.listener.core.port,
73 reverse_url: req.body.reverse_url || req.query.reverse_url || null, 73 reverse_url: req.body.reverse_url || req.query.reverse_url || null,
74 }, 74 },
75 }); 75 });
76 76
77 if (err || !coreResponse) { 77 if (err || !coreResponse) {
78 logger.warn(`${MODULE_NAME} 8DEBE15F: ERROR on /prepaid/buy response`, { 78 logger.warn(`${MODULE_NAME} 8DEBE15F: ERROR on /prepaid/buy response`, {
79 xid, 79 xid,
80 err, 80 err,
81 coreResponseTypeof: typeof coreResponse, 81 coreResponseTypeof: typeof coreResponse,
82 coreResponse, 82 coreResponse,
83 }); 83 });
84 res.end('INVALID CORE RESPONSE'); 84 res.end('INVALID CORE RESPONSE');
85 return; 85 return;
86 } 86 }
87 87
88 logger.verbose(`${MODULE_NAME} 2528A9B4: Got CORE response`, { 88 logger.verbose(`${MODULE_NAME} 2528A9B4: Got CORE response`, {
89 xid, 89 xid,
90 coreResponse, 90 coreResponse,
91 }); 91 });
92 92
93 const responseToPartner = { 93 const responseToPartner = {
94 httpgetx_xid: xid, 94 httpgetx_xid: xid,
95 request_id: coreResponse.request_id, 95 request_id: coreResponse.request_id,
96 transaction_id: coreResponse.transaction_id, 96 transaction_id: coreResponse.transaction_id,
97 transaction_date: coreResponse.transaction_date, 97 transaction_date: coreResponse.transaction_date,
98 store_name: coreResponse.store_name, 98 store_name: coreResponse.store_name,
99 terminal_name: coreResponse.terminal_name, 99 terminal_name: coreResponse.terminal_name,
100 product_name: coreResponse.product_name, 100 product_name: coreResponse.product_name,
101 destination: coreResponse.destination, 101 destination: coreResponse.destination,
102 rc: coreResponse.rc, 102 rc: coreResponse.rc,
103 sn: coreResponse.sn, 103 sn: coreResponse.sn || undefined,
104 amount: Number(coreResponse.amount) || undefined, 104 amount: Number(coreResponse.amount) || undefined,
105 ending_balance: Number(coreResponse.ending_balance) || undefined, 105 ending_balance: Number(coreResponse.ending_balance) || undefined,
106 message: coreResponse.message, 106 message: coreResponse.message,
107 }; 107 };
108 108
109 res.json(responseToPartner); 109 res.json(responseToPartner);
110 } 110 }
111 111
112 // router.all('/', (req, res) => { res.status(404).end('404: Not implemented yet'); }); 112 // router.all('/', (req, res) => { res.status(404).end('404: Not implemented yet'); });
113 router.get('/', pagePrerequisite, pageIndex); 113 router.get('/', pagePrerequisite, pageIndex);
114 114