diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go
index 4864eff69..a9786470c 100644
--- a/apier/v1/apier_local_test.go
+++ b/apier/v1/apier_local_test.go
@@ -1115,42 +1115,42 @@ func TestApierRemActionTiming(t *testing.T) {
}
}
-// Test here GetBalance
-func TestApierGetBalance(t *testing.T) {
+// Test here GetUserBalance
+func TestApierGetUserBalance(t *testing.T) {
if !*testLocal {
return
}
var reply *engine.UserBalance
attrs := &AttrGetUserBalance{Tenant: "cgrates.org", Account: "1001", BalanceId: "*monetary", Direction: "*out"}
- if err := rater.Call("ApierV1.GetBalance", attrs, &reply); err != nil {
- t.Error("Got error on ApierV1.GetBalance: ", err.Error())
+ if err := rater.Call("ApierV1.GetUserBalance", attrs, &reply); err != nil {
+ t.Error("Got error on ApierV1.GetUserBalance: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceId+attrs.Direction].GetTotalValue() != 11.5 { // We expect 11.5 since we have added in the previous test 1.5
t.Errorf("Calling ApierV1.GetBalance expected: 11.5, received: %f", reply)
}
attrs = &AttrGetUserBalance{Tenant: "cgrates.org", Account: "dan", BalanceId: "*monetary", Direction: "*out"}
- if err := rater.Call("ApierV1.GetBalance", attrs, &reply); err != nil {
- t.Error("Got error on ApierV1.GetBalance: ", err.Error())
+ if err := rater.Call("ApierV1.GetUserBalance", attrs, &reply); err != nil {
+ t.Error("Got error on ApierV1.GetUserBalance: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceId+attrs.Direction].GetTotalValue() != 1.5 {
- t.Errorf("Calling ApierV1.GetBalance expected: 1.5, received: %f", reply)
+ t.Errorf("Calling ApierV1.GetUserBalance expected: 1.5, received: %f", reply)
}
// The one we have topped up though executeAction
attrs = &AttrGetUserBalance{Tenant: "cgrates.org", Account: "dan2", BalanceId: "*monetary", Direction: "*out"}
- if err := rater.Call("ApierV1.GetBalance", attrs, &reply); err != nil {
- t.Error("Got error on ApierV1.GetBalance: ", err.Error())
+ if err := rater.Call("ApierV1.GetUserBalance", attrs, &reply); err != nil {
+ t.Error("Got error on ApierV1.GetUserBalance: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceId+attrs.Direction].GetTotalValue() != 10 {
- t.Errorf("Calling ApierV1.GetBalance expected: 10, received: %f", reply)
+ t.Errorf("Calling ApierV1.GetUserBalance expected: 10, received: %f", reply)
}
attrs = &AttrGetUserBalance{Tenant: "cgrates.org", Account: "dan3", BalanceId: "*monetary", Direction: "*out"}
- if err := rater.Call("ApierV1.GetBalance", attrs, &reply); err != nil {
- t.Error("Got error on ApierV1.GetBalance: ", err.Error())
+ if err := rater.Call("ApierV1.GetUserBalance", attrs, &reply); err != nil {
+ t.Error("Got error on ApierV1.GetUserBalance: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceId+attrs.Direction].GetTotalValue() != 3.6 {
- t.Errorf("Calling ApierV1.GetBalance expected: 3.6, received: %f", reply)
+ t.Errorf("Calling ApierV1.GetUserBalance expected: 3.6, received: %f", reply)
}
attrs = &AttrGetUserBalance{Tenant: "cgrates.org", Account: "dan6", BalanceId: "*monetary", Direction: "*out"}
- if err := rater.Call("ApierV1.GetBalance", attrs, &reply); err != nil {
- t.Error("Got error on ApierV1.GetBalance: ", err.Error())
+ if err := rater.Call("ApierV1.GetUserBalance", attrs, &reply); err != nil {
+ t.Error("Got error on ApierV1.GetUserBalance: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceId+attrs.Direction].GetTotalValue() != 1 {
- t.Errorf("Calling ApierV1.GetBalance expected: 1, received: %f", reply)
+ t.Errorf("Calling ApierV1.GetUserBalance expected: 1, received: %f", reply)
}
}
diff --git a/console/debit_balance.go b/console/debit_balance.go
new file mode 100644
index 000000000..210ad61fd
--- /dev/null
+++ b/console/debit_balance.go
@@ -0,0 +1,97 @@
+/*
+Rating system designed to be used in VoIP Carriers World
+Copyright (C) 2013 ITsysCOM
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+ "time"
+)
+
+func init() {
+ commands["debit_balance"] = &CmdDebitBalance{}
+}
+
+// Commander implementation
+type CmdDebitBalance struct {
+ rpcMethod string
+ rpcParams *engine.CallDescriptor
+ rpcResult engine.CallCost
+}
+
+// name should be exec's name
+func (self *CmdDebitBalance) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] debit_balance ")
+}
+
+// set param defaults
+func (self *CmdDebitBalance) defaults() error {
+ self.rpcMethod = "Responder.Debit"
+ self.rpcParams = &engine.CallDescriptor{Direction: "*out"}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdDebitBalance) FromArgs(args []string) error {
+ if len(args) != 8 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ var tStart time.Time
+ var err error
+ if args[6] == "*now" {
+ tStart = time.Now()
+ } else {
+ tStart, err = utils.ParseDate(args[6])
+ if err != nil {
+ fmt.Println("\n*start_time* should have one of the formats:")
+ fmt.Println("\ttime.RFC3339\teg:2013-08-07T17:30:00Z in UTC")
+ fmt.Println("\tunix time\teg: 1383823746")
+ fmt.Println("\t*now\t\tmetafunction transformed into localtime at query time")
+ fmt.Println("\t+dur\t\tduration to be added to localtime (valid suffixes: ns, us/µs, ms, s, m, h)\n")
+ return fmt.Errorf(self.Usage(""))
+ }
+ }
+ callDur, err := utils.ParseDurationWithSecs(args[7])
+ if err != nil {
+ fmt.Println("\n\tExample durations: 60s for 60 seconds, 25m for 25minutes, 1m25s for one minute and 25 seconds\n")
+ }
+ self.rpcParams.TOR = args[2]
+ self.rpcParams.Tenant = args[3]
+ self.rpcParams.Subject = args[4]
+ self.rpcParams.Destination = args[5]
+ self.rpcParams.TimeStart = tStart
+ self.rpcParams.CallDuration = callDur
+ self.rpcParams.TimeEnd = tStart.Add(callDur)
+ return nil
+}
+
+func (self *CmdDebitBalance) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdDebitBalance) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdDebitBalance) RpcResult() interface{} {
+ return &self.rpcResult
+}