Commit d9342c64542fcea46469aa6714c35abd94db6961

Authored by Adhidarma Hadiwinoto
1 parent 51b2b581db
Exists in master

parseSn

Showing 2 changed files with 28 additions and 0 deletions Side-by-side Diff

... ... @@ -152,6 +152,13 @@ function parseMessage(task, message) {
152 152 rc = '40';
153 153 }
154 154  
  155 + if (rc == '00') {
  156 + let sn = parseSn(message, config.h2h_out.sn_pattern);
  157 + if (sn) {
  158 + message = "SN=" + sn + ";" + message;
  159 + }
  160 + }
  161 +
155 162 callbackReport(requestId, rc, message);
156 163 }
157 164  
... ... @@ -203,6 +210,21 @@ function createReverseHttpServer() {
203 210 });
204 211 }
205 212  
  213 +function parseSn(message, pattern) {
  214 +
  215 + try {
  216 + let sn_regex = new RegExp(pattern);
  217 + let sn_match = message.match(sn_regex);
  218 +
  219 + return sn_match[1].trim();
  220 + }
  221 + catch(e) {
  222 + return;
  223 + }
  224 +
  225 +}
  226 +
206 227 exports.start = start;
207 228 exports.topupRequest = topupRequest;
208 229 exports.generateSign = generateSign;
  230 +exports.parseSn = parseSn;
... ... @@ -7,4 +7,10 @@ describe ('#partner', function() {
7 7 partner.generateSign('YUSUF', 'XX10', '08123456789', '2140669', '1144', 'abcd').should.equal('vlrN9Yuu4xHAT8_bXIUHKw2NjHo=');
8 8 })
9 9 });
  10 +
  11 + describe('parseSn', function() {
  12 + it('should return correct sn', function() {
  13 + partner.parseSn("TrxID:#451318 TN10.08128364883 SUKSES. SN: 41000905936059. Saldo Rp-20.420 - 10.210 = Rp-30.630 ctr:1 RS:HTH049BSI @2016-06-10 08:11:04 PrintStruk: http://27.111.44.196/report/ Add HANGOUT trxtuj@gmail.com By Holic Reload", "SN: (\\d+)\\.").should.equal("41000905936059");
  14 + })
  15 + });
10 16 });