Commit 6ea630a341775fac196293cda9515cc8ec788fb2
1 parent
813ff266fd
Exists in
master
force parse sn flag
Showing 2 changed files with 25 additions and 30 deletions Side-by-side Diff
gentong.js
... | ... | @@ -135,13 +135,22 @@ function parseSN(message, _config) { |
135 | 135 | return ''; |
136 | 136 | } |
137 | 137 | |
138 | - var sn = sn_match[0]; | |
138 | + var match_index = 0; | |
139 | + if (_config.h2h_out.sn_match_index) { | |
140 | + match_index = Number(_config.h2h_out.sn_match_index) | |
141 | + } | |
142 | + | |
143 | + var sn = sn_match[match_index]; | |
139 | 144 | var sn_remove_patterns = _config.h2h_out.sn_remove_patterns.split(_config.h2h_out.sn_remove_patterns_separator); |
140 | 145 | |
141 | 146 | var count = sn_remove_patterns.length; |
142 | 147 | |
143 | 148 | for(var i = 0; i < count; i++) { |
144 | - sn = sn.replace(sn_remove_patterns[i], ''); | |
149 | + | |
150 | + //sn = sn.replace(sn_remove_patterns[i], ''); | |
151 | + | |
152 | + var re = new RegExp(sn_remove_patterns[i], 'g'); | |
153 | + sn = sn.replace(re, ''); | |
145 | 154 | } |
146 | 155 | |
147 | 156 | return sn.trim(); |
... | ... | @@ -159,7 +168,7 @@ function createServer() { |
159 | 168 | |
160 | 169 | if (qs.topup_status == 'S') { |
161 | 170 | response_code = '00'; |
162 | - if (qs.sn) { | |
171 | + if (qs.sn && !config.h2h_out.force_parse_sn) { | |
163 | 172 | sn = qs.sn; |
164 | 173 | } else { |
165 | 174 | logger.warn('Missing SN from query string. Trying to get SN from message'); |
... | ... | @@ -267,3 +276,4 @@ function start(_config, _callbackReport, options) { |
267 | 276 | |
268 | 277 | exports.start = start; |
269 | 278 | exports.topupRequest = topupRequest; |
279 | +exports.parseSN = parseSN; |
test.js
1 | 1 | var assert = require("assert"); |
2 | 2 | |
3 | - | |
4 | -describe('aaa', function() { | |
5 | - var aaa = require('./aaa'); | |
3 | +describe("#parseSN()", function() { | |
4 | + var partner = require('./gentong'); | |
5 | + | |
6 | + var config = {}; | |
7 | + config.h2h_out = {}; | |
6 | 8 | |
7 | - describe("#unaliasResponseCode()", function() { | |
8 | - it('should return 68', function() { | |
9 | - assert.equal('68', aaa.unaliasResponseCode('01', '01:68')); | |
10 | - }); | |
11 | - | |
12 | - it('should return 68', function() { | |
13 | - assert.equal('68', aaa.unaliasResponseCode('68', '01:68')); | |
14 | - }); | |
15 | - | |
16 | - it('should return 00', function() { | |
17 | - assert.equal('00', aaa.unaliasResponseCode('00', '01:68')); | |
18 | - }); | |
19 | - | |
20 | - it('should return 40', function() { | |
21 | - assert.equal('40', aaa.unaliasResponseCode('40', '')); | |
22 | - }); | |
23 | - | |
24 | - it('should return 40', function() { | |
25 | - assert.equal('40', aaa.unaliasResponseCode('40', '')); | |
26 | - }); | |
27 | - | |
28 | - it('should return 40', function() { | |
29 | - assert.equal('40', aaa.unaliasResponseCode('40')); | |
30 | - }); | |
9 | + config.h2h_out.parse_sn = 'YES'; | |
10 | + config.h2h_out.sn_pattern = " SN : (.+?) Pos Reff"; | |
11 | + config.h2h_out.sn_remove_patterns_separator = '|'; | |
12 | + config.h2h_out.sn_remove_patterns = ' '; | |
13 | + config.h2h_out.sn_match_index = 1; | |
31 | 14 | |
15 | + it ('should return correct sn', function () { | |
16 | + assert.equal(partner.parseSN("Berhasil 26/16/13 49: s10h ke 081282629266 SN : 31 0009 5856 5718 Pos Reff : 4109000292575968, Saldo Rp. 9.990.500.SA_POIN", config), '31000958565718'); | |
32 | 17 | }); |
33 | 18 | }); |