Commit f2be872ef8e628fd0e04e9de67eee13492ac1221

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

config.terminals_with_location

Showing 2 changed files with 32 additions and 11 deletions Inline Diff

1 { 1 {
2 "name": "HTTPGETX", 2 "name": "HTTPGETX",
3 3
4 "# core_url": "Silahkan diisi dengan core url, bisa dikosongkan jika ingin membaca dari main config komodo", 4 "# core_url": "Silahkan diisi dengan core url, bisa dikosongkan jika ingin membaca dari main config komodo",
5 "core_url": "", 5 "core_url": "",
6 6
7 "listener": { 7 "listener": {
8 "partner": { 8 "partner": {
9 "trust_proxy": ["loopback", "linklocal"], 9 "trust_proxy": ["loopback", "linklocal"],
10 "port": 25614, 10 "port": 25614,
11 "dump": false 11 "dump": false
12 }, 12 },
13 "core": { 13 "core": {
14 "port": 25615, 14 "port": 25615,
15 "dump": false 15 "dump": false
16 }, 16 },
17 "apiserver": { 17 "apiserver": {
18 "port": 25617, 18 "port": 25617,
19 "apikey": "PLEASE_CHANGE_ME" 19 "apikey": "PLEASE_CHANGE_ME"
20 } 20 }
21 }, 21 },
22 22
23 "callback_sender": { 23 "callback_sender": {
24 "http_timeout_ms": 30000, 24 "http_timeout_ms": 30000,
25 "sleep_before_retry_ms": 10000, 25 "sleep_before_retry_ms": 10000,
26 "max_retry": 10 26 "max_retry": 10
27 }, 27 },
28 28
29 "terminals_with_location": [],
30
29 "# cluster": "Isi dengan boolean atau angka jumlah anak yang akan dibuat. Jika diisi boolean true, jumlah anak akan dihitung otomatis", 31 "# cluster": "Isi dengan boolean atau angka jumlah anak yang akan dibuat. Jika diisi boolean true, jumlah anak akan dihitung otomatis",
30 "cluster": false 32 "cluster": false
31 } 33 }
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('tektrans-logger'); 6 const logger = require('tektrans-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 const matrix = require('../../matrix'); 9 const matrix = require('../../matrix');
10 const dumper = require('../dumper'); 10 const dumper = require('../dumper');
11 11
12 const router = express.Router(); 12 const router = express.Router();
13 module.exports = router; 13 module.exports = router;
14 14
15 const terminalsWithLocation = Array.isArray(config.terminals_with_location)
16 ? config.terminals_with_location
17 .filter((item) => typeof item === 'string')
18 .map((item) => (item.trim().toLowerCase()))
19 : [];
20
15 function onInvalidParameter(missingParameter, req, res) { 21 function onInvalidParameter(missingParameter, req, res) {
16 logger.verbose(`${MODULE_NAME} 1536D577: Undefined ${missingParameter} parameter`, { 22 logger.verbose(`${MODULE_NAME} 1536D577: Undefined ${missingParameter} parameter`, {
17 xid: res.locals.xid, 23 xid: res.locals.xid,
18 ip: req.ip, 24 ip: req.ip,
19 terminal_name: req.body.terminal_name || req.query.terminal_name, 25 terminal_name: req.body.terminal_name || req.query.terminal_name,
20 request_id: req.body.request_id || req.query.request_id, 26 request_id: req.body.request_id || req.query.request_id,
21 product_name: req.body.product_name || req.query.product_name, 27 product_name: req.body.product_name || req.query.product_name,
22 destination: req.body.destination || req.query.destination, 28 destination: req.body.destination || req.query.destination,
23 }); 29 });
24 res.end('INVALID REQUEST'); 30 res.end('INVALID REQUEST');
25 } 31 }
26 32
27 function pagePrerequisite(req, res, next) { 33 function pagePrerequisite(req, res, next) {
28 if (!req.body) req.body = {}; 34 if (!req.body) req.body = {};
29 35
30 if (!req.body.terminal_name && !req.query.terminal_name) { 36 if (!req.body.terminal_name && !req.query.terminal_name) {
31 onInvalidParameter('terminal_name', req, res); 37 onInvalidParameter('terminal_name', req, res);
32 return; 38 return;
33 } 39 }
34 40
35 if (!req.body.password && !req.query.password) { 41 if (!req.body.password && !req.query.password) {
36 onInvalidParameter('password', req, res); 42 onInvalidParameter('password', req, res);
37 return; 43 return;
38 } 44 }
39 45
40 if (!req.body.request_id && !req.query.request_id) { 46 if (!req.body.request_id && !req.query.request_id) {
41 onInvalidParameter('request_id', req, res); 47 onInvalidParameter('request_id', req, res);
42 return; 48 return;
43 } 49 }
44 50
45 if (!req.body.product_name && !req.query.product_name) { 51 if (!req.body.product_name && !req.query.product_name) {
46 onInvalidParameter('product_name', req, res); 52 onInvalidParameter('product_name', req, res);
47 return; 53 return;
48 } 54 }
49 55
50 if (!req.body.destination && !req.query.destination) { 56 if (!req.body.destination && !req.query.destination) {
51 onInvalidParameter('destination', req, res); 57 onInvalidParameter('destination', req, res);
52 return; 58 return;
53 } 59 }
54 60
55 next(); 61 next();
56 } 62 }
57 63
58 async function pageIndex(req, res) { 64 async function pageIndex(req, res) {
59 const { xid } = res.locals; 65 const { xid } = res.locals;
60 66
61 const terminalName = `${req.body.terminal_name || req.query.terminal_name}@${req.ip.replace(/^::ffff:/, '')}`; 67 const terminalName = `${req.body.terminal_name || req.query.terminal_name}@${req.ip.replace(/^::ffff:/, '')}`;
62 68
69 const qs = {
70 terminal_name: terminalName,
71 password: req.body.password || req.query.password,
72 request_id: req.body.request_id || req.query.request_id,
73 product_name: req.body.product_name || req.query.product_name,
74 destination: req.body.destination || req.query.destination,
75 origin: config.name || 'HTTPGETX',
76 report_ip: config.listener.core.ip || null,
77 report_port: config.listener.core.port,
78 reverse_url: req.body.reverse_url || req.query.reverse_url || null,
79 };
80
81 if (terminalsWithLocation.indexOf(terminalName.toLowerCase()) >= 0) {
82 const location = req.body.location
83 || req.body.location_id
84 || req.query.location
85 || req.query.location_id;
86
87 if (location) {
88 qs.location = location;
89 }
90 }
91
63 matrix.core.sent += 1; 92 matrix.core.sent += 1;
64 93
65 const [err, coreResponse] = await coreapi({ 94 const [err, coreResponse] = await coreapi({
66 xid, 95 xid,
67 path: '/prepaid/buy', 96 path: '/prepaid/buy',
68 qs: { 97 qs,
69 terminal_name: terminalName,
70 password: req.body.password || req.query.password,
71 request_id: req.body.request_id || req.query.request_id,
72 product_name: req.body.product_name || req.query.product_name,
73 destination: req.body.destination || req.query.destination,
74 origin: config.name || 'HTTPGETX',
75 report_ip: config.listener.core.ip || null,
76 report_port: config.listener.core.port,
77 reverse_url: req.body.reverse_url || req.query.reverse_url || null,
78 },
79 }); 98 });
80 99
81 if (err || !coreResponse) { 100 if (err || !coreResponse) {
82 matrix.core.sent_failed += 1; 101 matrix.core.sent_failed += 1;
83 matrix.core.last_error = { 102 matrix.core.last_error = {
84 xid, 103 xid,
85 ts: new Date(), 104 ts: new Date(),
86 e: err, 105 e: err,
87 eCode: err.code, 106 eCode: err.code,
88 eMessage: err.message, 107 eMessage: err.message,
89 }; 108 };
90 109
91 logger.warn(`${MODULE_NAME} 8DEBE15F: ERROR on /prepaid/buy response`, { 110 logger.warn(`${MODULE_NAME} 8DEBE15F: ERROR on /prepaid/buy response`, {
92 xid, 111 xid,
93 err, 112 err,
94 coreResponseTypeof: typeof coreResponse, 113 coreResponseTypeof: typeof coreResponse,
95 coreResponse, 114 coreResponse,
96 }); 115 });
97 res.end('INVALID CORE RESPONSE'); 116 res.end('INVALID CORE RESPONSE');
98 117
99 dumper(xid, req, 'INVALID CORE RESPONSE'); 118 dumper(xid, req, 'INVALID CORE RESPONSE');
100 return; 119 return;
101 } 120 }
102 121
103 logger.verbose(`${MODULE_NAME} 2528A9B4: Got CORE response`, { 122 logger.verbose(`${MODULE_NAME} 2528A9B4: Got CORE response`, {
104 xid, 123 xid,
105 coreResponse, 124 coreResponse,
106 }); 125 });
107 126
108 const responseToPartner = { 127 const responseToPartner = {
109 httpgetx_xid: xid, 128 httpgetx_xid: xid,
110 request_id: coreResponse.request_id, 129 request_id: coreResponse.request_id,
111 transaction_id: coreResponse.transaction_id, 130 transaction_id: coreResponse.transaction_id,
112 transaction_date: coreResponse.transaction_date, 131 transaction_date: coreResponse.transaction_date,
113 store_name: coreResponse.store_name, 132 store_name: coreResponse.store_name,
114 terminal_name: coreResponse.terminal_name, 133 terminal_name: coreResponse.terminal_name,
115 product_name: coreResponse.product_name, 134 product_name: coreResponse.product_name,
116 destination: coreResponse.destination, 135 destination: coreResponse.destination,
117 rc: coreResponse.rc, 136 rc: coreResponse.rc,
118 sn: coreResponse.sn || undefined, 137 sn: coreResponse.sn || undefined,
119 amount: Number(coreResponse.amount) || undefined, 138 amount: Number(coreResponse.amount) || undefined,
120 ending_balance: Number(coreResponse.ending_balance) || undefined, 139 ending_balance: Number(coreResponse.ending_balance) || undefined,