diff --git a/partner-datacell.js b/partner-datacell.js index 0a1784c..128e142 100644 --- a/partner-datacell.js +++ b/partner-datacell.js @@ -20,6 +20,14 @@ function calculateSignature(userid, password, msisdn, timestamp) { return xor.encode(a,b); } +function calculateBalanceSignature(userid, password, timestamp) { + var a = '0000' + timestamp; + var b = userid.substr(0, 4) + password; + + return xor.encode(a,b); +} + + function createPayload(task) { var timestamp = strftime('%H%M%S'); @@ -189,6 +197,51 @@ function createServer() { }); } +function balanceCheck() { + var timestamp = strftime('%H%M%S'); + + var payload = { + datacell: [ + {perintah: 'saldo'}, + {userid: config.h2h_out.userid}, + {time: timestamp}, + {sgn: calculateBalanceSignature(config.h2h_out.userid, config.h2h_out.password, timestamp)} + ] + }; + + var postRequest = { + host: "202.152.62.2", + path: "/RELOAD97.php", + port: 7713, + method: "POST", + headers: { + 'Content-Type': 'text/xml', + 'Content-Length': Buffer.byteLength(payload_xml) + } + }; + + var buffer = ""; + var req = http.request( postRequest, function( res ) { + + console.log('Status code: ' + res.statusCode ); + var buffer = ""; + res.on( "data", function( data ) { buffer = buffer + data; } ); + res.on( "end", function( data ) { + console.log('CHECK BALANCE RESULT:'); + console.log(buffer); + }); + + }); + + req.on('error', function(e) { + console.log('problem with request: ' + e.message); + }); + + req.write( payload_xml ); + req.end(); + +} + function start(_config, _callbackReport) { config = _config;