Commit bf636f78efdc5e8e04d06342d2e1b0d678f88a03
1 parent
1616520506
Exists in
master
penanganan trx gagal
Showing 1 changed file with 32 additions and 23 deletions Side-by-side Diff
partner-trustlink.js
... | ... | @@ -19,11 +19,11 @@ var options; |
19 | 19 | function start(_config, _callbackReport, options) { |
20 | 20 | config = _config; |
21 | 21 | callbackReport = _callbackReport |
22 | - | |
22 | + | |
23 | 23 | if (options && options.aaa) { |
24 | 24 | aaa = options.aaa; |
25 | 25 | } |
26 | - | |
26 | + | |
27 | 27 | if (options && options.logger) { |
28 | 28 | logger = options.logger; |
29 | 29 | } else { |
... | ... | @@ -33,7 +33,7 @@ function start(_config, _callbackReport, options) { |
33 | 33 | ] |
34 | 34 | }); |
35 | 35 | } |
36 | - | |
36 | + | |
37 | 37 | createReverseReportServer(); |
38 | 38 | } |
39 | 39 | |
... | ... | @@ -45,7 +45,7 @@ function createReverseReportServer() { |
45 | 45 | |
46 | 46 | function onReverseReport(req, res) { |
47 | 47 | res.end('OK'); |
48 | - | |
48 | + | |
49 | 49 | var qs = url.parse(req.url, true).query; |
50 | 50 | logger.info('Reverse Report', {qs: qs}); |
51 | 51 | } |
... | ... | @@ -53,15 +53,15 @@ function onReverseReport(req, res) { |
53 | 53 | function calculateSignature(ts, destination, password) { |
54 | 54 | var a = ts + destination.substr(destination.length - 4); |
55 | 55 | var b = destination.substr(destination.length - 4).split('').reverse().join('') + password; |
56 | - | |
56 | + | |
57 | 57 | return xor.encode(a,b); |
58 | 58 | } |
59 | 59 | |
60 | 60 | function createXmlPayload(task, userid, password) { |
61 | 61 | var ts = strftime('%H%M%S', new Date()); |
62 | - | |
62 | + | |
63 | 63 | var signature = calculateSignature(ts, task.destination, password); |
64 | - | |
64 | + | |
65 | 65 | var payload = { |
66 | 66 | evoucher: [ |
67 | 67 | {command: 'TOPUP'}, |
... | ... | @@ -74,11 +74,11 @@ function createXmlPayload(task, userid, password) { |
74 | 74 | {trxke: 1}, |
75 | 75 | ] |
76 | 76 | }; |
77 | - | |
77 | + | |
78 | 78 | if (logger) { |
79 | 79 | logger.verbose('Generate xml payload', {payload: payload}); |
80 | 80 | } |
81 | - | |
81 | + | |
82 | 82 | return "<?xml version=\"1.0\" ?>\n" + xml(payload); |
83 | 83 | } |
84 | 84 | |
... | ... | @@ -86,11 +86,11 @@ function topupRequest(task, retry) { |
86 | 86 | if (retry === undefined) { |
87 | 87 | retry = max_retry; |
88 | 88 | } |
89 | - | |
89 | + | |
90 | 90 | var payload = createXmlPayload(task, config.h2h_out.userid, config.h2h_out.password); |
91 | - | |
91 | + | |
92 | 92 | var partner = url.parse(config.h2h_out.partner); |
93 | - | |
93 | + | |
94 | 94 | var request_options = { |
95 | 95 | host: partner.hostname, |
96 | 96 | path: partner.path, |
... | ... | @@ -101,17 +101,17 @@ function topupRequest(task, retry) { |
101 | 101 | 'Content-Length': Buffer.byteLength(payload) |
102 | 102 | } |
103 | 103 | }; |
104 | - | |
104 | + | |
105 | 105 | var buffer = ""; |
106 | - | |
106 | + | |
107 | 107 | logger.info('Requesting to partner', {request_options: request_options}); |
108 | - | |
108 | + | |
109 | 109 | var req = http.request(request_options, function( res ) { |
110 | 110 | |
111 | 111 | logger.verbose('Status code: ' + res.statusCode ); |
112 | 112 | var buffer = ""; |
113 | 113 | res.on( "data", function( data ) { buffer = buffer + data; } ); |
114 | - res.on( "end", function( data ) { | |
114 | + res.on( "end", function( data ) { | |
115 | 115 | logger.verbose('Got direct response from partner', {resp: buffer}); |
116 | 116 | directResponseHandler(buffer, task); |
117 | 117 | }); |
... | ... | @@ -139,21 +139,30 @@ function directResponseHandler(body, task) { |
139 | 139 | callbackReport(request_id, '68', buffer); |
140 | 140 | return; |
141 | 141 | } |
142 | - | |
142 | + | |
143 | 143 | logger.info('Direct response parsed', {result: result}); |
144 | - | |
144 | + | |
145 | 145 | var response_code = '68'; |
146 | - | |
146 | + | |
147 | 147 | var request_id = task.requestId; |
148 | 148 | var status = result.evoucher.result[0].trim(); |
149 | 149 | var message = result.evoucher.value[0].string[0].trim(); |
150 | - | |
150 | + | |
151 | 151 | if (status == '0') { |
152 | - response_code = '00'; | |
152 | + if (message.indexOf('SUKSES') >= 0) { | |
153 | + response_code = '00'; | |
154 | + } | |
155 | + else if (message.indexOf('GAGAL') >= 0) { | |
156 | + response_code = '40'; | |
157 | + } | |
158 | + else { | |
159 | + response_code = '68'; | |
160 | + } | |
161 | + | |
153 | 162 | } |
154 | 163 | else if (status == "-1") { |
155 | 164 | response_code = '40'; |
156 | - | |
165 | + | |
157 | 166 | /* |
158 | 167 | var new_response_code = responseCodeFromMessage(message); |
159 | 168 | if (new_response_code) { |
... | ... | @@ -164,7 +173,7 @@ function directResponseHandler(body, task) { |
164 | 173 | } else { |
165 | 174 | response_code = '68'; |
166 | 175 | } |
167 | - | |
176 | + | |
168 | 177 | callbackReport(request_id, response_code, message); |
169 | 178 | }); |
170 | 179 | } |