Logic behind simultaneous calls and maintain the balance
Page 2 of 2

Author:  jimmy888 [ Fri Dec 18, 2009 6:22 am ]
Post subject:  negative balance when canreinvite is enabled

Hi, Sir:
I found that when canreinvite=yes is enabled, even restrict to single channel phone call will result in negative balance in calling card case. My understanding is that when caller initially calls the system, the asterisk uses Dial() command to make the call to termination. But after sip reinvite, the a2billing essentially handles the call to the caller and the callee directly. And it appears that it doesn't actively monitor the call any more. So when the call lasts longer than the credit allows, the call still continues between caller and callee. When the caller or callee finally hang up, the server updates the cc_card record, resulting in negative balance.
I wonder if there is any way to resolve this. sip reinvite is very useful in reducing the server bandwidth usage and improve call quality. But this negative balance is preventing me from using it. If somebody can point me to the method and where to make the code change, I will try to get this done.
I am using 1.3.2 A2B and 1.4 asterisk.

Author:  jroper [ Fri Dec 18, 2009 9:13 am ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance


Can you show us what you have put in your dialcommand_param in the agi-conf.

With the default settings (L), I don't think a re-invite happens, as there is a possibility that Asterisk will have to play some more IVR, so you have to change this to an S.


Author:  asiby [ Sun Jan 10, 2010 6:27 pm ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance


Happy new year 2010. I wish more donation and success for A2Billing.

I am using reinvite and I have never noticed that it could be the cause for negative balance. That is something to investigate.

During one of our experiments with asterisk, we have noticed that asterisk is able to dynamically put itself in the rtp path when necessary. So basically, the rtp debug was not showing a single rtp packet while the sip debug was showing lots of them. But as soon as we entered the code for spying on a channel or monitoring the call, the rtp packets started going through asterisk. Then after finish our spying or monitoring, the rtp disapeared from asterisk and started going directly from the caller to the callee.

When using reinvite, the signaling is still routed through asterisk, and that's all that is needed in order to disconnect the call when that time comes. I don't thing that asterisk monitors the rtp waiting for the disconnection time to arrive. It merely sets a timer that determines when a call must be disconnected regardless of the reinvite status.


Author:  toxi [ Fri Feb 27, 2015 7:23 am ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance

There is a problem: You can write code that will disable users who ended the balance, even if they speak at this time? To balance did not go negative. Maybe we can somehow change the timeout value when there is a conversation?
Help solve the problem.

A2Billing v2.0.16

min_credit_2call = 0.25 (0.99, 0.00)
min_duration_2bill = 0
dialcommand_param = |60|HRrL(%timeout%:61000:00000)
dial_balance_reservation = 0.0

When the per-minute billing (per 1 minute), min_duration_2bill = 60, dial_balance_reservation = 0.0
-2.886 USD
-5.352 USD
-9.952 USD

With per-second billing, min_duration_2bill = 1, dial_balance_reservation = 0.99
-0.792 USD
-0.992 USD

If you disable per-second counter (without dropping a call) and without "pre-booking" the cost of the call
-0.139 USD

From -0,139 to -5.352 USD

I think that, in order to properly calculate the balance of the subscriber (without a care in the negative), then you need to call is managed by the AGI script to specify the settings to connect to the database and the fields to be read and updated.

That is, I can see this logic:
The call came in the context, then went to the AGI, following script to check the current balance if it is positive, then send the call to the trunk through it, while if the other side responded, the script updates every second balance basis, taking into account the cost of direction, then reads the new value of the balance sheet and check if the balance is greater than 0, then continue to perform call / update the balance. In this second call from the same account will receive the current balance and at the same time to update the timeout counter for all active calls / channels on actual data. Upon reaching the 0 on the balance sheet, the script that got 0 when checking automatically stops all other calculations and breaks all active connections account. In this follow-up calls are already locked, as the balance of 0 (even if for 1 sec. Will be two calls at the same time, in the same second, which is almost impossible), as the script will handle each call separately.

Author:  jroper [ Fri Feb 27, 2015 8:52 am ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance


If i understand correctly, you want to check the current balance almost continuously. The hits on the database for several hundred concurrent calls may be huge, and the revenue you keep by not allowing any negative balance may exceed the revenue you lose by not being able to have as higher call capacity on your hardware.

Now that Asterisk allows execution of dialplan after the AGI-Conf has hung-up, there may be a halfway house solution with less load on the platform by extending the dialplan we have at ... ls-module/ which limits the number of concurrent VoIP calls in dialplan.

It could be extended that each time a call is hung-up, the balance is checked for that customer, and if the balance is less than the minimum credit to call, then hang-up all calls belonging to that customer.

There would still be the possibility of negative balance, but the figures would be very much lower.


Author:  toxi [ Fri Feb 27, 2015 9:35 am ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance

Where can I find these settings?

Author:  jroper [ Fri Feb 27, 2015 9:45 am ]
Post subject:  Re: Logic behind simultaneous calls and maintain the balance


There are settings in the database to set the number of concurrent calls, but no code in A2Billing to respect these settings.

We have written some dialplan to refer to these database settings, which you are welcome to purchase. We can also provide a quote to extend this functionality as described in my last post.

Alternatively, you can write your own dialplan to do the same thing.


Page 2 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group