sending amount in get max session time

This commit is contained in:
Radu Ioan Fericean
2012-09-19 14:43:18 +03:00
parent e1748c8c4a
commit a43bfeedfd
2 changed files with 3 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ func (rsd *SessionDelegate) OnChannelPark(ev Event, sm SessionManager) {
Subject: ev.GetSubject(),
Account: ev.GetAccount(),
Destination: ev.GetDestination(),
Amount: rsd.DebitPeriod.Seconds(),
TimeStart: startTime}
var remainingSeconds float64
err = rsd.Connector.GetMaxSessionTime(cd, &remainingSeconds)

View File

@@ -292,11 +292,13 @@ func (cd *CallDescriptor) GetMaxSessionTime() (seconds float64, err error) {
_, err = cd.LoadActivationPeriods()
now := time.Now()
availableCredit, availableSeconds := 0.0, 0.0
Logger.Debug(fmt.Sprintf("cd: %+v", cd))
if userBalance, err := cd.getUserBalance(); err == nil && userBalance != nil {
if userBalance.Type == UB_TYPE_POSTPAID {
return -1, nil
} else {
availableSeconds, availableCredit, _ = userBalance.getSecondsForPrefix(cd.Destination)
Logger.Debug(fmt.Sprintf("available sec: %v credit: %v", availableSeconds, availableCredit))
}
} else {
return cd.Amount, err
@@ -305,7 +307,6 @@ func (cd *CallDescriptor) GetMaxSessionTime() (seconds float64, err error) {
if availableCredit == 0 {
return availableSeconds, nil
}
// the price of a seccond cannot be determined because all the seconds can have a different cost.
// therfore we get the cost for the whole period and then if there are not enough money we backout in steps of 10%.
maxSessionSeconds := cd.Amount