Commit 358728726e11e057d9f4f16e112f7d7180113973
1 parent
e1f73a2c87
Exists in
master
Tambahan buat postpaid
Showing 2 changed files with 59 additions and 4 deletions Side-by-side Diff
index.js
... | ... | @@ -3,6 +3,18 @@ |
3 | 3 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); |
4 | 4 | const organicRc = require('./rc'); |
5 | 5 | |
6 | +function isInquiryResponseMessage(msg) { | |
7 | + return (msg || '').indexOf('CEK TAGIHAN') >= 0; | |
8 | +} | |
9 | + | |
10 | +function isPaymentResponseMessage(msg) { | |
11 | + return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; | |
12 | +} | |
13 | + | |
14 | +function isPostpaidResponseMessage(msg) { | |
15 | + return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); | |
16 | +} | |
17 | + | |
6 | 18 | function getRcFromMessage(msg, customRc) { |
7 | 19 | let rc; |
8 | 20 | if (customRc && Array.isArray(customRc) && customRc.length) { |
... | ... | @@ -74,7 +86,7 @@ function extractFromMessage(msg, rule) { |
74 | 86 | function getSnFromMessage(msg, rule) { |
75 | 87 | if (!rule) { |
76 | 88 | rule = { |
77 | - pattern: "SN: (\\d+)", | |
89 | + pattern: "[: ]S/*N:\\s*(.+?)\\s", | |
78 | 90 | match_idx: 1 |
79 | 91 | } |
80 | 92 | } |
... | ... | @@ -82,7 +94,7 @@ function getSnFromMessage(msg, rule) { |
82 | 94 | let sn = extractFromMessage(msg, rule); |
83 | 95 | if (!sn || typeof sn !== 'string') { return; } |
84 | 96 | |
85 | - return sn.toUpperCase().replace(/[^a-zA-Z0-9/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); | |
97 | + return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); | |
86 | 98 | } |
87 | 99 | |
88 | 100 | function getBalanceFromMessage(msg, rule) { |
... | ... | @@ -99,7 +111,23 @@ function getBalanceFromMessage(msg, rule) { |
99 | 111 | return Number(result.replace(/\./g, '')); |
100 | 112 | } |
101 | 113 | |
114 | +function getDetailFromMessage(msg, rule) { | |
115 | + if (!rule) { | |
116 | + rule = { | |
117 | + pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", | |
118 | + match_idx: 1, | |
119 | + } | |
120 | + } | |
121 | + | |
122 | + let result = extractFromMessage(msg, rule); | |
123 | + return (result || '').trim(); | |
124 | +} | |
125 | + | |
102 | 126 | exports.getRcFromMessage = getRcFromMessage; |
103 | 127 | exports.getPriceFromMessage = getPriceFromMessage; |
104 | 128 | exports.getSnFromMessage = getSnFromMessage; |
105 | 129 | exports.getBalanceFromMessage = getBalanceFromMessage; |
130 | +exports.isInquiryResponseMessage = isInquiryResponseMessage; | |
131 | +exports.isPaymentResponseMessage = isPaymentResponseMessage; | |
132 | +exports.isPostpaidResponseMessage = isPostpaidResponseMessage; | |
133 | +exports.getDetailFromMessage = getDetailFromMessage; |
test/main.js
1 | -"use strict"; | |
2 | - | |
3 | 1 | /* global describe it */ |
4 | 2 | |
5 | 3 | //process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES'; |
... | ... | @@ -13,6 +11,10 @@ describe('#irs', function() { |
13 | 11 | irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68'); |
14 | 12 | irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40'); |
15 | 13 | irs.getRcFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal('00'); |
14 | + | |
15 | + irs.getRcFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal('00', 'postpaid inquiry success'); | |
16 | + irs.getRcFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal('00', 'postpaid payment success'); | |
17 | + | |
16 | 18 | irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90'); |
17 | 19 | }); |
18 | 20 | }); |
... | ... | @@ -23,6 +25,11 @@ describe('#irs', function() { |
23 | 25 | irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal(24475); |
24 | 26 | }); |
25 | 27 | |
28 | + it('should handle postpaid response', () => { | |
29 | + irs.getPriceFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal(0, 'postpaid inquiry succces'); | |
30 | + irs.getPriceFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal(17741, 'postpaid payment success'); | |
31 | + }) | |
32 | + | |
26 | 33 | it('should handle missing price', function() { |
27 | 34 | should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); |
28 | 35 | }); |
... | ... | @@ -60,4 +67,24 @@ describe('#irs', function() { |
60 | 67 | }); |
61 | 68 | }) |
62 | 69 | }); |
70 | + | |
71 | + describe('#getSnFromMessage', () => { | |
72 | + it('should return correct result', () => { | |
73 | + irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN: 99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN: 99971113094584'); | |
74 | + irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN:99971113094584'); | |
75 | + irs.getSnFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') | |
76 | + .should.equal('0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); | |
77 | + }); | |
78 | + }); | |
79 | + | |
80 | + describe('#getDetailFromMessage', () => { | |
81 | + it('should return correct result', () => { | |
82 | + irs.getDetailFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16') | |
83 | + .should.equal('NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041', 'postpaid inquiry success'); | |
84 | + | |
85 | + irs.getDetailFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') | |
86 | + .should.equal('S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); | |
87 | + }); | |
88 | + | |
89 | + }); | |
63 | 90 | }); |
64 | 91 | \ No newline at end of file |