Hello All,<br>
<br>
I had the same question when I was writing my own billing software in
java. Here is what I am doing to track multiple calls at a time from
the prepaid account. <br>
<br>
1. Keep on db table for balance and reserver_balance.<br>
2. First call coming to agi, check the balance - Sum of all the reserve_balance of that account code. <br>
3. Check the destination and allowed minutes for that balance amount from step 2. <br>
4. Reserve balance table will contain destination, amount, reserved secs columns<br>
5. If the avaialable balance is <= 0 then announce not enough credit and hangup. <br>
6. If the available balance is > 0 but seconds allowed to talk is
less than reserved secs (see step 8 for more details about what this is)<br>
then set absolutetimeout for those seconds.<br>
7. Otherwise the allowed seconds is more than the allowed seconds, set
absolute time out for the reserved seconds and make the call.<br>
8. Reserved secs is a custom constant seconds, say you can reserve fund
for 3 minutes (180 seconds). if the account has balance for only 2
minutes (120 seconds) then the absolute time out will be 120 seconds. <br>
9. Once the channel status changed to reserved, insert an record to
reserve_balance table with uniqueid, accountcode, amount, reserved_secs
information. <br>
<br>
The above steps will handle one call so far now...and lets see how the dial plan should be,<br>
10. In your dial plan, add an AbsoluteTimeout extension "T" and call
another AGI script which will just to reset the absolute timeout.<br>
11. When the particular timeout is reached asterisk will transfer the
call to 'T" extension which will in turn call another agi. <br>
12. The agi will receive all the information about the channel
including uniqueid, repeat the steps 2- 7 (except dial) and reset the
abstimeout and this process will repeat until the channel hangup. <br>
13. Once the channel hangup, you can either use Manager to receive the
cdr event or you can set "h" extension (not reliable and not
recommended) to calculate the real balance and update the balance
table. Once you update the balance table, remove the record from
reserve_balance table for the uniqueid, channel and accountcode. (these
three are enough to find out the entry in that table).<br>
<br>
Now lets take the scenario for second call when the first call was active, <br>
14. When the second call comes in, start from step 2. In step 2, we are
doing finalBalance = Balance - Sum(reserve_balance) for that account
code. If there is already a call on this accountcode, then this table
will have one entry and the reserved amount. Get the finalBalance by
subtracting the amounts. Follow step 3 and allow or deny the caller.<br>
The above said solution is very stable and doesn't overflow the memory
or session and not using any threads. The only restriction here is, if
we have the scenario, <br>
<br>
Call -1 <br>
balance = $0.10 <br>
destination= 1 (which is US) <br>
rate = $0.02 per minute<br>
reserveSecs = 10 minutes (600secs)<br>
finalBalance = $0.10 - $0 (consider this is first call and no entry in reserve_balance table) = $0.10 <br>
allowedMints = $0.10/$0.02 = 5 minutes = 300 seconds. <br>
AbsoluteTimeout = 300 seconds (this is less than the default reserveSecs so set this as abstimeout)<br>
<br>
Call -2<br>
balance = $0.10 <br>
destination= 1 (which is US) <br>
rate = $0.02 per minute<br>
reserveSecs = 10 minutes (600secs)<br>
finalBalance = $0.10 - $0.10 (consider this is second call and already an entry in reserve_balance table) = $0.0<br>
allowedMints = 0 seconds. <br>
announce the denied ivr. <br>
<br>
So, the reserveSecs is critical to avoid how much threshold amount the
caller should have to make two calls. If they have $10 in their account
as per the above two algorithms, they can make as many simultaneous
calls. <br>
<br>
I hope this solves most of your problems. I looked at ASTCC, A2Billing
etc and they are not doing this way and not know whether they work
properly. But this works for me. Shoot me your questions if you have
one. <br>
<br>
I am developing my own billing and routing app (in java) and I need a
name for that.. guys pls suggest one.. i may put that in sourceforge if
i feel confident. <br>
<br>
Thanks,<br>
Thameem<br>
<br><br><div><span class="gmail_quote">On 4/27/06, <b class="gmail_sendername">JP Carballo</b> <<a href="mailto:lists@netfone2x.com">lists@netfone2x.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dovid Bender wrote:<br><br>>A while back some one posted some code that he used<br>>that took out the flag in astcc that kept track if<br>>there was a call in progress for that pin or not. Dont<br>>know if it wil work for real time though.
<br>><br>>Dovid<br>><br>><br>I don't know if you were pertaining to what I posted in the message<br>"ASTCC: How to reset "in-use" flag automatically ?".<br>The setinuse() routine already exists in ASTCC.
<br>One simply has to use that routine to disable the inuse flag when a call<br>begins and ASTCC will allow multiple calls for the same account.<br><br>However, I too have no idea if this will work for real time.<br><br>--
<br>JP Carballo<br><br><a href="http://www.netfone2x.com">http://www.netfone2x.com</a><br>Bringing the world closer.<br><br>It might look like I'm doing nothing, but at the cellular level, I'm really quite busy.<br><br>_______________________________________________
<br>--Bandwidth and Colocation provided by <a href="http://Easynews.com">Easynews.com</a> --<br><br>Asterisk-Users mailing list<br>To UNSUBSCRIBE or update options visit:<br> <a href="http://lists.digium.com/mailman/listinfo/asterisk-users">
http://lists.digium.com/mailman/listinfo/asterisk-users</a><br></blockquote></div><br>