RE: [Asterisk-Users] billing realtime
[EMAIL PROTECTED] wrote: Hi Senad i looking for same thing, that is consider absolutetimeout as a timer, everytime is near t zero, 3 secs for example, renew it, reacalculate real credit, and start again until some of the parties hangup. The problem is how to iterate in asterisk config, or in deadagi, you will need some time values from asterisk anyway, CDR{billsec} and CDR{duration}, because i think we have to give this control to asterisk, he really knows the timing of calls. Now the problem number two. Asterisk set those values above, when the call is completely finished, i have tried with deadagi in php whit sleep function, nothing, the values of the varialbles are set after hangup extension, after deadagi final execution. If I understood well, when each call is made u give him duration time based on the billing. Its wrong direction at start. The only possible solution is in the asterisk. You need global variable with total time for all channels, then you need the timer. Timer can be one by each channel, and each channel timer decrements same global time variable when it becomes a zero or less terminate all active channels for that account. The other way would be to have one timer who decrements global time variable based on number of active channels. Timer is inactive when there is no active channels for account. To explain this, if timer decrement cycle is n second then he should decrement global remained time variable ACCOUNT_TIME = ACCOUNT_TIME- (n active channels at the moment) x (timer cycle in seconds). Then check condition ACCOUNT_TIME = 0 if true hangup all active channels for that account. Then check condition (n active channels for account == 0) if true stop the timer. The n active channels should be checked on asterisk. If you create account time variable when first channel of account becomes active like AV_{some id} and timer who will process this remaining time. Then on each new channel for that account you just increment other variable NAC_{some id} or decrement. The best is that this variables be asterisk variables (global). We have not tried above, so be my guest if you have free time :) Senad ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
How about AstRTB ? Asterisk Real Time Billing --- Thameem Ansari [EMAIL PROTECTED] wrote: Hello All, 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. 1. Keep on db table for balance and reserver_balance. 2. First call coming to agi, check the balance - Sum of all the reserve_balance of that account code. 3. Check the destination and allowed minutes for that balance amount from step 2. 4. Reserve balance table will contain destination, amount, reserved secs columns 5. If the avaialable balance is = 0 then announce not enough credit and hangup. 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) then set absolutetimeout for those seconds. 7. Otherwise the allowed seconds is more than the allowed seconds, set absolute time out for the reserved seconds and make the call. 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. 9. Once the channel status changed to reserved, insert an record to reserve_balance table with uniqueid, accountcode, amount, reserved_secs information. The above steps will handle one call so far now...and lets see how the dial plan should be, 10. In your dial plan, add an AbsoluteTimeout extension T and call another AGI script which will just to reset the absolute timeout. 11. When the particular timeout is reached asterisk will transfer the call to 'T extension which will in turn call another agi. 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. 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). Now lets take the scenario for second call when the first call was active, 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. 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, Call -1 balance = $0.10 destination= 1 (which is US) rate = $0.02 per minute reserveSecs = 10 minutes (600secs) finalBalance = $0.10 - $0 (consider this is first call and no entry in reserve_balance table) = $0.10 allowedMints = $0.10/$0.02 = 5 minutes = 300 seconds. AbsoluteTimeout = 300 seconds (this is less than the default reserveSecs so set this as abstimeout) Call -2 balance = $0.10 destination= 1 (which is US) rate = $0.02 per minute reserveSecs = 10 minutes (600secs) finalBalance = $0.10 - $0.10 (consider this is second call and already an entry in reserve_balance table) = $0.0 allowedMints = 0 seconds. announce the denied ivr. 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. 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. 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. Thanks, Thameem On 4/27/06, JP Carballo [EMAIL PROTECTED] wrote: Dovid Bender wrote: A while back some one posted some code that he used that took out the flag in astcc that kept track if there was a call in progress for that pin or not. Dont know if it wil work for real time though. Dovid I don't know if you were pertaining to what I posted in the message ASTCC: How to reset in-use flag automatically ?. The setinuse() routine already exists in ASTCC. One simply has to use that routine to disable the inuse flag when a call begins and ASTCC will allow multiple calls for the same account. However, I too have no idea if this will work for real time. -- JP Carballo
Re: [Asterisk-Users] billing realtime
Hello All, 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. 1. Keep on db table for balance and reserver_balance. 2. First call coming to agi, check the balance - Sum of all the reserve_balance of that account code. 3. Check the destination and allowed minutes for that balance amount from step 2. 4. Reserve balance table will contain destination, amount, reserved secs columns 5. If the avaialable balance is = 0 then announce not enough credit and hangup. 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) then set absolutetimeout for those seconds. 7. Otherwise the allowed seconds is more than the allowed seconds, set absolute time out for the reserved seconds and make the call. 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. 9. Once the channel status changed to reserved, insert an record to reserve_balance table with uniqueid, accountcode, amount, reserved_secs information. The above steps will handle one call so far now...and lets see how the dial plan should be, 10. In your dial plan, add an AbsoluteTimeout extension T and call another AGI script which will just to reset the absolute timeout. 11. When the particular timeout is reached asterisk will transfer the call to 'T extension which will in turn call another agi. 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. 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). Now lets take the scenario for second call when the first call was active, 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. 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, Call -1 balance = $0.10 destination= 1 (which is US) rate = $0.02 per minute reserveSecs = 10 minutes (600secs) finalBalance = $0.10 - $0 (consider this is first call and no entry in reserve_balance table) = $0.10 allowedMints = $0.10/$0.02 = 5 minutes = 300 seconds. AbsoluteTimeout = 300 seconds (this is less than the default reserveSecs so set this as abstimeout) Call -2 balance = $0.10 destination= 1 (which is US) rate = $0.02 per minute reserveSecs = 10 minutes (600secs) finalBalance = $0.10 - $0.10 (consider this is second call and already an entry in reserve_balance table) = $0.0 allowedMints = 0 seconds. announce the denied ivr. 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. 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. 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. Thanks, Thameem On 4/27/06, JP Carballo [EMAIL PROTECTED] wrote: Dovid Bender wrote:A while back some one posted some code that he usedthat took out the flag in astcc that kept track ifthere was a call in progress for that pin or not. Dontknow if it wil work for real time though. DovidI don't know if you were pertaining to what I posted in the messageASTCC: How to reset in-use flag automatically ?.The setinuse() routine already exists in ASTCC. One simply has to use that routine to disable the inuse flag when a callbegins and ASTCC will allow multiple calls for the same account.However, I too have no idea if this will work for real time.-- JP Carballohttp://www.netfone2x.comBringing the world closer.It might look like I'm doing nothing, but at the cellular level, I'm really quite busy.___ --Bandwidth and Colocation provided by Easynews.com --Asterisk-Users mailing listTo UNSUBSCRIBE or update
Re: [Asterisk-Users] billing realtime
JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? A while back some one posted some code that he used that took out the flag in astcc that kept track if there was a call in progress for that pin or not. Dont know if it wil work for real time though. Dovid __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
Dovid Bender wrote: A while back some one posted some code that he used that took out the flag in astcc that kept track if there was a call in progress for that pin or not. Dont know if it wil work for real time though. Dovid I don't know if you were pertaining to what I posted in the message ASTCC: How to reset in-use flag automatically ?. The setinuse() routine already exists in ASTCC. One simply has to use that routine to disable the inuse flag when a call begins and ASTCC will allow multiple calls for the same account. However, I too have no idea if this will work for real time. -- JP Carballo http://www.netfone2x.com Bringing the world closer. It might look like I'm doing nothing, but at the cellular level, I'm really quite busy. ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
random cluster wrote: Now, the question, can I access somehow in a deadagi, or whatever the CDR function in order to update the credit when the call has just finished. Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. -- JP Carballo http://www.netfone2x.com Bringing the world closer. It might look like I'm doing nothing, but at the cellular level, I'm really quite busy. ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? -- Jon Farmer Telford, Shropshire, UK ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jon, we can do that using ASTPP. The downside is that we don't currently have a way to limit the call lengths so that when they have multiple calls in progress they still can't go over their prepaid limit. On postpaid accounts this is not usually an issue but on prepaid it still is. Darren Wiebe [EMAIL PROTECTED] Jon Farmer wrote: JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFETxRg4DADnh+tnOQRAuhJAJ9kzGiQYh4Z6WPXXes6TKtwusBliwCeMvHG 3nrqsxdXNrfJbCZ3uzlpd5w= =+fV+ -END PGP SIGNATURE- ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
On Wed April 26 2006 16:31, Jon Farmer [EMAIL PROTECTED] wrote: JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? -- Jon Farmer Telford, Shropshire, UK Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? -- Nick e: [EMAIL PROTECTED] p: +61 7 5591 3588 f: +61 7 5591 6588 If you receive this email by mistake, please notify us and do not make any use of the email. We do not waive any privilege, confidentiality or copyright associated with it. ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
Nick Hoffman wrote: Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? -- Nick e: [EMAIL PROTECTED] p: +61 7 5591 3588 f: +61 7 5591 6588 If you receive this email by mistake, please notify us and do not make any use of the email. We do not waive any privilege, confidentiality or copyright associated with it. There's an application (sorry, which one, escapes me at the moment), that gets around this by reserving a certain amount of credit per call. Say the amount is 10 minutes, if you have 30 minutes worth of credit, you can have 3 concurrent calls good for 10 minutes each. The way I understand it, if you only have 15 minutes left in your account, the first call will last for 10 and the next concurrent one for 5 minutes. -- JP Carballo http://www.netfone2x.com Bringing the world closer. It might look like I'm doing nothing, but at the cellular level, I'm really quite busy. ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
RE: [Asterisk-Users] billing realtime
[EMAIL PROTECTED] wrote: On Wed April 26 2006 16:31, Jon Farmer [EMAIL PROTECTED] wrote: JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? -- Jon Farmer Telford, Shropshire, UK Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? The way we solved this is: 1/ Each account has incoming/outgoing channels 2/ Once call is started then the total balance is divided by number of outgoing channels for that account. This sets the time limit. 3/ If more calls are made then each new call has same absolute timeout. Above is not perfect, since we are limiting each call to less talk time then total balance allows, hence why we are currently looking into possibility in changing the value of absolute timeout in memory for each of the calls. Senad ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
Hi Senad i looking for same thing, that is consider absolutetimeout as a timer, everytime is near t zero, 3 secs for example, renew it, reacalculate real credit, and start again until some of the parties hangup. The problem is how to iterate in asterisk config, or in deadagi, you will need some time values from asterisk anyway, CDR{billsec} and CDR{duration}, because i think we have to give this control to asterisk, he really knows the timing of calls. Now the problem number two. Asterisk set those values above, when the call is completely finished, i have tried with deadagi in php whit sleep function, nothing, the values of the varialbles are set after hangup extension, after deadagi final execution. The solution that I looking for is to take a average-time-call, and create a timer with it. Then base on this value, and the price for destination call, every time the average-time-call pass substract the consume credit from the real credit, and set absolute timeout, for this average-time-call. But I dont know how to implement this is asterisk. With pseudo-code while 2006/4/26, Senad Jordanovic [EMAIL PROTECTED]: [EMAIL PROTECTED] wrote: On Wed April 26 2006 16:31, Jon Farmer [EMAIL PROTECTED] wrote: JP Carballo wrote: Yes, certainly, through deadagi. I just have one question though, why reinvent the wheel? There are prepaid systems that work with asterisk. I have yet to find a prepaid system that allows multiple concurrent calls per account. Most seem to be based on a pin number also which I don't want. Anyone know of a system that allows concurrent calls? -- Jon Farmer Telford, Shropshire, UK Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? The way we solved this is: 1/ Each account has incoming/outgoing channels 2/ Once call is started then the total balance is divided by number of outgoing channels for that account. This sets the time limit. 3/ If more calls are made then each new call has same absolute timeout. Above is not perfect, since we are limiting each call to less talk time then total balance allows, hence why we are currently looking into possibility in changing the value of absolute timeout in memory for each of the calls. Senad ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [Asterisk-Users] billing realtime
Nick Hoffman wrote: Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? That is the problem I am asking about :-) -- Jon Farmer Telford, Shropshire, UK ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
RE: [Asterisk-Users] billing realtime
You keep eluding to the answer yourself. Asterisk Manager is the way to go. Check out http://search.cpan.org/~xantus/POE-Component-Client-Asterisk-Manager/. Relatively simple event based method for using Asterisk manager. What I would do is register a handler to track new calls, and calls ending. Every time you get a new call, add it to a hash with the customer_id as the key. Seperately register a callback that keeps re-calling itself at X second intervals. It would cycle through the hash of active calls decrementing remaining time for each, and then kick anyone with 1 second remaining. I have a single script running 12 instances of POE::Component::Client::Asterisk::Manager (1 for each of 12 servers) under a single POE kernel to track 2500 channels (comings and goings of MeetMe users) and it's had no problem keeping up. Just make sure that you avoid any long running loops as POE is not multi-threaded. For something like this, I think you'll find 1 instance of a single script much easier to track and debug than a whole bunch of instance of an AGI script. Josh McAllister -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jon Farmer Sent: Wednesday, April 26, 2006 7:27 AM To: [EMAIL PROTECTED] Cc: asterisk-users@lists.digium.com Subject: Re: [Asterisk-Users] billing realtime Nick Hoffman wrote: Hi Jon. If a customer has 10 minutes of call credit left and he makes 2 concurrent calls, how do you know to cut off the 2 calls at the 5 minute mark rather than cut off both calls after 10 minutes? That is the problem I am asking about :-) -- Jon Farmer Telford, Shropshire, UK ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users ___ --Bandwidth and Colocation provided by Easynews.com -- Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users