Blame view

partner-kospinjasa.js 7.98 KB
1f837fd31   Adhidarma Hadiwinoto   on progress
1
2
  var winston = require('winston');
  var soap = require('soap');
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
3
4
  var crypto = require('crypto');
  var strftime = require('strftime');
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
5
6
7
  var fs = require("fs");
  var whiskers = require("whiskers");
  var http = require("http");
e7d59da25   Adhidarma Hadiwinoto   require url
8
  var url = require("url");
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
9
10
11
  
  process.chdir(__dirname);
  var soapTemplate = fs.readFileSync("message.xml");
1f837fd31   Adhidarma Hadiwinoto   on progress
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
39
40
41
42
43
44
  
  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   Adhidarma Hadiwinoto   siap coba dapat r...
45
      var remoteProduct = task.remoteProduct.split(',');
b6b185202   Adhidarma Hadiwinoto   inputCheck
46
      var params = {
7f796c813   Adhidarma Hadiwinoto   coba easysoap
47
48
          userName: config.h2h_out.userid,
          productCode: remoteProduct[0] ,
7be37af22   Adhidarma Hadiwinoto   pakai terminal H2...
49
          terminal: 'H2HIPN10',
7f796c813   Adhidarma Hadiwinoto   coba easysoap
50
51
52
53
54
          transactionType: '50',
          billNumber: createBillNumber(task.destination),
          amount: remoteProduct[1],
          bit61: createBillNumber(task.destination),
          reff: task.requestId,
342d268ac   Adhidarma Hadiwinoto   ubah timeStamp fo...
55
          timeStamp: strftime('%Y-%m-%d %H:%M:%S', new Date())
7f796c813   Adhidarma Hadiwinoto   coba easysoap
56
      }
b6b185202   Adhidarma Hadiwinoto   inputCheck
57
58
      var signature = createSignature(params, config.h2h_out.password);
      params.signature = signature;
7f796c813   Adhidarma Hadiwinoto   coba easysoap
59

a45d167eb   Adhidarma Hadiwinoto   pakai node-soap
60
61
      //topupRequestSoapDIY(task, params, retry);
      topupRequestSoap(task, params, retry);
7f796c813   Adhidarma Hadiwinoto   coba easysoap
62
  }
b6b185202   Adhidarma Hadiwinoto   inputCheck
63
  function topupRequestSoap(task, params, retry) {
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
64

777c49c56   Adhidarma Hadiwinoto   hapus forceSoap12...
65
      soap.createClient(config.h2h_out.partner, function(err, soapClient) {
35d3e5057   Adhidarma Hadiwinoto   pakai signature
66

699851497   Adhidarma Hadiwinoto   rearrange params
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
          var _params = {
              userName: params.userName,
              signature: params.signature,
              productCode: params.productCode,
              terminal: params.terminal,
              transactionType: params.transactionType,
              billNumber: params.billNumber,
              amount: params.amount,
              bit61: params.bit61,
              reff: params.reff,
              timeStamp: params.timeStamp
          }
  
          logger.info('Requesting to service', {url: config.h2h_out.partner, params: _params});
  
          soapClient.apih2h.apih2hPort.billpayment({ inputCheck: _params }, function(err, result) {
4252c2818   Adhidarma Hadiwinoto   penanganan rc
83
84
85
86
87
88
89
90
91
              logger.verbose(
                  'Got response',
                  {
                      lastEndpoint: soapClient.lastEndpoint,
                      lastRequest: soapClient.lastRequest,
                      lastMessage: soapClient.lastMessage,
                      lastResponse: soapClient.lastResponse,
                  }
              );
3899d9816   Adhidarma Hadiwinoto   log last request
92

5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
93
94
95
96
97
              if (err) {
                  logger.warn('Error requesting service', {err: err});
                  callbackReport(task.requestId, '68', 'something wrong');
                  return;
              }
4252c2818   Adhidarma Hadiwinoto   penanganan rc
98
              topupResponseHandler(task, result);
1f837fd31   Adhidarma Hadiwinoto   on progress
99
100
101
          });
      });
  }
