Commit 59b806630b1baa7a4135be253c95e56c0971b98c
1 parent
60d4b3934e
Exists in
master
reverse report post method
Showing 1 changed file with 52 additions and 4 deletions Side-by-side Diff
partner-simplepay.js
... | ... | @@ -306,8 +306,50 @@ function checkStatus(task) { |
306 | 306 | } |
307 | 307 | |
308 | 308 | |
309 | -function reverseReportHandler(body) { | |
310 | - logger.info('Got reverse report', {body: body}); | |
309 | +function reverseReportHandler(data) { | |
310 | + //logger.info('Got reverse report', {body: body}); | |
311 | + | |
312 | + const qs = URL.parse(data, true).query; | |
313 | + | |
314 | + if (!qs || !qs.request_id) { | |
315 | + return; | |
316 | + } | |
317 | + | |
318 | + if ((typeof qs.balance === 'string') && qs.balance && aaa.updateBalance) { | |
319 | + const balance = qs.balance.replace(/\D/g, ''); | |
320 | + if (balance) { | |
321 | + aaa.updateBalance(balance); | |
322 | + } | |
323 | + } | |
324 | + | |
325 | + | |
326 | + let rc = '68'; | |
327 | + if (qs.trx_status === 'S') { | |
328 | + rc = '00'; | |
329 | + } | |
330 | + else if (qs.trx_status === 'R') { | |
331 | + rc = '40'; | |
332 | + } | |
333 | + | |
334 | + if ((typeof qs.serial === 'string') && qs.serial) { | |
335 | + rc = '00'; | |
336 | + } | |
337 | + | |
338 | + const sn = (rc === '00') ? _createSnFromReverseReport(qs) : null; | |
339 | + let msg = [ | |
340 | + 'REVERSE REPORT', | |
341 | + 'Diag: ' + (qs.diag + '-'), | |
342 | + 'Message': + (qs.message || '-'), | |
343 | + 'Status: ' + (qs.trx_status || '-'), | |
344 | + 'Balance: ' + (qs.balance || '-'), | |
345 | + 'Harga: ' + (qs.harga || '-') | |
346 | + ].join('. '); | |
347 | + | |
348 | + if (sn) { | |
349 | + msg = 'SN=' + sn + '; ' + msg; | |
350 | + } | |
351 | + | |
352 | + callbackReport(qs.request_id, rc, msg); | |
311 | 353 | } |
312 | 354 | |
313 | 355 | function _parseInfoFromReverseReport(info) { |
... | ... | @@ -350,7 +392,6 @@ function _createSnFromReverseReport(qs) { |
350 | 392 | function createReverseHttpServer() { |
351 | 393 | var httpServer = http.createServer(function(req, res) { |
352 | 394 | |
353 | - const qs = URL.parse(req.url, true).query; | |
354 | 395 | logger.info('Got request from partner (reverse report)', {remote_address: req.connection.remoteAddress, url: req.url, qs: qs}); |
355 | 396 | |
356 | 397 | var body = ""; |
... | ... | @@ -362,9 +403,16 @@ function createReverseHttpServer() { |
362 | 403 | res.writeHead(200); |
363 | 404 | res.end('OK'); |
364 | 405 | |
365 | - reverseReportHandler(body); | |
406 | + logger.info('Got reverse report', {body: body}); | |
407 | + | |
408 | + reverseReportHandler('?' + body); | |
366 | 409 | }); |
367 | 410 | |
411 | + return; | |
412 | + | |
413 | + const qs = URL.parse(req.url, true).query; | |
414 | + | |
415 | + | |
368 | 416 | if (!qs || !qs.request_id) { |
369 | 417 | return; |
370 | 418 | } |