Hello,
I have employed a coder to write me an agi script to check the account balance for each outgoing voip call before the call is passed to agi-conf2. It seems to work OK.
Here it is...
#!/usr/bin/php -q
<?php
require_once("lib/phpagi/phpagi.php");
$agi = new AGI();
$exten = $agi->get_variable("EXTEN");
$exten = $exten["data"];
$acc=$agi->get_variable("CDR(accountcode)");
//print_r($acc);
$acc=$acc["data"];
$callerid = $agi->get_variable("CALLERID(num)");
$callerid = $callerid["data"];
$channel = $agi->get_variable("CHANNEL");
$channel = $channel["data"];
$agi->verbose("***Preroute-AGI => exten => ".$exten, 4);
$agi->verbose("***Preroute-AGI => callerid => ".$callerid, 4);
$agi->set_variable("CALLERID(num)", $callerid);
$agi->set_variable("CALLERID(dnid)", $dnid);
$agi->verbose("***Preroute-AGI =>Account code => ".$acc, 4);
$agi->set_variable("EXTEN", $exten);
$ini_array = parse_ini_file("/etc/a2billing.conf");
$connA = mysql_connect($ini_array["hostname"], $ini_array["user"], $ini_array["password"]);
mysql_select_db($ini_array["dbname"], $connA);
$query="select credit from cc_card where id in(select id_cc_card from cc_sip_buddies where accountcode='$acc')";
$res=mysql_query($query);
$data=mysql_fetch_assoc($res);
$credit=$data['credit'];
$agi->verbose("***Preroute-AGI => credit => ".$credit, 4);
if($credit<=0)
{
$agi->exec("goto","voip-balance-check,*0,1");
<<<< if the account balance = 0 or less the call is passed to agi-conf9 which is set to play the "you do not have enough credit..." }
?>
[voip-balance-check]
exten => *0,1,Noop(zero balance)
exten => *0,n,DeadAgi(a2billing.php,9)
exten => *0,n,Hangup
I hope that helps...
Marcin