diff --git a/apier/v1/accountprofiles.go b/apier/v1/accountprofiles.go index f202195ed..23638772f 100644 --- a/apier/v1/accountprofiles.go +++ b/apier/v1/accountprofiles.go @@ -164,7 +164,7 @@ func (aSv1 *AccountSv1) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent return aSv1.aS.V1AccountProfilesForEvent(args, aps) } -// MaxUsage returns the maximum usage for the event, based on matching Account +// MaxAbstracts returns the maximum abstracts for the event, based on matching Account func (aSv1 *AccountSv1) MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) { return aSv1.aS.V1MaxAbstracts(args, eEc) @@ -176,6 +176,18 @@ func (aSv1 *AccountSv1) DebitAbstracts(args *utils.ArgsAccountsForEvent, return aSv1.aS.V1DebitAbstracts(args, eEc) } +// MaxConcretes returns the maximum concretes for the event, based on the matching Account +func (aSv1 *AccountSv1) MaxConcretes(args *utils.ArgsAccountsForEvent, + eEc *utils.ExtEventCharges) (err error) { + return aSv1.aS.V1MaxConcretes(args, eEc) +} + +// DebitConcretes performs debit of concrete units for the provided event +func (aSv1 *AccountSv1) DebitConcretes(args *utils.ArgsAccountsForEvent, + eEc *utils.ExtEventCharges) (err error) { + return aSv1.aS.V1DebitConcretes(args, eEc) +} + // ActionSetBalance performs a set balance action func (aSv1 *AccountSv1) ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error) { diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index 769eb0807..5b3903d61 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -292,5 +292,7 @@ type AccountSv1Interface interface { MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error) + MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) + DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) ActionRemoveBalance(args *utils.ArgsActRemoveBalances, eEc *string) (err error) } diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 668a1c447..c2bea902a 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -1390,6 +1390,14 @@ func (dR *DispatcherAccountSv1) DebitAbstracts(args *utils.ArgsAccountsForEvent, return dR.dR.DebitAbstracts(args, eEc) } +func (dR *DispatcherAccountSv1) MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error { + return dR.dR.MaxConcretes(args, eEc) +} + +func (dR *DispatcherAccountSv1) DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error { + return dR.dR.DebitConcretes(args, eEc) +} + func (dR *DispatcherAccountSv1) ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error) { return dR.dR.AccountSv1ActionSetBalance(args, eEc) } diff --git a/apier/v1/tpdispatchers_it_test.go b/apier/v1/tpdispatchers_it_test.go index 7ce9d85fd..bdf6a8272 100644 --- a/apier/v1/tpdispatchers_it_test.go +++ b/apier/v1/tpdispatchers_it_test.go @@ -46,7 +46,7 @@ var sTestsTPDispatchers = []func(t *testing.T){ testTPDispatcherResetStorDb, testTPDispatcherStartEngine, testTPDispatcherRpcConn, - ttestTPDispatcherGetTPDispatcherBeforeSet, + testTPDispatcherGetTPDispatcherBeforeSet, testTPDispatcherSetTPDispatcher, testTPDispatcherGetTPDispatcherAfterSet, testTPDispatcherGetTPDispatcherIds, @@ -110,7 +110,7 @@ func testTPDispatcherRpcConn(t *testing.T) { } } -func ttestTPDispatcherGetTPDispatcherBeforeSet(t *testing.T) { +func testTPDispatcherGetTPDispatcherBeforeSet(t *testing.T) { var reply *utils.TPDispatcherProfile if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, @@ -190,7 +190,7 @@ func testTPDispatcherGetTPDispatcherAfterUpdate(t *testing.T) { &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDispatcher, reply) && !reflect.DeepEqual(revHosts, reply) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpDispatcher), utils.ToJSON(reply)) + t.Errorf("Expecting : %+v \n and %+v\n, received: %+v", utils.ToJSON(tpDispatcher), utils.ToJSON(revHosts), utils.ToJSON(reply)) } } diff --git a/dispatchers/accounts.go b/dispatchers/accounts.go index 92fcfd79c..0a576642c 100644 --- a/dispatchers/accounts.go +++ b/dispatchers/accounts.go @@ -80,6 +80,34 @@ func (dS *DispatcherService) DebitAbstracts(args *utils.ArgsAccountsForEvent, re return dS.Dispatch(args.CGREvent, utils.MetaAccounts, utils.AccountSv1DebitAbstracts, args, reply) } +func (dS *DispatcherService) MaxConcretes(args *utils.ArgsAccountsForEvent, reply *utils.ExtEventCharges) (err error) { + tnt := dS.cfg.GeneralCfg().DefaultTenant + if args.CGREvent != nil && args.CGREvent.Tenant != utils.EmptyString { + tnt = args.CGREvent.Tenant + } + if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { + if err = dS.authorize(utils.AccountSv1MaxConcretes, tnt, + utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil { + return + } + } + return dS.Dispatch(args.CGREvent, utils.MetaAccounts, utils.AccountSv1MaxConcretes, args, reply) +} + +func (dS *DispatcherService) DebitConcretes(args *utils.ArgsAccountsForEvent, reply *utils.ExtEventCharges) (err error) { + tnt := dS.cfg.GeneralCfg().DefaultTenant + if args.CGREvent != nil && args.CGREvent.Tenant != utils.EmptyString { + tnt = args.CGREvent.Tenant + } + if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { + if err = dS.authorize(utils.AccountSv1DebitConcretes, tnt, + utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil { + return + } + } + return dS.Dispatch(args.CGREvent, utils.MetaAccounts, utils.AccountSv1DebitConcretes, args, reply) +} + func (dS *DispatcherService) AccountSv1ActionSetBalance(args *utils.ArgsActSetBalance, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { diff --git a/utils/consts.go b/utils/consts.go index 3b36dee3e..df4473736 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -1582,6 +1582,8 @@ const ( AccountSv1AccountProfilesForEvent = "AccountSv1.AccountProfilesForEvent" AccountSv1MaxAbstracts = "AccountSv1.MaxAbstracts" AccountSv1DebitAbstracts = "AccountSv1.DebitAbstracts" + AccountSv1MaxConcretes = "AccountSv1.MaxConcretes" + AccountSv1DebitConcretes = "AccountSv1.DebitConcretes" AccountSv1ActionSetBalance = "AccountSv1.ActionSetBalance" AccountSv1ActionRemoveBalance = "AccountSv1.ActionRemoveBalance" )