Commit 010de7b46d020466f311e1182bdaecba8a4b3ed6

Authored by Adhidarma Hadiwinoto
1 parent 9e7d5d4281
Exists in master

94 jd 68

Showing 1 changed file with 48 additions and 37 deletions Side-by-side Diff

... ... @@ -21,20 +21,20 @@ function topupRequest(task, retry) {
21 21 } else {
22 22 config.globals.requests_count++;
23 23 }
24   -
  24 +
25 25 if (config.globals.active_requests_count == undefined) {
26 26 config.globals.active_requests_count = 1;
27 27 } else {
28 28 config.globals.active_requests_count++;
29 29 }
30   -
  30 +
31 31 if (config.globals.max_active_requests_count == undefined) {
32 32 config.globals.max_active_requests_count = config.globals.active_requests_count;
33 33 } else {
34 34 config.globals.max_active_requests_count = math.max(config.globals.max_active_requests_count, config.globals.active_requests_count);
35 35 }
36   -
37   - /*
  36 +
  37 + /*
38 38 if (retry === undefined) {
39 39 retry = max_retry;
40 40 }
... ... @@ -54,7 +54,7 @@ function topupRequest(task, retry) {
54 54 } else {
55 55 client = xmlrpc.createClient(clientOptions);
56 56 }
57   -
  57 +
58 58 var params = {
59 59 MSISDN: config.h2h_out.userid,
60 60 REQUESTID: task['requestId'],
... ... @@ -62,42 +62,47 @@ function topupRequest(task, retry) {
62 62 NOHP: task['destination'],
63 63 NOM: task['remoteProduct']
64 64 };
65   -
  65 +
66 66 var methodName = 'topUpRequest';
67 67 logger.info('Preparing XMLRPC client method', {methodname: methodName, params: params});
68 68  
69 69 client.methodCall(methodName, [ params ], function (error, value) {
70   -
  70 +
71 71 if (config.globals.active_requests_count == undefined) {
72 72 config.globals.active_requests_count = 0;
73 73 } else {
74 74 config.globals.active_requests_count--;
75 75 }
76   -
  76 +
77 77 // Results of the method response
78 78 if (error) {
79   -
  79 +
80 80 logger.warn('XMLRPC Client Error', {requestId: task['requestId'], errorMessage: error});
81   -
  81 +
82 82 if (retry) {
83   -
  83 +
84 84 logger.info('Retrying topUpRequest (' + retry + ')');
85 85 setTimeout(function() {
86 86 topupRequest(task, retry - 1);
87 87 }, sleep_before_retry);
88   -
  88 +
89 89 } else {
90 90 callbackReport(task['requestId'], '91', 'Gangguan koneksi ke suplier: ' + error);
91 91 }
92 92 return;
93 93 }
94   -
  94 +
95 95 logger.info('Got XMLRPC response from partner for', {response_method: methodName, response_message: value});
96   -
  96 +
  97 + if (value['RESPONSECODE'] == '94') {
  98 + logger.info('Change RC 94 to 68');
  99 + value['RESPONSECODE'] = '68';
  100 + }
  101 +
97 102 if (value['RESPONSECODE'] == '00' && config.h2h_out.parse_sn == 'YES') {
98 103 value['MESSAGE'] = 'SN=' + parseSN(value['MESSAGE']) + '; ' + value['MESSAGE'];
99 104 }
100   -
  105 +
101 106 callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
102 107 });
103 108 }
... ... @@ -116,16 +121,22 @@ function createServer() {
116 121 });
117 122  
118 123 server.on('topUpReport', function (err, params, callback) {
119   -
  124 +
120 125 logger.info('Got XMLRPC topUpReport request from partner', {xmlrpc_method: 'topUpReport', xmlrpc_params: params});
121   -
  126 +
122 127 var paramscount = params.length;
123 128 for (var i = 0; i < paramscount; i++) {
124 129 var value = params[i];
125   -
  130 +
  131 + if (value['RESPONSECODE'] == '94') {
  132 + logger.info('Change RC 94 to 68');
  133 + value['RESPONSECODE'] = '68';
  134 + }
  135 +
126 136 if (value['RESPONSECODE'] == '00' && config.h2h_out.parse_sn == 'YES') {
127 137 value['MESSAGE'] = 'SN=' + parseSN(value['MESSAGE']) + '; ' + value['MESSAGE'];
128 138 }
  139 +
129 140 callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
130 141 }
131 142  
... ... @@ -140,20 +151,20 @@ function getBalanceFromMessage(message, balance_regex) {
140 151 balance_regex = config.globals.balance_regex;
141 152 }
142 153 }
143   -
  154 +
144 155 if (!balance_regex) {
145 156 return;
146 157 }
147   -
  158 +
148 159 try {
149 160 var re = new RegExp(balance_regex);
150 161 var matches = message.match(re);
151   -
  162 +
152 163 var result = matches[1];
153 164 result = result.replace(/\./g, '');
154 165 result = result.replace(/,/g, '');
155   -
156   -
  166 +
  167 +
157 168 return Number(result);
158 169 }
159 170 catch(err) {
... ... @@ -214,11 +225,11 @@ function checkStatus(task) {
214 225 function start(_config, _callbackReport, options) {
215 226 config = _config;
216 227 callbackReport = _callbackReport;
217   -
  228 +
218 229 if (options && options.aaa) {
219 230 aaa = options.aaa;
220 231 }
221   -
  232 +
222 233 if (options && options.logger) {
223 234 logger = options.logger;
224 235 } else {
... ... @@ -233,46 +244,46 @@ function start(_config, _callbackReport, options) {
233 244 }
234 245  
235 246 function parseSN(message, _config) {
236   -
  247 +
237 248 if (!_config) {
238 249 _config = config;
239 250 }
240   -
  251 +
241 252 var sn_regex = new RegExp(_config.h2h_out.sn_pattern);
242 253 var sn_match = message.match(sn_regex);
243   -
  254 +
244 255 if (sn_match <= 0) {
245 256 logger.info('SN Not found: ' + message);
246 257 return '';
247 258 }
248   -
  259 +
249 260 var match_index = 0;
250 261 if (_config.h2h_out.sn_match_index) {
251 262 match_index = Number(_config.h2h_out.sn_match_index)
252 263 }
253   -
  264 +
254 265 var sn = sn_match[match_index];
255   -
  266 +
256 267 if (_config.h2h_out.sn_remove_whitespace) {
257 268 sn = sn.replace(/\s/g, '');
258 269 }
259   -
  270 +
260 271 var sn_remove_patterns = [];
261 272 if (_config.h2h_out.sn_remove_patterns && _config.h2h_out.sn_remove_patterns_separator) {
262 273 sn_remove_patterns = _config.h2h_out.sn_remove_patterns.split(_config.h2h_out.sn_remove_patterns_separator);
263 274 }
264 275 var count = sn_remove_patterns.length;
265   -
  276 +
266 277 for(var i = 0; i < count; i++) {
267   -
  278 +
268 279 //sn = sn.replace(sn_remove_patterns[i], '');
269   -
  280 +
270 281 var re = new RegExp(sn_remove_patterns[i], 'g');
271 282 sn = sn.replace(re, '');
272 283 }
273   -
  284 +
274 285 //sn = paddingSN(sn, _config);
275   -
  286 +
276 287 return sn.trim();
277 288 }
278 289