mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
AccountS - V1AccountProfileForEvent and V1DebitUsage implementation
This commit is contained in:
@@ -164,6 +164,20 @@ func (aS *AccountS) accountProcessEvent(acnt *utils.AccountProfile,
|
||||
return
|
||||
}
|
||||
|
||||
// V1AccountProfileForEvent returns the matching AccountProfile for Event
|
||||
func (aS *AccountS) V1AccountProfileForEvent(args *utils.ArgsAccountForEvent, ap *utils.AccountProfile) (err error) {
|
||||
var acnt *utils.AccountProfile
|
||||
if acnt, err = aS.matchingAccountForEvent(args.CGREvent.Tenant,
|
||||
args.CGREvent, args.AccountIDs); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
*ap = *acnt // Make sure we clone in RPC
|
||||
return
|
||||
}
|
||||
|
||||
// V1MaxUsage returns the maximum usage for the event, based on matching Account
|
||||
func (aS *AccountS) V1MaxUsage(args *utils.ArgsAccountForEvent, ec *utils.EventCharges) (err error) {
|
||||
var acnt *utils.AccountProfile
|
||||
@@ -183,3 +197,27 @@ func (aS *AccountS) V1MaxUsage(args *utils.ArgsAccountForEvent, ec *utils.EventC
|
||||
*ec = *procEC
|
||||
return
|
||||
}
|
||||
|
||||
// V1DebitUsage performs debit for the provided event
|
||||
func (aS *AccountS) V1DebitUsage(args *utils.ArgsAccountForEvent, ec *utils.EventCharges) (err error) {
|
||||
var acnt *utils.AccountProfile
|
||||
if acnt, err = aS.matchingAccountForEvent(args.CGREvent.Tenant,
|
||||
args.CGREvent, args.AccountIDs); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var procEC *utils.EventCharges
|
||||
if procEC, err = aS.accountProcessEvent(acnt, args.CGREvent); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = aS.dm.SetAccountProfile(acnt, false); err != nil {
|
||||
return // no need of revert since we did not save
|
||||
}
|
||||
|
||||
*ec = *procEC
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user