diff --git a/lib/st24.js b/lib/st24.js index 230b4e4..e7eae7b 100644 --- a/lib/st24.js +++ b/lib/st24.js @@ -41,7 +41,9 @@ function extractPriceFromMsg(msg, custom_rule) { const default_pattern = "\\d,HRG=(.*?),ID="; const default_match_idx = 1; - return extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); + let price = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); + price = (typeof price === 'string') ? Number(price.replace(/\./g, '')) : null; + return price; } function extractBalanceFromMsg(msg, custom_rule) { diff --git a/test.js b/test.js index 14a7cc2..a27bffe 100644 --- a/test.js +++ b/test.js @@ -63,4 +63,19 @@ describe('#st24', function() { }) }) + describe('#extractPriceFromMsg', function() { + describe('using native ST24 topUpRequest direct response', function() { + it('should return correct price', function() { + st24.extractPriceFromMsg('SN=0041002635395450;;19/07/18 21:01 ISI SPT20 KE 08125100091, SUKSES. SAL=798.500,HRG=19.700,ID=48761075,SN=0041002635395450;; ..trx lancar').should.equal(19700); + st24.extractPriceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(5250); + }); + }) + + describe('using native ST24 topUpInquiry response', function() { + it('should return correct price', function() { + st24.extractPriceFromMsg('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal(19700); + }) + }) + }) + })