Difference between revisions of "Prepaid Logic"
Line 20: | Line 20: | ||
When the user makes his first call to Lithuania MOB: | When the user makes his first call to Lithuania MOB: | ||
* MOR freezes his balance | * MOR freezes his balance of 6 EUR (30 min * 0.2 EUR/min). | ||
* Now the user has 8 EUR in his balance where 6 EUR are frozen (2 EUR left free). | * Now the user has 8 EUR in his balance where 6 EUR are frozen (2 EUR left free). | ||
* The call limit for this call is 30 minutes. | * The call limit for this call is 30 minutes. | ||
When the user makes a second call to Lithuania MOB (first call is in progress): | When the user makes a second call to Lithuania MOB (the first call is in progress): | ||
* MOR freezes the remaining 2 EUR of the user's not-frozen balance. | * MOR freezes the remaining 2 EUR of the user's not-frozen balance. | ||
* Now the user has 8 EUR frozen balance and 0 left as unfrozen. | * Now the user has 8 EUR frozen balance and 0 left as unfrozen. | ||
* The call limit for this call is 10 min (2 EUR / 0.2 EUR/min). | * The call limit for this call is 10 min (2 EUR / 0.2 EUR/min). | ||
When the user makes a third call to Lithuania MOB (first and second calls are in progress): | When the user makes a third call to Lithuania MOB (the first and second calls are in progress): | ||
* The call is dropped because there is no free balance to cover the call. | * The call is dropped because there is no free balance to cover the call. | ||
Revision as of 05:21, 30 April 2010
Explanation
Prepaid Logic applies only to Prepaid users.
In /etc/asterisk/mor.conf value frozen_time describes the maximum time for calls by prepaid users.
When a user makes a call, his balance is frozen by the amount which is necessary to make the maximum length of the call (frozen_time).
If the user talks for less time, his part of the balance is unfrozen and the correct amount is deducted.
If the user talks for a time which is equal to frozen_time, then his call ends automatically after the frozen_time minutes are up.
Example
/etc/asterisk/mor.conf frozen_time = 3
A call minute to Lithuania MOB costs 0.2 EUR/min.
A prepaid user has 8 EUR in his balance.
When the user makes his first call to Lithuania MOB:
- MOR freezes his balance of 6 EUR (30 min * 0.2 EUR/min).
- Now the user has 8 EUR in his balance where 6 EUR are frozen (2 EUR left free).
- The call limit for this call is 30 minutes.
When the user makes a second call to Lithuania MOB (the first call is in progress):
- MOR freezes the remaining 2 EUR of the user's not-frozen balance.
- Now the user has 8 EUR frozen balance and 0 left as unfrozen.
- The call limit for this call is 10 min (2 EUR / 0.2 EUR/min).
When the user makes a third call to Lithuania MOB (the first and second calls are in progress):
- The call is dropped because there is no free balance to cover the call.
When the user hangs up his first call, let's say after 12 minutes:
- His balance is unfrozen by 6 EUR.
- 2.4 EUR (12min * 0.2 EUR/min) is deducted from the user's balance, so now the user will have a total balance of 5.6 EUR (8 - 2.4), where 2 EUR is still frozen by second call.
- Now user can make a fourth call while the second is still in progress, and the length of the fourth call would be (5.6 - 2) / 0.2 = 18 minutes.
When the user hangs up his second call, say with a length of 9 minutes (and there is no fourth call), we have this situation:
- The balance is unfrozen by 2 EUR.
- The call price is 9 * 0.2 = 1.8 EUR, so the user's balance will be 5.6 - 1.8 = 3.8 EUR. And none of this amount is frozen.
If the user talks for 10 minutes in the second call, this call is automatically ended by the system.
This logic prevents any loss to the system owner. It applies stricter rules, but this pays off in the long run.
Special case
When only 1 simultaneous call is allowed for device and/or user (Call Limit = 1) then frozen_balance is not used.
E.g. #1: If User/Device is limited to only 1 call at a time, that means it can use all his remaining balance for the call (if User is prepaid).
E.g. #2: Call will last till balance will run out.
NOTE: 2 hours is hardcoded call limit for all calls. If balance allows longer calls then 2 hours - call will be limited to 2 hours.
If user has Call Limit not 1, but his one device (D1) has Call Limit == 1 and another device (D2) Call Limit not 1 , then device D1 will be able to make 1 simm. call with duration 2h, and ONLY if it is enough balance to cover for frozen_time - device D2 calls will be limited to frozen_time.
Calling Card calls are always limited to 1 call. E.g. at same time calling card can make only 1 call (for whole available balance).
Questions
Q. What would happen if an user has balance lower than the cost of a "maximum duration" call?
A. User will be allowed to talk only such amount which is covered by his balance. Example: Maximum duration = 2h. User has enough balance for 1h. So his call will be limited to 1h. After 1h his call will end (system will terminate it) and you will not take any loss.