diff --git a/data/test.kch b/data/test.kch index efa620ffa..b6fe7ab2c 100644 Binary files a/data/test.kch and b/data/test.kch differ diff --git a/data/test_activation_periods.json b/data/test_activation_periods.json index ee42cf1fe..cb1a8d2ee 100644 --- a/data/test_activation_periods.json +++ b/data/test_activation_periods.json @@ -30,6 +30,13 @@ } ] }, +{"TOR": "0","CstmId":"1","Subject":"1000","DestinationPrefix":"service", "ActivationPeriods": [ + {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ + {"BillingUnit":60,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":1,"StartTime":"","EndTime":""} + ] + } + ] +}, {"TOR": "0","CstmId":"vdf","Subject":"minutosu","DestinationPrefix":"0723", "ActivationPeriods": [ {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ {"BillingUnit":60,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":1,"StartTime":"","EndTime":""} diff --git a/data/test_destinations.json b/data/test_destinations.json index 6d18e55cb..b2fdda58a 100644 --- a/data/test_destinations.json +++ b/data/test_destinations.json @@ -2,5 +2,6 @@ {"Id":"nationale", "Prefixes":["0256","0257","0723","0740"]}, {"Id":"retea", "Prefixes":["0723","0724"]}, {"Id":"mobil", "Prefixes":["0723","0740"]}, -{"Id":"radu", "Prefixes":["0723045326"]} +{"Id":"radu", "Prefixes":["0723045326"]}, +{"Id":"freeswitch", "Prefixes":["service"]} ] diff --git a/data/test_tariffplans.json b/data/test_tariffplans.json index 3fc95b306..251a79b67 100644 --- a/data/test_tariffplans.json +++ b/data/test_tariffplans.json @@ -12,6 +12,6 @@ [{"Seconds":100,"Priority":10,"Price":0.01,"DestinationId":"nationale"}, {"Seconds":1000,"Priority":20,"Price":0,"DestinationId":"retea"}], "VolumeDiscountThresholds": [{"Volume": 100, "Discount": 10},{"Volume": 500, "Discount": 15},{"Volume": 1000, "Discount": 20}] - } + } ] diff --git a/data/test_userbudgets.json b/data/test_userbudgets.json index 528ac8f31..b5b2dc5be 100644 --- a/data/test_userbudgets.json +++ b/data/test_userbudgets.json @@ -3,6 +3,9 @@ [{"Seconds":10,"Priority":10,"Price":0.01,"DestinationId":"nationale"}, {"Seconds":100,"Priority":20,"Price":0,"DestinationId":"retea"}]}, {"Id":"broker","Credit":0,"SmsCredit":0,"Traffic":0,"VolumeDiscountSeconds":0,"ReceivedCallSeconds":0,"ResetDayOfTheMonth":10,"TariffPlanId":"seara","MinuteBuckets": + [{"Seconds":10,"Priority":10,"Price":0.01,"DestinationId":"nationale"}, + {"Seconds":100,"Priority":20,"Price":0,"DestinationId":"retea"}]}, +{"Id":"1000","Credit":0,"SmsCredit":0,"Traffic":0,"VolumeDiscountSeconds":0,"ReceivedCallSeconds":0,"ResetDayOfTheMonth":10,"TariffPlanId":"seara","MinuteBuckets": [{"Seconds":10,"Priority":10,"Price":0.01,"DestinationId":"nationale"}, {"Seconds":100,"Priority":20,"Price":0,"DestinationId":"retea"}]} ] diff --git a/sessionmanager/sessiondelegate.go b/sessionmanager/sessiondelegate.go index 53780d3f7..c9905b757 100644 --- a/sessionmanager/sessiondelegate.go +++ b/sessionmanager/sessiondelegate.go @@ -56,6 +56,7 @@ func (dsd *DirectSessionDelegate) OnHeartBeat(ev *Event) { func (dsd *DirectSessionDelegate) OnChannelAnswer(ev *Event, s *Session) { s.callDescriptor.Amount = DEBIT_PERIOD.Seconds() + s.callDescriptor.SetStorageGetter(storageGetter) remainingSeconds, err := s.callDescriptor.GetMaxSessionTime() if remainingSeconds == 0 || err != nil { log.Print("No credit left: Disconnect!") @@ -70,6 +71,7 @@ func (dsd *DirectSessionDelegate) OnChannelHangupComplete(ev *Event, s *Session) } func (dsd *DirectSessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor) { + cd.SetStorageGetter(storageGetter) cc, err := cd.Debit() if err != nil { log.Printf("Could not complete debit opperation: %v", err) diff --git a/sessionmanager/sessionmanager.go b/sessionmanager/sessionmanager.go index 49e2ddfaf..4987b1d6a 100644 --- a/sessionmanager/sessionmanager.go +++ b/sessionmanager/sessionmanager.go @@ -99,6 +99,7 @@ func (sm *SessionManager) OnHeartBeat(ev *Event) { func (sm *SessionManager) OnChannelAnswer(ev *Event) { if sm.sessionDelegate != nil { s := NewSession(ev, sm.sessionDelegate) + sm.sessions = append(sm.sessions, s) sm.sessionDelegate.OnChannelAnswer(ev, s) } else { log.Print("answer") diff --git a/timespans/calldesc.go b/timespans/calldesc.go index bf22b7984..92d215c57 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -20,7 +20,7 @@ package timespans import ( "fmt" - // "log" + "log" "math" "time" ) @@ -298,12 +298,17 @@ func (cd *CallDescriptor) GetMaxSessionTime() (seconds float64, err error) { // from user's money budget. func (cd *CallDescriptor) Debit() (cc *CallCost, err error) { cc, err = cd.GetCost() + if err != nil { + log.Printf("error getting cost %v", err) + } if userBudget, err := cd.getUserBudget(); err == nil && userBudget != nil { if cc.Cost != 0 || cc.ConnectFee != 0 { userBudget.debitMoneyBudget(cd.storageGetter, cc.Cost+cc.ConnectFee) } for _, ts := range cc.Timespans { - userBudget.debitMinutesBudget(cd.storageGetter, ts.MinuteInfo.Quantity, cd.DestinationPrefix) + if ts.MinuteInfo != nil { + userBudget.debitMinutesBudget(cd.storageGetter, ts.MinuteInfo.Quantity, cd.DestinationPrefix) + } } } return