xmlout.js
3.74 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var xmlrpc = require('xmlrpc');
var url = require('url');
var config;
var callbackReport;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
function topupRequest(task) {
var partnerUrl = url.parse(config.h2h_out.partner);
var clientOptions = {
host: partnerUrl.hostname
, port: partnerUrl.port
, path: partnerUrl.pathname
};
console.log('XMLRPC client options:');
console.log(clientOptions);
var client;
if (partnerUrl.protocol == 'https:') {
console.log('Use SSL');
client = xmlrpc.createSecureClient(clientOptions);
} else {
console.log('Not using SSL');
client = xmlrpc.createClient(clientOptions);
}
var methodName = 'topUpRequest';
console.log('methodName: ' + methodName);
var params = {
MSISDN: config.h2h_out.userid,
REQUESTID: task['requestId'],
PIN: config.h2h_out.password,
NOHP: task['destination'],
NOM: task['remoteProduct']
};
console.log('PARAMS:');
console.log(params);
client.methodCall(methodName, [ params ], function (error, value) {
// Results of the method response
if (error) {
console.log('Error: ');
console.log(error);
return;
}
console.log('Method response for \'' + methodName + '\': ')
console.log(value);
callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
});
}
function createServer() {
console.log('Creating XML-RPC server on port ' + config.h2h_out.listen_port);
var serverOptions = {
port: config.h2h_out.listen_port
};
var server = xmlrpc.createServer(serverOptions);
server.on('NotFound', function (method, params) {
console.log(method + ' is not found on our XML-RPC server');
console.log('params:');
console.log(params);
});
server.on('topUpReport', function (err, params, callback) {
console.log('RECEIVE topUpReport, params:');
console.log(params);
var paramscount = params.length;
for (var i = 0; i < paramscount; i++) {
var value = params[i];
callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
}
callback(null, 'ACK REPORT OK');
})
}
function checkStatus(task) {
var partnerUrl = url.parse(config.h2h_out.partner);
var clientOptions = {
host: partnerUrl.hostname
, port: partnerUrl.port
, path: partnerUrl.pathname
};
console.log('XMLRPC client options:');
console.log(clientOptions);
var client;
if (partnerUrl.protocol == 'https:') {
console.log('Use SSL');
client = xmlrpc.createSecureClient(clientOptions);
} else {
console.log('Not using SSL');
client = xmlrpc.createClient(clientOptions);
}
var methodName = 'topUpInquiry';
console.log('methodName: ' + methodName);
var params = {
MSISDN: config.h2h_out.userid,
REQUESTID: task['requestId'],
PIN: config.h2h_out.password,
NOHP: task['destination']
};
console.log('PARAMS:');
console.log(params);
client.methodCall(methodName, [ params ], function (error, value) {
// Results of the method response
if (error) {
console.log('Error: ');
console.log(error);
return;
}
console.log('Method response for \'' + methodName + '\': ')
console.log(value);
callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
});
}
function start(_config, _callbackReport) {
config = _config;
callbackReport = _callbackReport
createServer();
}
exports.start = start;
exports.topupRequest = topupRequest;