Blame view
partner-kospinjasa.js
3.73 KB
1f837fd31
|
1 2 |
var winston = require('winston'); var soap = require('soap'); |
5a947e400
|
3 4 |
var crypto = require('crypto'); var strftime = require('strftime'); |
7f796c813
|
5 |
var easysoap = require('easysoap'); |
1f837fd31
|
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 38 |
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
|
39 |
var remoteProduct = task.remoteProduct.split(','); |
7f796c813
|
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
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()), } var signature = createSignature(args, config.h2h_out.password); args.signature = signature; topupRequestEasySoap(task, args, retry); } function topupRequestEasySoap(task, args, retry) { //partner=http://203.130.243.155/ApiH2H/index.php?wsdl var params = { host: '203.130.243.155', path: '/ApiH2H/index.php' wsdl: '/ApiH2H/index.php?wsdl' } var soapClient = easysoap.createClient(params); soapClient.call({ method: 'billpayment', params: args, }) .then((callResponse) => { console.log(callResponse.data); // response data as json console.log(callResponse.body); // response body console.log(callResponse.header); //response header }) .catch((err) => { throw new Error(err); }); callbackReport(task.requestId, '68', 'debug'); } function topupRequestSoap(task, args, retry) { |
5a947e400
|
84 |
|
2b3124a96
|
85 |
soap.createClient(config.h2h_out.partner, function(err, client) { |
35d3e5057
|
86 |
|
2b3124a96
|
87 |
logger.info('Requesting to service', {url: config.h2h_out.partner, args: args}); |
73c4fa043
|
88 89 |
client.apih2h.apih2hPort.billpayment(args, function(err, result) { |
5a947e400
|
90 91 92 93 94 |
if (err) { logger.warn('Error requesting service', {err: err}); callbackReport(task.requestId, '68', 'something wrong'); return; } |
73c4fa043
|
95 96 97 98 99 |
var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value; logger.info('Got result: ' + responseMessageToST24, {result: result}); callbackReport(task.requestId, '68', responseMessageToST24); |
1f837fd31
|
100 101 102 |
}); }); } |
7f796c813
|
103 |
|
5a947e400
|
104 105 |
function createSignature(args, password) { var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); |
dfcc535b5
|
106 |
var plain = |
5a947e400
|
107 108 109 110 111 112 113 |
args.userName + passwordHash + args.productCode + args.terminal + args.transactionType + args.billNumber + args.amount |
dfcc535b5
|
114 115 116 117 |
+ args.reff + args.timeStamp; var result = crypto.createHash('sha1').update(plain).digest().toString('hex'); |
5a947e400
|
118 |
|
371375d72
|
119 |
if (logger) { |
cb466883c
|
120 |
logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password}); |
371375d72
|
121 |
} |
5a947e400
|
122 123 124 125 126 |
return result; } function createBillNumber(destination) { return ("0000000000000" + destination).slice(-13); |
1f837fd31
|
127 128 129 130 |
} exports.start = start; exports.topupRequest = topupRequest; |
5a947e400
|
131 132 |
exports.createSignature = createSignature; exports.createBillNumber = createBillNumber; |