Commit 4e651067774f61c8628cd8905389269117891ea9

Authored by Adhidarma Hadiwinoto
1 parent c47be51fe8
Exists in master

mulai adaptasi agar bisa tangani selain st24 asli

Showing 3 changed files with 57 additions and 15 deletions Side-by-side Diff

... ... @@ -34,6 +34,10 @@ function createXmlRpcClient(endpoint) {
34 34 }
35 35  
36 36 function buy(task) {
  37 + _topUpRequest(task);
  38 +}
  39 +
  40 +function _topUpRequest(task, isAdvice) {
37 41 const params = {
38 42 MSISDN: config.partner.msisdn || config.partner.userid,
39 43 REQUESTID: task.trx_id,
... ... @@ -54,10 +58,13 @@ function buy(task) {
54 58 let rc = '68';
55 59  
56 60 if (
57   - err.code === 'ECONNREFUSED'
58   - || err.code === 'EHOSTUNREACH'
59   - || (err.code === 'ETIMEDOUT' && err.syscall === "connect")
60   - || (err.code === 'EPROTO' && err.syscall === "write")
  61 + !isAdvice &&
  62 + (
  63 + err.code === 'ECONNREFUSED'
  64 + || err.code === 'EHOSTUNREACH'
  65 + || (err.code === 'ETIMEDOUT' && err.syscall === "connect")
  66 + || (err.code === 'EPROTO' && err.syscall === "write")
  67 + )
61 68 ) {
62 69 rc = '91';
63 70 }
... ... @@ -99,7 +106,7 @@ function buy(task) {
99 106 });
100 107 }
101 108  
102   -function advice(task) {
  109 +function _topUpInquiry(task) {
103 110 const params = {
104 111 REQUESTID: task.trx_id,
105 112 MSISDN: config.partner.msisdn || config.partner.userid,
... ... @@ -127,11 +134,6 @@ function advice(task) {
127 134 }
128 135 });
129 136  
130   - setTimeout(
131   - function() { advice(task); },
132   - 60 * 1000
133   - );
134   -
135 137 return;
136 138 }
137 139  
... ... @@ -152,6 +154,19 @@ function advice(task) {
152 154 });
153 155 }
154 156  
  157 +function advice(task) {
  158 + if (config && advice_is_not_allowed) {
  159 + return;
  160 + }
  161 +
  162 + if (config && advice_is_topuprequest) {
  163 + _topUpRequest(task, true);
  164 + }
  165 + else {
  166 + _topUpInquiry(task);
  167 + }
  168 +}
  169 +
155 170 function report(data) {
156 171 if (!data) {
157 172 return;
1 1 "use strict";
2 2  
3   -function extractSnFromMessage(msg) {
  3 +function extractSnFromMessage(msg, custom_rule) {
4 4 if (!msg || typeof msg !== 'string') {
5 5 return;
6 6 }
7 7  
8   - let match = msg.match(/^SN=(.*?);/);
9   - if (!match || match.length < 2) {
10   - return;
  8 + let pattern;
  9 + let pattern_match_idx;
  10 +
  11 + if (custom_rule && custom_rule.pattern) {
  12 + pattern = custom_rule.pattern;
  13 + pattern_match_idx = custom_rule.match_idx;
  14 + }
  15 + else {
  16 + pattern = "^SN=(.*?);";
  17 + pattern_match_idx = 1;
11 18 }
12 19  
13   - return match[1];
  20 + const re = new RegExp(pattern);
  21 + const matches = msg.match(re);
  22 +
  23 + if (!matches) return;
  24 +
  25 + if (pattern_match_idx < matches.length) {
  26 + return matches[pattern_match_idx];
  27 + } else {
  28 + return;
  29 + }
14 30 }
15 31  
16 32 function extractPriceFromMsg(msg) {
rc-local.sample.kopnus.json
... ... @@ -0,0 +1,11 @@
  1 +{
  2 + "00": "00",
  3 + "14": "14",
  4 + "15": "88",
  5 + "68": "68",
  6 + "74": "77",
  7 + "82": "94",
  8 + "I8": "14",
  9 + "I9": "14",
  10 + "A0": "68"
  11 +}