Commit 606e426dedb5050b3221a86bb3c4b687fd6af78b
1 parent
4d8e9c52c3
Exists in
master
reverse report processed
Showing 1 changed file with 63 additions and 0 deletions Side-by-side Diff
partner-simplepay.js
... | ... | @@ -310,6 +310,43 @@ function reverseReportHandler(body) { |
310 | 310 | logger.info('Got reverse report', {body: body}); |
311 | 311 | } |
312 | 312 | |
313 | +function _parseInfoFromReverseReport(info) { | |
314 | + let result; | |
315 | + try { | |
316 | + result = JSON.parse(info); | |
317 | + } | |
318 | + catch (e) { | |
319 | + logger.warn('Exception on parsing qs info as JSON', {info: info}); | |
320 | + } | |
321 | + | |
322 | + return result; | |
323 | +} | |
324 | + | |
325 | +function _createSnFromReverseReport(qs) { | |
326 | + let token = qs.serial; | |
327 | + if (token && typeof token === 'string') { | |
328 | + token = token.replace(/\W+/g, '-'); | |
329 | + | |
330 | + } | |
331 | + | |
332 | + let sn = token || '-'; | |
333 | + | |
334 | + const info = _parseInfoFromReverseReport(qs.info); | |
335 | + if (info) { | |
336 | + const cust_name = (typeof info.cust_name === 'string') ? info.cust_name.replace(/\W+/g, '-').replace(/^\W+/, '').replace(/\W+$/, '') : '-'; | |
337 | + const kelas = (typeof info.kelas === 'string') ? info.kelas.replace(/\W+/g, '-').replace(/^\W+/, '').replace(/\W+$/, '') : '-'; | |
338 | + const kwh = (typeof info.size === 'string') ? info.size.replace(/\W+/g, '-').replace(/^\W+/, '').replace(/\W+$/, '') : '-'; | |
339 | + | |
340 | + sn = [ | |
341 | + token || '-', | |
342 | + cust_name || '-', | |
343 | + kwh || '-' | |
344 | + ].join('/'); | |
345 | + } | |
346 | + | |
347 | + return sn; | |
348 | +} | |
349 | + | |
313 | 350 | function createReverseHttpServer() { |
314 | 351 | var httpServer = http.createServer(function(req, res) { |
315 | 352 | |
... | ... | @@ -328,6 +365,32 @@ function createReverseHttpServer() { |
328 | 365 | reverseReportHandler(body); |
329 | 366 | }); |
330 | 367 | |
368 | + if (!qs || !qs.request_id) { | |
369 | + return; | |
370 | + } | |
371 | + | |
372 | + let rc = '68'; | |
373 | + if (qs.trx_status === 'S') { | |
374 | + rc = '00'; | |
375 | + } | |
376 | + else if (qs.trx_status === 'R') { | |
377 | + rc = '40'; | |
378 | + } | |
379 | + | |
380 | + const sn = (rc === '00') ? _createSnFromReverseReport(qs) : null; | |
381 | + let msg = [ | |
382 | + qs.diag, | |
383 | + 'Status: ' + (qs.trx_status || '-') | |
384 | + 'Balance: ' + (qs.balance || '-'), | |
385 | + 'Harga: ' + (qs.harga || '-') | |
386 | + ].join('. '); | |
387 | + | |
388 | + if (sn) { | |
389 | + msg = 'SN=' + sn + '; ' + msg; | |
390 | + } | |
391 | + | |
392 | + callbackReport(qs.request_id, rc, msg); | |
393 | + | |
331 | 394 | }); |
332 | 395 | |
333 | 396 | httpServer.listen(config.h2h_out.listen_port, function() { |