renamed balance_add to balance_set

now it accepts negative values
This commit is contained in:
Radu Ioan Fericean
2014-06-04 18:43:29 +03:00
parent b56356486f
commit 3d99f917f5
3 changed files with 20 additions and 8 deletions

View File

@@ -113,9 +113,12 @@ func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
if attr.Direction == "" {
attr.Direction = engine.OUTBOUND
}
aType := engine.TOPUP
aType := engine.DEBIT
// reverse the sign as it is a debit
attr.Value = -attr.Value
if attr.Overwrite {
aType = engine.TOPUP_RESET
aType = engine.DEBIT_RESET
}
at.SetActions(engine.Actions{
&engine.Action{

View File

@@ -25,7 +25,7 @@ import (
func init() {
c := &CmdAddBalance{
name: "balance_add",
name: "balance_set",
rpcMethod: "ApierV1.AddBalance",
}
commands[c.Name()] = c
@@ -50,7 +50,7 @@ func (self *CmdAddBalance) RpcMethod() string {
func (self *CmdAddBalance) RpcParams() interface{} {
if self.rpcParams == nil {
self.rpcParams = &apier.AttrAddBalance{BalanceType: engine.CREDIT}
self.rpcParams = &apier.AttrAddBalance{BalanceType: engine.CREDIT, Overwrite: false}
}
return self.rpcParams
}

View File

@@ -55,6 +55,7 @@ const (
RESET_ACCOUNT = "*reset_account"
TOPUP_RESET = "*topup_reset"
TOPUP = "*topup"
DEBIT_RESET = "*debit_reset"
DEBIT = "*debit"
RESET_COUNTER = "*reset_counter"
RESET_COUNTERS = "*reset_counters"
@@ -88,6 +89,8 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
return topupResetAction, true
case TOPUP:
return topupAction, true
case DEBIT_RESET:
return debitResetAction, true
case DEBIT:
return debitAction, true
case RESET_COUNTER:
@@ -149,14 +152,20 @@ func topupResetAction(ub *Account, a *Action) (err error) {
}
ub.BalanceMap[a.BalanceType+a.Direction] = BalanceChain{}
genericMakeNegative(a)
genericDebit(ub, a)
return
return genericDebit(ub, a)
}
func topupAction(ub *Account, a *Action) (err error) {
genericMakeNegative(a)
genericDebit(ub, a)
return
return genericDebit(ub, a)
}
func debitResetAction(ub *Account, a *Action) (err error) {
if ub.BalanceMap == nil { // Init the map since otherwise will get error if nil
ub.BalanceMap = make(map[string]BalanceChain, 0)
}
ub.BalanceMap[a.BalanceType+a.Direction] = BalanceChain{}
return genericDebit(ub, a)
}
func debitAction(ub *Account, a *Action) (err error) {