Commit 96e4677f6e00cb0bdb4ff4a9d97efb72e6489929
1 parent
0203b4c7ac
Exists in
master
put last rc, messsage refnum to mongo
Showing 2 changed files with 29 additions and 17 deletions Side-by-side Diff
partner-cjk.js
... | ... | @@ -108,9 +108,25 @@ function pushResponseToMongoDb(task, response) { |
108 | 108 | if (!isMongoReady()) { return; } |
109 | 109 | |
110 | 110 | try { |
111 | + var rc = null; | |
112 | + var message = null; | |
113 | + var refnum = null; | |
114 | + | |
115 | + if (response.parsed) { | |
116 | + if (response.parsed.rc) { rc = response.parsed.rc; }; | |
117 | + if (response.parsed.message) { message = response.parsed.message; }; | |
118 | + if (response.parsed.refnum) { refnum = response.parsed.refnum; }; | |
119 | + } | |
120 | + | |
111 | 121 | mongodb.collection(config.mongodb.collection).updateOne( |
112 | 122 | {requestId: task.requestId}, |
113 | - {$push: {responses: response}}, | |
123 | + { | |
124 | + rc: rc, | |
125 | + message: message, | |
126 | + refnum: refnum, | |
127 | + | |
128 | + $push: {responses: response} | |
129 | + }, | |
114 | 130 | function(err, result) { |
115 | 131 | if (err) { |
116 | 132 | logger.warn('Error when pushing response to mongodb', {err: err, task: task, response: response}); |
... | ... | @@ -135,11 +151,12 @@ function isMongoReady() { |
135 | 151 | function getSNFromMessage(message) { |
136 | 152 | try { |
137 | 153 | var sn_match = message.match(/SN: (\w+)/); |
138 | - logger.verbose('Got SN: ' + sn_match[1]); | |
139 | 154 | return sn_match[1].trim(); |
140 | 155 | } |
141 | 156 | catch(err) { |
142 | - logger.verbose('Exception on getting sn from message', {err: err}); | |
157 | + if (logger) { | |
158 | + logger.verbose('Exception on getting sn from message', {err: err}); | |
159 | + } | |
143 | 160 | return ''; |
144 | 161 | } |
145 | 162 | } |
... | ... | @@ -199,16 +216,6 @@ function topupResponseHandler(body, task) { |
199 | 216 | var rc = '68'; |
200 | 217 | var message = result.ciwaru.msg[0]; |
201 | 218 | |
202 | - /* | |
203 | - var trxid = 0; | |
204 | - try { | |
205 | - trxid = result.ciwaru.reqnum[0]; | |
206 | - } | |
207 | - catch(err) { | |
208 | - trxid = result.ciwaru.trxid[0]; | |
209 | - } | |
210 | - */ | |
211 | - | |
212 | 219 | if (message.toUpperCase().indexOf('PENDING') >= 0) { |
213 | 220 | rc = '68'; |
214 | 221 | } |
... | ... | @@ -306,10 +313,15 @@ function topupRequest(task, retry) { |
306 | 313 | |
307 | 314 | logger.verbose('Status code: ' + res.statusCode ); |
308 | 315 | var buffer = ""; |
309 | - res.on( "data", function( data ) { buffer = buffer + data; } ); | |
316 | + | |
317 | + res.on( "data", function( data ) { | |
318 | + buffer = buffer + data; | |
319 | + }); | |
320 | + | |
310 | 321 | res.on( "end", function( data ) { |
311 | - topupResponseHandler(buffer, task); | |
322 | + topupResponseHandler(buffer, task); | |
312 | 323 | }); |
324 | + | |
313 | 325 | }); |
314 | 326 | |
315 | 327 | req.on('error', function(e) { |
test.js
... | ... | @@ -26,8 +26,8 @@ describe("#partner-cjk", function() { |
26 | 26 | |
27 | 27 | describe('#getSNFromMessage', function() { |
28 | 28 | it('should return correct sn', function() { |
29 | - var message = '2016-05-04 10:15:50: SUKSES Topup Ke 081905851012 Sebesar 5.000 Dengan SN: 100008530070 Harga = 5.612. Saldo = 475.972'; | |
30 | - partner.getSNFromMessage(message).should.equal('100008530070'); | |
29 | + var message = '2016-05-09 13:26:29: SUKSES Topup Ke 087884428889 Sebesar 50.000 Dengan SN: 55000509134656 Harga = 48.750. Saldo = 104.418.989'; | |
30 | + partner.getSNFromMessage(message).should.equal('55000509134656'); | |
31 | 31 | }); |
32 | 32 | }); |
33 | 33 | }); |