<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hello<br>
    I would like to use nibblebilling for fraud prevention on
    international and premium numbers ( national or emergency calls
    should never be blocked and should still working even if the billing
    database is unavailable&nbsp; )<br>
    <br>
    Unfortunately that never hangup my calls using standard dial plan<br>
    <br>
    <b>nibblebill.conf.xml</b><br>
    <br>
    <tt>&lt;configuration name="nibblebill.conf" description="Nibble
      Billing"&gt;</tt><tt><br>
    </tt><tt>&nbsp; &lt;settings&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- See
      <a class="moz-txt-link-freetext" href="http://wiki.freeswitch.org/wiki/Mod_nibblebill">http://wiki.freeswitch.org/wiki/Mod_nibblebill</a> for help with these
      options --&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- Information for connecting to your database
      --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="db_dsn"
      value="pgsql://hostaddr=127.0.0.1 dbname=xxxx user=xxxx
      password=xxxx"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- The database table where your CASH column is
      located --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="db_table" value="accounts"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- The column name where we store the value of the
      account --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="db_column_cash" value="cash"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- The column name for the unique ID identifying
      the account --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="db_column_account" value="id"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- Default heartbeat interval. Set to 'off' for no
      heartbeat (i.e. bill only at end of call) --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="global_heartbeat" value="20"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- By default, warn a caller when their balance is
      at $5.00. You can set this to a negative number. --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="lowbal_amt" value="-100"/&gt;</tt><tt>
      &lt;!-- i don't need this --&gt;<br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="lowbal_action" value="play ding"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- By default, terminate a caller when their
      balance hits $0.00. You can set this to a negative number. --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="nobal_amt" value="0"/&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="nobal_action" value="hangup"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;!-- If a call goes beyond a certain dollar amount,
      flag or terminate it --&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="percall_max_amt" value="10"/&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; &lt;param name="percall_action" value="hangup"/&gt;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp; &lt;/settings&gt;</tt><tt><br>
    </tt><tt>&lt;/configuration&gt;</tt><br>
    <br>
    <b>outbound route</b><br>
    <br>
    <tt>&lt;extension name="international" &gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp; &lt;condition field="destination_number"
      expression="^00(\d{6,20})$" &gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action application="nibblebill"
      data="flush"/&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action application="set"
      data="nibble_account=${accountcode}"/&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action application="set"
      data="nibble_rate=0.1"/&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action application="bridge"
      data="sofia/gateway/gw_idt/$1" /&gt;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp; &lt;/condition&gt;</tt><tt><br>
    </tt><tt>&lt;/extension&gt;</tt><br>
    <br>
    <br>
    <b>My balance</b><br>
    My balance is already negative<br>
    <br>
    <tt>&nbsp;select * from accounts ;</tt><tt><br>
    </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; cash&nbsp;&nbsp;&nbsp; </tt><tt><br>
    </tt><tt>----------------------------------+-----------</tt><tt><br>
    </tt><tt>&nbsp;company.voip.mydomain.com | -0.789471</tt><br>
    <br>
    <b>A sample call</b><br>
    My balance already negative, the call will be billed but never
    blocked<br>
    <br>
    <tt>Dialplan: <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a> Action
      nibblebill(flush)</tt><tt><br>
    </tt><tt>Dialplan: <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a>
      Action set(nibble_account=${accountcode})</tt><tt><br>
    </tt><tt>Dialplan: <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a>
      Action set(nibble_rate=0.1)</tt><tt><br>
    </tt><tt>EXECUTE <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a>
      nibblebill(flush)</tt><tt><br>
    </tt><tt>EXECUTE <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a>
      set(nibble_account=company.voip.domain.com)</tt><tt><br>
    </tt><tt>2016-04-10 12:10:04.049418 [DEBUG] mod_dptools.c:1477
      <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a> SET
      [nibble_account]=[company.voip.domain.com]</tt><tt><br>
    </tt><tt>EXECUTE <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a>
      set(nibble_rate=0.1)</tt><tt><br>
    </tt><tt>2016-04-10 12:10:04.049418 [DEBUG] mod_dptools.c:1477
      <a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/5003@company.voip.domain.com">sofia/internal/5003@company.voip.domain.com</a> SET
      [nibble_rate]=[0.1]</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.132458 [DEBUG] mod_nibblebill.c:488
      Attempting to bill at $0.1 per minute to account
      company.voip.domain.com</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.132458 [INFO] mod_nibblebill.c:540
      Beginning new billing on 644488fc-ff04-11e5-9a27-fd2791153af9</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.132458 [DEBUG] mod_nibblebill.c:546 42
      seconds passed since last bill time of 2016-04-10 12:10:09</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.132458 [DEBUG] mod_nibblebill.c:563
      Billing $0.071033 to company.voip.domain.com (Call: / 0.000000 so
      far)</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.132458 [DEBUG] mod_nibblebill.c:393
      Doing update query</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.172440 [DEBUG] mod_nibblebill.c:420
      Doing lookup query</tt><tt><br>
    </tt><tt>[SELECT cash AS nibble_balance FROM accounts WHERE
      id='company.voip.domain.com']</tt><tt><br>
    </tt><tt>2016-04-10 12:10:52.172440 [DEBUG] mod_nibblebill.c:428
      Retrieved current balance for account company.voip.domain.com
      (balance = -0.860504)</tt><br>
    <br>
    <br>
    <b>Using b-leg only</b><br>
    Alternatively i tried an alternative dialplan ( Even if i don't
    relay understand what is the meaning of b-leg billing&nbsp; )<br>
    <br>
    <tt>&lt;action application="bridge"
      data="{enable_heartbeat_events=5,nibble_rate=0.1,nibble_account=${accountcode},originate_timeout=90}sofia/gateway/gw_idt/33$1"
      /&gt;</tt><tt> </tt><br>
    <br>
    The result is better because the pending call is hanged up when the
    balance reach 0.<br>
    <br>
    <tt>2016-04-10 12:39:59.012462 [CRIT] mod_nibblebill.c:607 Balance
      of -0.003237 fell below allowed amount of 0.000000! (Account </tt><tt>company.voip.domain.com</tt><tt>)</tt><br>
    <br>
    But if i make a new call ( when my balance is negative )&nbsp; , the
    caller party is immediately hanged but this did not cancel
    immediately the bridge:&nbsp; The called party ring and can stay bridged
    for 61 seconds after answer.<br>
    <br>
    <br>
    <br>
    <br>
    <br>
  </body>
</html>