From c52ed4be8a7085efc9d0d69c5abaf7d4aa930683 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Mon, 11 May 2020 19:27:02 +0700
Subject: [PATCH] Adaptasi metro-h2h

---
 lib/st24.js | 6 +++---
 test.js     | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/st24.js b/lib/st24.js
index 15c313d..5657a77 100644
--- a/lib/st24.js
+++ b/lib/st24.js
@@ -38,16 +38,16 @@ function extractSnFromMessage(msg, custom_rule) {
 }
 
 function extractPriceFromMsg(msg, custom_rule) {
-    const default_pattern = "\\d,HRG=(.*?),ID=";
+    const default_pattern = "\\d,HRG= *(?:RP)*\\.* *(.*?),ID=";
     const default_match_idx = 1;
 
     let price = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule);
-    price = (typeof price === 'string') ? Number(price.replace(/\./g, '')) : null;
+    price = (typeof price === 'string') ? Number(price.replace(/[^\d]/g, '')) : null;
     return price;
 }
 
 function extractBalanceFromMsg(msg, custom_rule) {
-    const default_pattern = "SAL=([\\d\\.]+)";
+    const default_pattern = 'SAL= *(?:RP)*\\.* *([\\d\\.,]+)';
     const default_match_idx = 1;
 
     let balance = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule);
diff --git a/test.js b/test.js
index 6b72ffc..5dccf0d 100644
--- a/test.js
+++ b/test.js
@@ -46,6 +46,7 @@ describe('#st24', function() {
             it('should return correct balance', function()  {
                 st24.extractBalanceFromMsg('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(426078);
                 st24.extractBalanceFromMsg('15/05/18 17:19 ISI SAN10 KE 08535686667, NOMOR YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI..SAL=1.144.578,ID=47250459, ..trx lancar').should.equal(1144578)
+                st24.extractBalanceFromMsg('SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31;11/05/20 17:24 TRANSAKSI PLNB50 KE 45019534903, (ISO00) BERHASIL. SAL=RP 4,729,975,HRG=RP 50,005,ID=62102710,SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31@ *[Gaspolll_TanpaBatas] CS: @CSMETROH2H | 62 85810555505 . Channel : https://t.me/metroreloadinfoh2h').should.equal(4729975, 'metro');
             })
 
             it('should return null if there is no balance info', function() {
@@ -74,6 +75,7 @@ describe('#st24', 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);
+                st24.extractPriceFromMsg('SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31;11/05/20 17:24 TRANSAKSI PLNB50 KE 45019534903, (ISO00) BERHASIL. SAL=RP 4,729,975,HRG=RP 50,005,ID=62102710,SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31@ *[Gaspolll_TanpaBatas] CS: @CSMETROH2H | 62 85810555505 . Channel : https://t.me/metroreloadinfoh2h').should.equal(50005, 'metro');
             });
         })
 
-- 
1.9.0