mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
fixed max debit function
This commit is contained in:
@@ -499,16 +499,15 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) {
|
||||
|
||||
// Interface method used to add/substract an amount of cents or bonus seconds (as returned by GetCost method)
|
||||
// from user's money balance.
|
||||
// This methods combines the Debit and GetMaxSessionTime and will debit the max available time as returned
|
||||
// This methods combines the Debit and GetMaxSessionDuration and will debit the max available time as returned
|
||||
// by the GetMaxSessionTime method. The amount filed has to be filled in call descriptor.
|
||||
func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
|
||||
remainingSeconds, err := cd.GetMaxSessionDuration()
|
||||
// Logger.Debug(fmt.Sprintf("In MaxDebitd remaining seconds: %v", remainingSeconds))
|
||||
if err != nil || remainingSeconds == 0 {
|
||||
remainingDuration, err := cd.GetMaxSessionDuration()
|
||||
if err != nil || remainingDuration == 0 {
|
||||
return new(CallCost), errors.New("no more credit")
|
||||
}
|
||||
if remainingSeconds > 0 { // for postpaying client returns -1
|
||||
cd.TimeEnd = cd.TimeStart.Add(time.Duration(remainingSeconds) * time.Second)
|
||||
if remainingDuration > 0 { // for postpaying client returns -1
|
||||
cd.TimeEnd = cd.TimeStart.Add(remainingDuration)
|
||||
}
|
||||
return cd.Debit()
|
||||
}
|
||||
|
||||
@@ -22,14 +22,15 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/fsock"
|
||||
"log/syslog"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/fsock"
|
||||
)
|
||||
|
||||
var cfg *config.CGRConfig // Share the configuration with the rest of the package
|
||||
@@ -163,15 +164,16 @@ func (sm *FSSessionManager) OnChannelPark(ev Event) {
|
||||
Destination: ev.GetDestination(),
|
||||
Amount: sm.debitPeriod.Seconds(),
|
||||
TimeStart: startTime}
|
||||
var remainingSeconds float64
|
||||
err = sm.connector.GetMaxSessionTime(cd, &remainingSeconds)
|
||||
var remainingDurationFloat float64
|
||||
err = sm.connector.GetMaxSessionTime(cd, &remainingDurationFloat)
|
||||
if err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("Could not get max session time for %s: %v", ev.GetUUID(), err))
|
||||
sm.unparkCall(ev.GetUUID(), ev.GetCallDestNr(), SYSTEM_ERROR)
|
||||
return
|
||||
}
|
||||
engine.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingSeconds))
|
||||
if remainingSeconds == 0 {
|
||||
remainingDuration := time.Duration(remainingDurationFloat)
|
||||
engine.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingDuration))
|
||||
if remainingDuration == 0 {
|
||||
engine.Logger.Info(fmt.Sprintf("Not enough credit for trasferring the call %s for %s.", ev.GetUUID(), cd.GetKey(cd.Subject)))
|
||||
sm.unparkCall(ev.GetUUID(), ev.GetCallDestNr(), INSUFFICIENT_FUNDS)
|
||||
return
|
||||
@@ -294,7 +296,6 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
func (sm *FSSessionManager) LoopAction(s *Session, cd *engine.CallDescriptor, index float64) (cc *engine.CallCost) {
|
||||
cc = &engine.CallCost{}
|
||||
cd.LoopIndex = index
|
||||
cd.Amount = sm.debitPeriod.Seconds()
|
||||
cd.CallDuration += sm.debitPeriod
|
||||
err := sm.connector.MaxDebit(*cd, cc)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user