Compare View
Commits (2)
Changes
Showing 3 changed files Side-by-side Diff
index.js
... | ... | @@ -4,5 +4,7 @@ process.chdir(__dirname); |
4 | 4 | const pullgw = require('komodo-sdk/gateway/pull'); |
5 | 5 | const partner = require('./lib/partner'); |
6 | 6 | const reverseReport = require('./lib/reverse-report'); |
7 | +const adviceServer = require('komodo-sdk/gateway/advice-push-server'); | |
7 | 8 | |
8 | 9 | pullgw.setPartner(partner); |
10 | +adviceServer.setPartner(partner); |
lib/partner.js
... | ... | @@ -91,6 +91,64 @@ function buy(task) { |
91 | 91 | } |
92 | 92 | |
93 | 93 | function advice(task) { |
94 | + const partnerUrl = url.parse(config.partner.url); | |
95 | + const clientOptions = { | |
96 | + host: partnerUrl.hostname, | |
97 | + port: partnerUrl.port, | |
98 | + path: partnerUrl.pathname | |
99 | + }; | |
100 | + | |
101 | + let client; | |
102 | + if (partnerUrl.protocol == 'https:') { | |
103 | + client = xmlrpc.createSecureClient(clientOptions); | |
104 | + } else { | |
105 | + client = xmlrpc.createClient(clientOptions); | |
106 | + } | |
107 | + | |
108 | + const params = { | |
109 | + REQUESTID: task.trx_id, | |
110 | + MSISDN: config.partner.msisdn || config.partner.userid, | |
111 | + PIN: config.partner.pin || config.partner.password, | |
112 | + NOHP: task.destination | |
113 | + }; | |
114 | + | |
115 | + const xmlrpcMethod = 'topUpInquiry'; | |
116 | + logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); | |
117 | + | |
118 | + client.methodCall(xmlrpcMethod, [ params ], function (err, value) { | |
119 | + | |
120 | + if (err) { | |
121 | + | |
122 | + const msg = 'XMLRPC Client Error: ' + err; | |
123 | + | |
124 | + logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); | |
125 | + report({ | |
126 | + trx_id: task.trx_id, | |
127 | + rc: '68', | |
128 | + message: 'INTERNAL: ' + msg, | |
129 | + misc: { | |
130 | + task: task | |
131 | + } | |
132 | + }); | |
133 | + | |
134 | + return; | |
135 | + } | |
136 | + | |
137 | + logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); | |
138 | + //matrix.last_topupRequest_ack = value; | |
139 | + | |
140 | + report({ | |
141 | + trx_id: task.trx_id, | |
142 | + rc: partnerRc[value.RESPONSECODE] || '40', | |
143 | + message: value.MESSAGE, | |
144 | + sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE), | |
145 | + amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), | |
146 | + raw: value, | |
147 | + misc: { | |
148 | + task: task | |
149 | + } | |
150 | + }); | |
151 | + }); | |
94 | 152 | } |
95 | 153 | |
96 | 154 | function report(data) { |