Commit 107ff7b0f6128093e27e3daa1b0f63173b2bc4c6
1 parent
caeb5ddbc6
Exists in
master
easysoap
Showing 1 changed file with 22 additions and 14 deletions Inline Diff
partner-kospinjasa.js
1 | var winston = require('winston'); | 1 | var winston = require('winston'); |
2 | var soap = require('soap'); | 2 | var soap = require('soap'); |
3 | var crypto = require('crypto'); | 3 | var crypto = require('crypto'); |
4 | var strftime = require('strftime'); | 4 | var strftime = require('strftime'); |
5 | var easysoap = require('easysoap'); | 5 | var easysoap = require('easysoap'); |
6 | 6 | ||
7 | var max_retry = 10; | 7 | var max_retry = 10; |
8 | var sleep_before_retry = 5000; | 8 | var sleep_before_retry = 5000; |
9 | 9 | ||
10 | var config; | 10 | var config; |
11 | var callbackReport; | 11 | var callbackReport; |
12 | var aaa; | 12 | var aaa; |
13 | var logger; | 13 | var logger; |
14 | var options; | 14 | var options; |
15 | 15 | ||
16 | function start(_config, _callbackReport, options) { | 16 | function start(_config, _callbackReport, options) { |
17 | config = _config; | 17 | config = _config; |
18 | callbackReport = _callbackReport | 18 | callbackReport = _callbackReport |
19 | 19 | ||
20 | if (options && options.aaa) { | 20 | if (options && options.aaa) { |
21 | aaa = options.aaa; | 21 | aaa = options.aaa; |
22 | } | 22 | } |
23 | 23 | ||
24 | if (options && options.logger) { | 24 | if (options && options.logger) { |
25 | logger = options.logger; | 25 | logger = options.logger; |
26 | } else { | 26 | } else { |
27 | logger = new winston.Logger({ | 27 | logger = new winston.Logger({ |
28 | transports: [ | 28 | transports: [ |
29 | new (winston.transports.Console)() | 29 | new (winston.transports.Console)() |
30 | ] | 30 | ] |
31 | }); | 31 | }); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | function topupRequest(task, retry) { | 35 | function topupRequest(task, retry) { |
36 | if (retry === undefined) { | 36 | if (retry === undefined) { |
37 | retry = max_retry; | 37 | retry = max_retry; |
38 | } | 38 | } |
39 | 39 | ||
40 | var remoteProduct = task.remoteProduct.split(','); | 40 | var remoteProduct = task.remoteProduct.split(','); |
41 | var args = { | 41 | var args = { |
42 | userName: config.h2h_out.userid, | 42 | userName: config.h2h_out.userid, |
43 | productCode: remoteProduct[0] , | 43 | productCode: remoteProduct[0] , |
44 | terminal: 'terminal0', | 44 | terminal: 'terminal0', |
45 | transactionType: '50', | 45 | transactionType: '50', |
46 | billNumber: createBillNumber(task.destination), | 46 | billNumber: createBillNumber(task.destination), |
47 | amount: remoteProduct[1], | 47 | amount: remoteProduct[1], |
48 | bit61: createBillNumber(task.destination), | 48 | bit61: createBillNumber(task.destination), |
49 | reff: task.requestId, | 49 | reff: task.requestId, |
50 | timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()), | 50 | timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()), |
51 | } | 51 | } |
52 | 52 | ||
53 | var signature = createSignature(args, config.h2h_out.password); | 53 | var signature = createSignature(args, config.h2h_out.password); |
54 | args.signature = signature; | 54 | args.signature = signature; |
55 | 55 | ||
56 | topupRequestEasySoap(task, args, retry); | 56 | topupRequestEasySoap(task, args, retry); |
57 | } | 57 | } |
58 | 58 | ||
59 | function topupRequestEasySoap(task, args, retry) { | 59 | function topupRequestEasySoap(task, args, retry) { |
60 | //partner=http://203.130.243.155/ApiH2H/index.php?wsdl | 60 | //partner=http://203.130.243.155/ApiH2H/index.php?wsdl |
61 | 61 | ||
62 | var params = { | 62 | var clientParams = { |
63 | host: '203.130.243.155', | 63 | host: '203.130.243.155', |
64 | path: '/ApiH2H/index.php', | 64 | path: '/ApiH2H/index.php', |
65 | wsdl: '/ApiH2H/index.php?wsdl' | 65 | wsdl: '/ApiH2H/index.php?wsdl' |
66 | } | 66 | } |
67 | 67 | ||
68 | var soapClient = easysoap.createClient(params); | 68 | var clientOptions { |
69 | soapClient.call({ | 69 | secure: false, |
70 | method: 'billpayment', | 70 | } |
71 | params: args, | ||
72 | }) | ||
73 | .then((callResponse) => { | ||
74 | console.log(callResponse.data); // response data as json | ||
75 | console.log(callResponse.body); // response body | ||
76 | console.log(callResponse.header); //response header | ||
77 | }) | ||
78 | .catch((err) => { throw new Error(err); }); | ||
79 | |||
80 | callbackReport(task.requestId, '68', 'debug'); | ||
81 | 71 | ||
72 | var soapClient = new easysoap.Client(clientParams, clientOptions); | ||
73 | soapClient.call( | ||
74 | {method: 'billpayment', params: args} | ||
75 | ).done( | ||
76 | //success | ||
77 | function(res) { | ||
78 | res.data // response data as array | ||
79 | res.response // full response data (including xml) | ||
80 | res.header // response header | ||
81 | }, | ||
82 | |||
83 | //method fail | ||
84 | function(err) { | ||
85 | console.log(err); | ||
86 | } | ||
87 | ); | ||
88 | |||
89 | callbackReport(task.requestId, '68', 'debug'); | ||
82 | } | 90 | } |
83 | 91 | ||
84 | function topupRequestSoap(task, args, retry) { | 92 | function topupRequestSoap(task, args, retry) { |
85 | 93 | ||
86 | soap.createClient(config.h2h_out.partner, function(err, client) { | 94 | soap.createClient(config.h2h_out.partner, function(err, client) { |
87 | 95 | ||
88 | logger.info('Requesting to service', {url: config.h2h_out.partner, args: args}); | 96 | logger.info('Requesting to service', {url: config.h2h_out.partner, args: args}); |
89 | 97 | ||
90 | client.apih2h.apih2hPort.billpayment(args, function(err, result) { | 98 | client.apih2h.apih2hPort.billpayment(args, function(err, result) { |
91 | if (err) { | 99 | if (err) { |
92 | logger.warn('Error requesting service', {err: err}); | 100 | logger.warn('Error requesting service', {err: err}); |
93 | callbackReport(task.requestId, '68', 'something wrong'); | 101 | callbackReport(task.requestId, '68', 'something wrong'); |
94 | return; | 102 | return; |
95 | } | 103 | } |
96 | 104 | ||
97 | var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value; | 105 | var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value; |
98 | 106 | ||
99 | logger.info('Got result: ' + responseMessageToST24, {result: result}); | 107 | logger.info('Got result: ' + responseMessageToST24, {result: result}); |
100 | 108 | ||
101 | callbackReport(task.requestId, '68', responseMessageToST24); | 109 | callbackReport(task.requestId, '68', responseMessageToST24); |
102 | }); | 110 | }); |
103 | }); | 111 | }); |
104 | } | 112 | } |
105 | 113 | ||
106 | 114 | ||
107 | 115 | ||
108 | function createSignature(args, password) { | 116 | function createSignature(args, password) { |
109 | var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); | 117 | var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); |
110 | 118 | ||
111 | var plain = | 119 | var plain = |
112 | args.userName | 120 | args.userName |
113 | + passwordHash | 121 | + passwordHash |
114 | + args.productCode | 122 | + args.productCode |
115 | + args.terminal | 123 | + args.terminal |
116 | + args.transactionType | 124 | + args.transactionType |
117 | + args.billNumber | 125 | + args.billNumber |
118 | + args.amount | 126 | + args.amount |
119 | + args.reff | 127 | + args.reff |
120 | + args.timeStamp; | 128 | + args.timeStamp; |
121 | 129 | ||
122 | var result = crypto.createHash('sha1').update(plain).digest().toString('hex'); | 130 | var result = crypto.createHash('sha1').update(plain).digest().toString('hex'); |
123 | 131 | ||
124 | if (logger) { | 132 | if (logger) { |
125 | logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password}); | 133 | logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password}); |
126 | } | 134 | } |
127 | 135 | ||
128 | return result; | 136 | return result; |
129 | } | 137 | } |