mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding account info in responder.RefundIncrements, update accountSummary after refund
This commit is contained in:
@@ -899,7 +899,8 @@ func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
|
||||
}
|
||||
|
||||
// refundIncrements has no locks
|
||||
func (cd *CallDescriptor) refundIncrements() (err error) {
|
||||
// returns the updated account referenced by the CallDescriptor
|
||||
func (cd *CallDescriptor) refundIncrements() (acnt *Account, err error) {
|
||||
accountsCache := make(map[string]*Account)
|
||||
for _, increment := range cd.Increments {
|
||||
account, found := accountsCache[increment.BalanceInfo.AccountID]
|
||||
@@ -935,11 +936,12 @@ func (cd *CallDescriptor) refundIncrements() (err error) {
|
||||
account.countUnits(-increment.Cost, utils.MONETARY, cc, balance)
|
||||
}
|
||||
}
|
||||
acnt = accountsCache[utils.ConcatenatedKey(cd.Tenant, cd.Account)]
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (cd *CallDescriptor) RefundIncrements() (err error) {
|
||||
func (cd *CallDescriptor) RefundIncrements() (acnt *Account, err error) {
|
||||
// get account list for locking
|
||||
// all must be locked in order to use cache
|
||||
cd.Increments.Decompress()
|
||||
@@ -953,7 +955,7 @@ func (cd *CallDescriptor) RefundIncrements() (err error) {
|
||||
}
|
||||
}
|
||||
_, err = guardian.Guardian.Guard(func() (iface interface{}, err error) {
|
||||
err = cd.refundIncrements()
|
||||
acnt, err = cd.refundIncrements()
|
||||
return
|
||||
}, 0, accMap.Slice()...)
|
||||
return
|
||||
|
||||
@@ -197,11 +197,11 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err error) {
|
||||
func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *Account) (err error) {
|
||||
cacheKey := utils.REFUND_INCR_CACHE_PREFIX + arg.CgrID + arg.RunID
|
||||
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
|
||||
if item.Value != nil {
|
||||
*reply = *(item.Value.(*float64))
|
||||
*reply = *(item.Value.(*Account))
|
||||
}
|
||||
return item.Err
|
||||
}
|
||||
@@ -229,9 +229,20 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
|
||||
return err
|
||||
}
|
||||
if !rs.usageAllowed(arg.TOR, arg.GetDuration()) {
|
||||
return utils.ErrMaxUsageExceeded
|
||||
err = utils.ErrMaxUsageExceeded
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Err: err,
|
||||
})
|
||||
return
|
||||
}
|
||||
if acnt, err := arg.RefundIncrements(); err != nil {
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Err: err,
|
||||
})
|
||||
return err
|
||||
} else if acnt != nil {
|
||||
*reply = *acnt
|
||||
}
|
||||
err = arg.RefundIncrements()
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Value: reply,
|
||||
Err: err,
|
||||
|
||||
@@ -230,8 +230,12 @@ func (self *SMGSession) refund(usage time.Duration) (err error) {
|
||||
TOR: self.CD.TOR,
|
||||
Increments: incrmts,
|
||||
}
|
||||
var reply float64
|
||||
return self.rals.Call("Responder.RefundIncrements", cd, &reply)
|
||||
var acnt engine.Account
|
||||
err = self.rals.Call("Responder.RefundIncrements", cd, &acnt)
|
||||
if acnt.ID != "" { // Account info updated, update also cached AccountSummary
|
||||
self.EventCost.AccountSummary = acnt.AsAccountSummary()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// storeSMCost will send the SMCost to CDRs for storing
|
||||
@@ -251,8 +255,9 @@ func (self *SMGSession) storeSMCost() error {
|
||||
CostDetails: self.EventCost,
|
||||
}
|
||||
var reply string
|
||||
if err := self.cdrsrv.Call("CdrsV2.StoreSMCost", engine.ArgsV2CDRSStoreSMCost{Cost: smCost,
|
||||
CheckDuplicate: true}, &reply); err != nil {
|
||||
if err := self.cdrsrv.Call("CdrsV2.StoreSMCost",
|
||||
engine.ArgsV2CDRSStoreSMCost{Cost: smCost,
|
||||
CheckDuplicate: true}, &reply); err != nil {
|
||||
if err == utils.ErrExists {
|
||||
self.refund(self.CD.GetDuration()) // Refund entire duration
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user