1

we do allow him to call based on his current balance, the call is scheduled for 10 min, next call comes in it is also scheduled for 10 min because the customer balance was not updated as his first call is still in process. we only update the balance when a call is disconnected. in this way balance will go negative. but is there is any solution to this problem so that balance do not go negative ?

kikito
  • 51,734
  • 32
  • 149
  • 189
Khawer Zeshan
  • 9,470
  • 6
  • 40
  • 63
  • This question is not about Lua. – lhf Dec 14 '11 at 16:21
  • possible duplicate of [How to deduct caller balance while he is still on a connected line using freeswitch](http://stackoverflow.com/questions/8504488/how-to-deduct-caller-balance-while-he-is-still-on-a-connected-line-using-freeswi) – finnw Dec 14 '11 at 21:14

1 Answers1

2

Banks solves this problem by placing a "hold" on the funds, and tracking two separate balances: the current balance (all money in the account) and the available balance (which is the current balance, minus the total of all the "holds" on all funds outstanding).

Let's say you have a balance of $10, and the calls cost $1/minute.

The idea is that your first 10 minute call wouldn't actually deduct the funds before it was done, but it would say, "Hey, I'm going to need $10 out of the current balance." The money, as you said, is only actually taken away when the call is disconnected.

However, because the "hold" on that $10 is already in place, when the second call is setup, it checks the balance and says, "Hey I'm going to need $10," but the algorithm would take the total balance ($10) and subtract the total of all the "hold" amounts ($10), and return $0.

So, basically the second call wouldn't get setup, because you balance algorithm would say, "Yes you've got $10 in your account, but you've currently reserved $10 of that, leaving you with $0 'available balance'. Therefore, I can't reserve the time for your call unless you either cancel your first call, or add more money to your balance."

jefflunt
  • 33,527
  • 7
  • 88
  • 126
  • the way you are suggesting first call will take all the balance and will not allow you to make second call which is not good – Khawer Zeshan Dec 14 '11 at 13:56
  • as we dont know for how long he wants to talk on the line so reserving balance for his call is not a good idea – Khawer Zeshan Dec 14 '11 at 13:57
  • we allow simultaneous calls , multiple calls can be connected at the same time , a customer can have 5 calls connected or more – Khawer Zeshan Dec 14 '11 at 13:58
  • Well, there are essentially two ways to do this. You can either put holds on funds (preventing users from scheduling more calls than they can afford) or you can do what you're currently doing, and letting them run on credit (with a negative balance) and get the money back from them later. Instead of thinking of this in terms of a balance, imagine the same scenario, but with cash. If someone wants to make $20 in calls, but they only have $10 in their pocket, you either can't let them place more calls than they can afford to pre-pay, or you have to extend them credit. – jefflunt Dec 14 '11 at 13:59
  • 1
    Allowing people to potentially place more calls than they can afford, without some mechanism for getting that money back at some later date, essentially lets your users get as many free calls as they want, because they only have to pay for the first call, never hang up, and then just keep placing additional calls for no cost. Or, if the first call is limited by time, they can pay for a 5 minute call, but then reserve as many 1,000 minute calls as they like. So long as those secondary calls start before the first, 5-minute call ends, they will still get calls for free. – jefflunt Dec 14 '11 at 14:01
  • the problem is with simultaneous calls. i have one call connected i do not disconnect it and i made another call so now there are 2 calls connected. i cannot reserve the balance for the first call if i will do so he wont be able to make another call. – Khawer Zeshan Dec 14 '11 at 14:04
  • I understand that, but if you don't reserve that money, people will be able to make free calls, and rip you off. Simultaneous calls are fine, but that means you have to be okay with them having a negative balance some of the time (if they go negative, you simply prevent reservation of any NEW calls after that point). Basically I'm saying that you can't have **both** (a) an always positive balance and (b) a system that allows unlimited, reserved, simultaneous calls that might exceed the current balance in their account. You have to choose one or the other. – jefflunt Dec 14 '11 at 14:04
  • yes i agree with your last comment . actually this is the problem and i want its solution . you got it right that eventually they will be able to get free calls if first call never hangup – Khawer Zeshan Dec 14 '11 at 14:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5851/discussion-between-khawer-zeshan-and-normalocity) – Khawer Zeshan Dec 14 '11 at 14:08