Commit bffc39e1f2ae6f5b9775a7d4c0fdaf3a8ef1479a

Authored by Adhidarma Hadiwinoto
1 parent b111328c0f
Exists in master

createServer

Showing 1 changed file with 29 additions and 2 deletions Side-by-side Diff

1 1 var xml2js = require('xml2js');
  2 +var request = require('request');
  3 +var http = require('http');
2 4  
3 5 var aaa;
4 6 var _callbackReport;
... ... @@ -63,7 +65,7 @@ function topupRequest(task) {
63 65 'Content-Type': 'text/xml',
64 66 'Content-Length': Buffer.byteLength(payload)
65 67 }
66   - }
  68 + };
67 69  
68 70 logger.verbose('Requesting to partner', {reqOpts: reqOpts, payload: payload});
69 71 var buffer = "";
... ... @@ -166,11 +168,36 @@ function composeTopupStatusMessage(pin, product, destination, requestId) {
166 168 product: product,
167 169 msisdn: destination,
168 170 refTrxid: requestId
169   - }}
  171 + }};
170 172  
171 173 return xmlBuilder.buildObject(data);
172 174 }
173 175  
  176 +function createServer() {
  177 + var httpServer = http.createServer(function(request, response) {
  178 +
  179 + logger.info('Got request from partner');
  180 +
  181 + var body = "";
  182 + req.on('data', function (chunk) {
  183 + body += chunk;
  184 + });
  185 +
  186 + req.on('end', function () {
  187 + res.writeHead(200);
  188 + res.end('OK');
  189 +
  190 + topupResponseHandler(body, null, callbackReport);
  191 +
  192 + });
  193 +
  194 + });
  195 +
  196 + httpServer.listen(config.h2h_out.listen_port, function() {
  197 + logger.info('HTTP Reverse/Report server listen on port ' + config.h2h_out.listen_port);
  198 + });
  199 +}
  200 +
174 201 exports.start = start;
175 202 exports.topupRequest = topupRequest;
176 203 exports.composeTopupStatusMessage = composeTopupStatusMessage;