4252c2818   Adhidarma Hadiwinoto   penanganan rc
102
103
104
  function topupResponseHandler(task, response) {
      var st24rc = '68';
      var st24message = response.outputParameter.resultDesc.$value;
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
105

4252c2818   Adhidarma Hadiwinoto   penanganan rc
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
      if ( response.outputParameter.resultCode.$value == '001' ) {
          // product disabled
          st24rc = '13';
      }
      else if ( response.outputParameter.resultCode.$value == '002' ) {
          // prodcode disable
          st24rc = '13';
      }
      else if ( response.outputParameter.resultCode.$value == '003' ) {
          // duplicate reff
          st24rc = '55';
      }
      else if ( response.outputParameter.resultCode.$value == '004' ) {
          // not enough balance
          st24rc = '40';
      }
      else if ( response.outputParameter.resultCode.$value == '005' ) {
          // username blocked
          st24rc = '40';
      }
      else if ( response.outputParameter.resultCode.$value == '006' ) {
          // not exists username
          st24rc = '40';
      }
      else if ( response.outputParameter.resultCode.$value == '011' ) {
          // invalid request
          st24rc = '40'
      }
      else if ( response.outputParameter.resultCode.$value == '012' ) {
          // no route to host
          st24rc = '40'
      }
      else if ( response.outputParameter.resultCode.$value == '013' ) {
          // invalid signature
          st24rc = '40'
      }
      else if ( response.outputParameter.bit39.$value == '06' ) {
          st24rc = '40';
          st24message = 'Error Transaksi ditolak karena terjadi error di H2H dengan response code diluar daftar ini. Silahkan hubungi H2H';
      }
      else if ( response.outputParameter.bit39.$value == '12' ) {
          st24rc = '40';
          st24message = 'Invalid Transaction Transaksi ditolak karena flow transaksi tidak valid';
      }
      else if ( response.outputParameter.bit39.$value == '13' ) {
          st24rc = '13';
          st24message = 'Invalid voucher nominal';
      }
      else if ( response.outputParameter.bit39.$value == '14' ) {
          st24rc = '14';
          st24message = 'MSISDN tidak ditemukan';
      }
      else if ( response.outputParameter.bit39.$value == '30' ) {
          st24rc = '40';
          st24message = 'Format Error';
      }
      else if ( response.outputParameter.bit39.$value == '31' ) {
          st24rc = '40';
          st24message = 'Kode bank tidak terdaftar';
      }
      else if ( response.outputParameter.bit39.$value == '63' ) {
          st24rc = '40';
          st24message = 'Reversal denied';
      }
      else if ( response.outputParameter.bit39.$value == '68' ) {
          st24rc = '68';
          st24message = 'Transaksi sedang dalam proses';
      }
      else if ( response.outputParameter.bit39.$value == '69' ) {
          st24rc = '68';
          st24message = 'Respon Ok lebih dari 24 detik';
      }
      else if ( response.outputParameter.bit39.$value == '70' ) {
          st24rc = '13';
          st24message = 'Voucher out of stock';
      }
      else if ( response.outputParameter.bit39.$value == '79' ) {
          st24rc = '14';
          st24message = 'Phone number is blocked by Telkomsel';
      }
      else if ( response.outputParameter.bit39.$value == '81' ) {
          st24rc = '14';
          st24message = 'Phone number is expired';
      }
      else if ( response.outputParameter.bit39.$value == '89' ) {
          st24rc = '40';
          st24message = 'Link to billing provider is down';
      }
      else if ( response.outputParameter.bit39.$value == '91' ) {
          st24rc = '40';
          st24message = 'Database problem';
      }
      else if ( response.outputParameter.bit39.$value == '92' ) {
          st24rc = '40';
          st24message = 'Unable to route transaction';
      }
      else if ( response.outputParameter.bit39.$value == '94' ) {
          st24rc = '40';
          st24message = 'Duplicate reversal request';
      }
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
206

4252c2818   Adhidarma Hadiwinoto   penanganan rc
207
208
209
210
211
      var message =
          response.outputParameter.resultCode.$value
          + " " + response.outputParameter.resultDesc.$value
          + "; " + response.outputParameter.bit39.$value
          ;
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
212

4252c2818   Adhidarma Hadiwinoto   penanganan rc
213
214
215
      if (response.outputParameter.resultDesc.$value != st24message) {
          var message = message + " " + st24message;
      }
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
216

4252c2818   Adhidarma Hadiwinoto   penanganan rc
217
218
      logger.info('Got result: ' + message, {result: result});
      callbackReport(task.requestId, st24rc, st24message);
97991a1dc   Adhidarma Hadiwinoto   pakai whiskers
219
220
221
222
223
224
225
226
227
228
229
230
231
  }
  
  function topupRequestRetry(task) {
      task.retry--;
  
      if (task.retry > 0) {
          logger.info('Retrying in ' +  sleepBeforeRetry + 's');
          setTimeout(topupRequest, sleepBeforeRetry * 1000, task, task.retry);
      }
      else {
          logger.warn('Maximum retry for pending status exceeded', {task: task});
      }
  }
b6b185202   Adhidarma Hadiwinoto   inputCheck
232
  function createSignature(params, password) {
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
233
      var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex');
dfcc535b5   Adhidarma Hadiwinoto   coba perbaiki cre...
234
      var plain =
b6b185202   Adhidarma Hadiwinoto   inputCheck
235
          params.userName
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
236
          + passwordHash
b6b185202   Adhidarma Hadiwinoto   inputCheck
237
238
239
240
241
242
243
          + params.productCode
          + params.terminal
          + params.transactionType
          + params.billNumber
          + params.amount
          + params.reff
          + params.timeStamp;
dfcc535b5   Adhidarma Hadiwinoto   coba perbaiki cre...
244

4252c2818   Adhidarma Hadiwinoto   penanganan rc
245
      return crypto.createHash('sha1').update(plain).digest().toString('hex');
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
246
247
248
249
  }
  
  function createBillNumber(destination) {
      return ("0000000000000" + destination).slice(-13);
1f837fd31   Adhidarma Hadiwinoto   on progress
250
251
252
253
  }
  
  exports.start = start;
  exports.topupRequest = topupRequest;
5a947e400   Adhidarma Hadiwinoto   siap coba dapat r...
254
255
  exports.createSignature = createSignature;
  exports.createBillNumber = createBillNumber;