diff --git a/package.json b/package.json index 96afb90..15cd73f 100644 --- a/package.json +++ b/package.json @@ -25,5 +25,9 @@ "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git", "soap": "^0.15.0", "winston": "^2.2.0" + }, + "devDependencies": { + "mocha": "^2.4.5", + "should": "^8.3.2" } } diff --git a/partner-kospinjasa.js b/partner-kospinjasa.js index 0c35784..9042321 100644 --- a/partner-kospinjasa.js +++ b/partner-kospinjasa.js @@ -1,5 +1,7 @@ var winston = require('winston'); var soap = require('soap'); +var crypto = require('crypto'); +var strftime = require('strftime'); var max_retry = 10; var sleep_before_retry = 5000; @@ -34,18 +36,57 @@ function topupRequest(task, retry) { retry = max_retry; } + var remoteProduct = task.remoteProduct.split(','); + soap.createClient(url, function(err, client) { - client.MyFunction(args, function(err, result) { - console.log(result); + var args = { + userName: config.h2h_out.userid, + productCode: remoteProduct[0] , + terminal: 'terminal0', + transactionType: '50', + billNumber: createBillNumber(task.destination), + amount: remoteProduct[1], + bit61: createBillNumber(task.destination), + reff: task.requestId, + timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()); + } + + client.billpayment(args, function(err, result) { + if (err) { + logger.warn('Error requesting service', {err: err}); + callbackReport(task.requestId, '68', 'something wrong'); + return; + } + + logger.info('Got result', {result: result}); + callbackReport(task.requestId, '68', 'got result'); }); }); } -function createSoapClient(url, callback) { - soap.createClient(url, function(err, client) { - callback(err, client); - }); +function createSignature(args, password) { + var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); + + var result = crypto.createHash('sha1').update( + args.userName + + passwordHash + + args.productCode + + args.terminal + + args.transactionType + + args.billNumber + + args.amount + + args.ref + + args.timestamp + ).digest().toString('hex'); + + return result; +} + +function createBillNumber(destination) { + return ("0000000000000" + destination).slice(-13); } exports.start = start; exports.topupRequest = topupRequest; +exports.createSignature = createSignature; +exports.createBillNumber = createBillNumber;