Commit bc5bcfea87edf7c94b3274a282dece731c33c4b0
1 parent
ba873b76b4
Exists in
master
pendingLimitCount
Showing 1 changed file with 31 additions and 5 deletions Side-by-side Diff
partner-kospinjasa.js
... | ... | @@ -14,12 +14,14 @@ var max_retry = 10; |
14 | 14 | var sleep_before_retry = 5000; |
15 | 15 | |
16 | 16 | var config; |
17 | +var matrix; | |
17 | 18 | var callbackReport; |
18 | 19 | var aaa; |
19 | 20 | var logger; |
20 | 21 | var options; |
21 | 22 | var mongodb; |
22 | 23 | |
24 | + | |
23 | 25 | function start(_config, _callbackReport, options) { |
24 | 26 | config = _config; |
25 | 27 | callbackReport = _callbackReport |
... | ... | @@ -38,9 +40,27 @@ function start(_config, _callbackReport, options) { |
38 | 40 | }); |
39 | 41 | } |
40 | 42 | |
43 | + if (options && options.matrix) { | |
44 | + matrix = options.matrix; | |
45 | + } | |
46 | + | |
41 | 47 | initMongoClient(); |
42 | 48 | } |
43 | 49 | |
50 | +function callbackReportWrapper(requestId, responseCode, message, dontIncrement) { | |
51 | + callbackReport(requestId, responseCode, message); | |
52 | + | |
53 | + if (dontIncrement) { | |
54 | + return; | |
55 | + } | |
56 | + | |
57 | + try { | |
58 | + aaa.incrementStrikeStatus(responseCode); | |
59 | + } catch(err) { | |
60 | + logger.warn("Gagal aaa.incrementStrikeStatus: " + err); | |
61 | + } | |
62 | +} | |
63 | + | |
44 | 64 | function initMongoClient() { |
45 | 65 | if (!config || !config.mongodb || !config.mongodb.url) { |
46 | 66 | return; |
... | ... | @@ -120,11 +140,17 @@ function isMongoReady() { |
120 | 140 | } |
121 | 141 | |
122 | 142 | function topupRequest(task, retry) { |
143 | + if (config && config.globals && config.globals.reject_on_pending_count && matrix && matrix.strikeStatus && matrix.strikeStatus.pending) { | |
144 | + if (parseInt(config.globals.reject_on_pending_count) <= matrix.strikeStatus.pending) { | |
145 | + callbackReport(task.requestId, '13', 'Reject trx karena pending terlalu banyak'); | |
146 | + return; | |
147 | + } | |
148 | + } | |
149 | + | |
123 | 150 | task.ts = moment(task.timestamp, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss'); |
124 | 151 | task.ts_date = moment(task.timestamp, 'YYYYMMDDHHmmss').format('YYYY-MM-DD'); |
125 | 152 | |
126 | 153 | insertTaskToMongoDb(task); |
127 | - | |
128 | 154 | saldoCheck(billpayment, task); |
129 | 155 | } |
130 | 156 | |
... | ... | @@ -148,7 +174,7 @@ function saldoCheck(callback, task) { |
148 | 174 | var errorMessage = 'Error creating soap client for saldoCheck: ' + err; |
149 | 175 | |
150 | 176 | logger.warn(errorMessage, {err: err}); |
151 | - callbackReport(task.requestId, '40', errorMessage); | |
177 | + callbackReportWrapper(task.requestId, '40', errorMessage); | |
152 | 178 | pushResponseToMongoDb(task, {supplier: config.globals.gateway_name, raw: errorMessage}, '40'); |
153 | 179 | |
154 | 180 | return; |
... | ... | @@ -171,7 +197,7 @@ function saldoCheck(callback, task) { |
171 | 197 | var errorMessage = 'Error requesting saldoCheck: ' + err; |
172 | 198 | |
173 | 199 | logger.warn(errorMessage, {err: err}); |
174 | - callbackReport(task.requestId, '40', errorMessage); | |
200 | + callbackReportWrapper(task.requestId, '40', errorMessage); | |
175 | 201 | pushResponseToMongoDb(task, {supplier: config.globals.gateway_name, raw: errorMessage}, '40'); |
176 | 202 | } |
177 | 203 | |
... | ... | @@ -246,7 +272,7 @@ function billpayment(task, balance) { |
246 | 272 | var errorMessage = 'Error requesting service: ' + err; |
247 | 273 | |
248 | 274 | logger.warn(errorMessage, {err: err}); |
249 | - callbackReport(task.requestId, '68', errorMessage); | |
275 | + callbackReportWrapper(task.requestId, '68', errorMessage); | |
250 | 276 | pushResponseToMongoDb(task, {supplier: config.globals.gateway_name, raw: soapClient.lastResponse}, '68'); |
251 | 277 | |
252 | 278 | return; |
... | ... | @@ -418,7 +444,7 @@ function topupResponseHandler(task, response, balance, rawResponse) { |
418 | 444 | parsedResponse.MESSAGE = combinedMessage; |
419 | 445 | |
420 | 446 | logger.info('Got result: ' + message, {response: response}); |
421 | - callbackReport(task.requestId, st24rc, st24message + ' -- Prev Balance: ' + balance); | |
447 | + callbackReportWrapper(task.requestId, st24rc, st24message + ' -- Prev Balance: ' + balance); | |
422 | 448 | pushResponseToMongoDb(task, {supplier: config.globals.gateway_name, raw: rawResponse, parsed: parsedResponse}, st24rc); |
423 | 449 | } |
424 | 450 |