Blame view
partner-kospinjasa.js
2.48 KB
1f837fd31
|
1 2 |
var winston = require('winston'); var soap = require('soap'); |
5a947e400
|
3 4 |
var crypto = require('crypto'); var strftime = require('strftime'); |
1f837fd31
|
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 |
var max_retry = 10; var sleep_before_retry = 5000; var config; var callbackReport; var aaa; var logger; var options; function start(_config, _callbackReport, options) { config = _config; callbackReport = _callbackReport if (options && options.aaa) { aaa = options.aaa; } if (options && options.logger) { logger = options.logger; } else { logger = new winston.Logger({ transports: [ new (winston.transports.Console)() ] }); } } function topupRequest(task, retry) { if (retry === undefined) { retry = max_retry; } |
5a947e400
|
38 |
var remoteProduct = task.remoteProduct.split(','); |
1f837fd31
|
39 |
soap.createClient(url, function(err, client) { |
5a947e400
|
40 41 42 43 44 45 46 47 48 |
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, |
35d3e5057
|
49 |
timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()), |
5a947e400
|
50 |
} |
35d3e5057
|
51 52 |
var signature = createSignature(args, config.h2h_out.password); args.signature = signature; |
5a947e400
|
53 54 55 56 57 58 59 60 61 |
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'); |
1f837fd31
|
62 63 64 |
}); }); } |
5a947e400
|
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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); |
1f837fd31
|
85 86 87 88 |
} exports.start = start; exports.topupRequest = topupRequest; |
5a947e400
|
89 90 |
exports.createSignature = createSignature; exports.createBillNumber = createBillNumber; |