Commit 9e047c12240b1d93d5e075b4dae92f7fa17e6cc5
1 parent
e2e928e50c
Exists in
master
saldoCheck
Showing 1 changed file with 58 additions and 21 deletions Side-by-side Diff
partner-kospinjasa.js
... | ... | @@ -39,10 +39,52 @@ function start(_config, _callbackReport, options) { |
39 | 39 | } |
40 | 40 | |
41 | 41 | function topupRequest(task, retry) { |
42 | - if (retry === undefined) { | |
43 | - retry = max_retry; | |
42 | + saldoCheck(billpayment, task); | |
43 | +} | |
44 | + | |
45 | +function saldoCheck(callback, task) { | |
46 | + | |
47 | + var params = { | |
48 | + userName: config.h2h_out.userid, | |
49 | + productCode: '00000' , | |
50 | + terminal: 'H2HIPN10', | |
51 | + transactionType: '61', | |
52 | + reff: Math.random() * 99999999; | |
53 | + timeStamp: strftime('%Y-%m-%d %H:%M:%S', new Date()) | |
44 | 54 | } |
45 | 55 | |
56 | + params.signature = createSignatureForSaldoCheck(params, config.h2h_out.password); | |
57 | + | |
58 | + logger.info('Requesting to service', {url: config.h2h_out.partner, params: params}); | |
59 | + soapClient.apih2h.apih2hPort.saldoCheck({ inputSaldo: params }, function(err, result) { | |
60 | + | |
61 | + logger.verbose( | |
62 | + 'Got saldoCheck response', | |
63 | + { | |
64 | + lastEndpoint: soapClient.lastEndpoint, | |
65 | + lastRequest: soapClient.lastRequest, | |
66 | + lastMessage: soapClient.lastMessage, | |
67 | + lastResponse: soapClient.lastResponse, | |
68 | + } | |
69 | + ); | |
70 | + | |
71 | + if (err) { | |
72 | + logger.warn('Error requesting saldoCheck', {err: err}); | |
73 | + } | |
74 | + | |
75 | + var balance; | |
76 | + logger.verbose('saldoCheck result', {result}); | |
77 | + | |
78 | + | |
79 | + if (task) {} | |
80 | + callback(task, balance); | |
81 | + } | |
82 | + }); | |
83 | + | |
84 | +} | |
85 | + | |
86 | +function billpayment(task, balance) { | |
87 | + | |
46 | 88 | var remoteProduct = task.remoteProduct.split(','); |
47 | 89 | var params = { |
48 | 90 | userName: config.h2h_out.userid, |
... | ... | @@ -59,12 +101,6 @@ function topupRequest(task, retry) { |
59 | 101 | var signature = createSignature(params, config.h2h_out.password); |
60 | 102 | params.signature = signature; |
61 | 103 | |
62 | - //topupRequestSoapDIY(task, params, retry); | |
63 | - topupRequestSoap(task, params, retry); | |
64 | -} | |
65 | - | |
66 | -function topupRequestSoap(task, params, retry) { | |
67 | - | |
68 | 104 | soap.createClient(config.h2h_out.partner, function(err, soapClient) { |
69 | 105 | |
70 | 106 | var _params = { |
... | ... | @@ -240,19 +276,6 @@ function topupResponseHandler(task, response) { |
240 | 276 | callbackReport(task.requestId, st24rc, st24message); |
241 | 277 | } |
242 | 278 | |
243 | -function topupRequestRetry(task) { | |
244 | - task.retry--; | |
245 | - | |
246 | - if (task.retry > 0) { | |
247 | - logger.info('Retrying in ' + sleepBeforeRetry + 's'); | |
248 | - setTimeout(topupRequest, sleepBeforeRetry * 1000, task, task.retry); | |
249 | - } | |
250 | - else { | |
251 | - logger.warn('Maximum retry for pending status exceeded', {task: task}); | |
252 | - } | |
253 | -} | |
254 | - | |
255 | - | |
256 | 279 | function createSignature(params, password) { |
257 | 280 | var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); |
258 | 281 | var plain = |
... | ... | @@ -269,6 +292,20 @@ function createSignature(params, password) { |
269 | 292 | return crypto.createHash('sha1').update(plain).digest().toString('hex'); |
270 | 293 | } |
271 | 294 | |
295 | +function createSignatureForSaldoCheck(params, password) { | |
296 | + var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); | |
297 | + var plain = | |
298 | + params.userName | |
299 | + + passwordHash | |
300 | + + params.productCode | |
301 | + + params.terminal | |
302 | + + params.transactionType | |
303 | + + params.reff | |
304 | + + params.timeStamp; | |
305 | + | |
306 | + return crypto.createHash('sha1').update(plain).digest().toString('hex'); | |
307 | +} | |
308 | + | |
272 | 309 | function createBillNumber(destination) { |
273 | 310 | return ("0000000000000" + destination).slice(-13); |
274 | 311 | } |