reverse-report.js
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
const xmlrpc = require('xmlrpc');
const stringify = require("json-stringify-pretty-compact");
const config = require('komodo-sdk/config');
const logger = require('komodo-sdk/logger');
const matrix = require('komodo-sdk/matrix');
const st24 = require('./st24');
const partner = require('./partner');
// const partnerRc = require('./partner-rc.json');
function create() {
if (!config || !config.reverse_report_port) {
logger.info('Not creating reverse report server because of undefined config.reverse_report_port');
return;
}
const server = xmlrpc.createServer({ port: config.reverse_report_port });
logger.info('Reverse report server listen on port ' + config.reverse_report_port);
server.on('NotFound', function (method, params) {
logger.warn('REVERSEREPORT: Unknown method recevied on XMLRPC server', {method: method, params: params});
});
server.on('topUpReport', function (err, params, callback) {
logger.info('REVERSEREPORT: Got XMLRPC topUpReport request from partner', {method: 'topUpReport', params: params});
matrix.last_topupReport_params = params;
const paramsCount = params.length;
for (let i = 0; i < paramsCount; i++) {
let value = params[i];
partner.report({
trx_id: value.REQUESTID,
// rc: partnerRc[value.RESPONSECODE] || '40',
rc: partner.komodoRc(value[partner.RESPONSECODE_TAG]) || '40',
//message: value.MESSAGE,
message: 'topUpReport: ' + stringify(value),
sn: (value.SN || '').replace(/;+$/, '').replace(/#+$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern),
amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern),
balance: st24.extractBalanceFromMsg(value.MESSAGE, config.balance_pattern),
raw: value,
misc: {
}
});
}
callback(null, 'ACK REPORT OK');
})
}
create();