Hi guys,
not sure whether u guys have already had a fix that cover all scenarios, i.e. CID callback, web callback, all callback, with flat as well as progressive rates.
I have a rather crude solution that will work for all. Tested it and seems fine. But, I may have overlooked something and it would be nice if you guys can give some comments on it.
FYI, I'm using a2billing v1.3.
There are 2 files affected:
a2billing.php and
Class.A2Billing.php. Changes are shown in
bold.
------------------------------
a2billing.php
------------------------------
line 70:
Code:
$A2B = new A2Billing();
$A2B -> load_conf($agi, NULL, 0, $idconfig);
[b]$A2B -> mode = $mode;[/b] // copied from asiby's patch.
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "IDCONFIG : $idconfig");
line 712:Code:
if ($callback_mode == 'CID') {
$charge_callback = 1;
$A2B->agiconfig['use_dnid'] = 0;
$A2B->agiconfig['number_try'] = 1;
[b]$A2B->agiconfig['cid_enable'] = 0;[/b]
} elseif ($callback_mode == 'ALL') {
$A2B->agiconfig['use_dnid'] = 0;
$A2B->agiconfig['number_try'] = 1;
} else {
$charge_callback = 1;
// FOR THE WEB-CALLBACK
$A2B->agiconfig['number_try'] = 1;
$A2B->agiconfig['use_dnid'] = 1;
$A2B->agiconfig['say_balance_after_auth'] = 0;
$A2B->agiconfig['cid_enable'] = 0;
$A2B->agiconfig['say_timetocall'] = 0;
}
[b]$A2B->callback_leg1_dest = $called_party;[/b]
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK]:[GET VARIABLE : CALLED=$called_party | CALLING=$calling_party | MODE=$callback_mode | TARIFF=$callback_tariff | CBID=$callback_uniqueid | LEG=$callback_leg]");
------------------------------
Class.A2Billing.php------------------------------
line 126:Code:
var $hostname='';
var $currency='usd';
[b]var $mode = '';[/b] // copied from asiby's patch.
[b]var $callback_leg1_dest = '';[/b]
var $timeout;
var $newdestination;
line 713:Code:
// STRIP * FROM DESTINATION NUMBER
$this->destination = str_replace('*', '', $this->destination);
[b]if ($this->mode == 'callback') {
$RateEngine_leg1 = new RateEngine();
$resfindrate = $RateEngine_leg1->rate_engine_findrates($this, $this->callback_leg1_dest, $this->tariff);
if ($resfindrate == 0) {
$this->debug(VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "Something is wrong! - cannot find rate for leg1 [dest: $this->callback_leg1_dest]");
return -1;
}
}[/b]
// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
line 732:Code:
/*$rate=$result[0][0];
if ($rate<=0) {
//$prompt="prepaid-dest-blocked";
$prompt="prepaid-dest-unreachable";
continue;
}*/
[b]if ($this->mode == 'callback') {
$epsilon = 1;
for ($k = 0; $k < count($RateEngine->ratecard_obj); $k++) {
$r = 0.5;
$r_min = 0.0;
$r_max = 1.0;
$credit_leg1 = $r * $this->credit;
$credit_leg2 = $this->credit - $credit_leg1;
for (;;) {
$timeout_leg1 = $RateEngine_leg1->rate_engine_calcultimeout($this, $credit_leg1) - 60; // assuming 1 minute gone before leg2 is established.
$timeout_leg2 = $RateEngine->rate_engine_calcultimeout($this, $credit_leg2, $k);
if ($timeout_leg1 > $timeout_leg2) {
$diff = $timeout_leg1 - $timeout_leg2;
$r_max = $r;
$r = ($r + $r_min) / 2;
}
else {
$diff = $timeout_leg2 - $timeout_leg1;
$r_min = $r;
$r = ($r + $r_max) / 2;
}
if ($diff < $epsilon) {
$this->debug(VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "CALCULTIMEOUT: k=$k - timeout=$timeout_leg2");
break;
}
$credit_leg1 = $r * $this->credit;
$credit_leg2 = $this->credit - $credit_leg1;
}
}
}
else {[/b]
// CHECKING THE TIMEOUT
$res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($this, $this->credit);
$this->debug(VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RES_ALL_CALCULTIMEOUT ::> $res_all_calcultimeout");
if (!$res_all_calcultimeout) {
$prompt="prepaid-no-enough-credit";
$agi->stream_file($prompt, '#');
return -1;
}
[b]}[/b]
// calculate timeout
//$this->timeout = intval(($this->credit * 60 * 100) / $rate);
That's all. Comments?
regards,
-rs-
Added after 2 minutes: LOL sorry... I've never posted anything before. I thought I can use BOLD and CODE together
the changes are between
and
regards,
-rs-
Added after 1 minutes: Man.. I'm really suck at this..
The changes is between [ b ] and [ /b ].
regards,
-rs-