Here are the changes i made : Here is the scenario that this happens. I have replicated the issue several times and it happens every time.
1. Caller has a balance of $1. With a promotion ( Package offer ) of 5 free minutes.
2. Caller Dials a destination costing 0.15 per minute.
3. System announces " You have 11 minutes " ( this is 5 minutes from balance and 5 minutes from promotion which is correct).
4. Just at the beginning of the 11th minute system announces " You have 61 seconds left".
5. After 30 seconds, system announces you have 31 seconds left".
6. Exactly at 10th minute, call drops with message " You don't have enough credit" (prepaid-no-enough-credit-stop )
Now user cannot use account again because in_use value is not updated back to 0 and balance is -0.495 USD.
I have replicated this scenario 100 times and every time is thesame.
--- New Class.A2Billing.php
+++ OLD Class.A2Billing.php
@@ -766,14 +766,13 @@
function enough_credit_to_call()
{
if ($this->typepaid == 0) {
- if ($this->credit < $this->agiconfig['min_credit_2call'] || $this->credit <= 0 ) {
+ if ($this->credit < $this->agiconfig['min_credit_2call'] || $this->credit < 0 ) {
return false;
} else {
return true;
}
} else {
- if ($this->credit <= 0) {
+ if ($this->credit <= -$this->creditlimit) {
$QUERY = "SELECT id_cc_package_offer FROM cc_tariffgroup WHERE id= ".$this->tariff ;
$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY);
if (!empty($result[0][0])) {
@@ -1164,7 +1163,7 @@
if ($this->agiconfig['busy_timeout'] > 0)
$res_busy = $agi->exec("Busy ".$this->agiconfig['busy_timeout']);
$agi-> stream_file('prepaid-isbusy', '#');
- } elseif ($dialstatus == "NOANSWER") {
+ } elseif ($this->dialstatus == "NOANSWER") {
$answeredtime = 0;
$agi-> stream_file('prepaid-noanswer', '#');
} elseif ($dialstatus == "CANCEL") {
@@ -1319,8 +1318,7 @@
continue;
} elseif ($dialstatus == "CANCEL") {
// Call cancelled, no need to follow-me
- $answeredtime = 0;
+ return 1;
} elseif ($dialstatus == "ANSWER") {
$this -> debug( DEBUG, $agi, __FILE__, __LINE__,
"[A2Billing] DID call friend: dialstatus : $dialstatus, answered time is ".$answeredtime." \n");
@@ -1461,8 +1459,7 @@
}
}
} else {
- if ($this->credit <= 0) {
+ if ($this->credit <= -$this->creditlimit) {
$time2call =0;
} else {
$credit_without_charge = $this->credit + abs($this->creditlimit) - abs($connection_charge);
@@ -1526,8 +1523,7 @@
// Dial(IAX2/
[email protected]/s@default)
$myres = $this -> run_dial($agi, $dialstr);
$this -> debug( INFO, $agi, __FILE__, __LINE__, "DIAL $dialstr");
- } elseif ( $time2call > 0) { // prevent 0 time to call on follow me
+ } else {
$this -> debug( INFO, $agi, __FILE__, __LINE__, "TIME TO CALL : $time2call");
$this -> fct_say_time_2_call($agi,$time2call,$selling_rate);
@@ -1547,8 +1543,6 @@
$myres = $agi->exec("StopMixMonitor");
$this -> debug( INFO, $agi, __FILE__, __LINE__, "EXEC StopMixMonitor (".$this->uniqueid.")");
}
- } else {
- continue;
}
$answeredtime = $agi->get_variable("ANSWEREDTIME");
@@ -1571,14 +1565,14 @@
$agi-> stream_file('prepaid-isbusy', '#');
if (count($listdestination)>$callcount)
continue;
- } elseif ($dialstatus == "NOANSWER") {
+ } elseif ($this->dialstatus == "NOANSWER") {
$answeredtime = 0;
$agi-> stream_file('prepaid-callfollowme', '#');
if (count($listdestination) > $callcount)
continue;
} elseif ($dialstatus == "CANCEL") {
// Call cancelled, no need to follow-me
- $answeredtime = 0;
+ return 1;
} elseif ($dialstatus == "ANSWER") {
$this -> debug( DEBUG, $agi, __FILE__, __LINE__,
"[A2Billing] DID call friend: dialstatus : $dialstatus, answered time is ".$answeredtime." \n");