Deduct from multiple balances at once

230 views
Skip to first unread message

paulg...@gmail.com

unread,
Jun 24, 2021, 6:57:21 AM6/24/21
to CGRateS
Hi there

Apologies if this is a basic question.

I have my test setup fully working and am successfully charging prepaid accounts between Kamailio and CGRates.

My question is if I want to deduct from multiple control balances in realtime how do I achieve this?

I believe its using Derived Charging but I cant seem to see an example for what I am trying to do.

My use case is I would like to have all prepaid charging but as a wholesale provider I would like to parallel debit from
- reseller balances
- the reseller's reseller balances
- ultimate end customer balances

I imagine I have to have some kind of shared balance structure to achieve the control and if any one of the balances expires the call is disconnected.

Any guidance would be appreciated 

regards
Paul

paulg...@gmail.com

unread,
Jun 24, 2021, 7:11:10 AM6/24/21
to CGRateS
I could manage without the recursive  reseller's reseller balance scenario if that made things too messy

paulg...@gmail.com

unread,
Jun 26, 2021, 7:48:37 AM6/26/21
to CGRateS

I presume below will work as an alternative to derived charging but will try out

  • Tiered accounts/balances with each level in a separate tenant
  • Authorise the session with CGR_AUTH_REQUEST via the registered user returning the reseller parent account identifier via AttributeS
  • Authorise each parent reseller found in a loop to the respective account/balance until no more parent identifiers found
  • If one fails then call not authorised.
  • Do a loop of CGR_CALL_START for each authorised session with the last one restarting the Kamailio transaction
  • This should have parallel debits for the call for each cgrates session/account/bundle at each level 
  • Similarly at CGR_CALL_END, loop through and close each cgrates session and cut a CDR for each level/tenant
This on the right track?

paulg...@gmail.com

unread,
Jun 28, 2021, 3:59:11 AM6/28/21
to CGRateS
For others who may be looking for something similar, this works

  • End user session auth returns reseller tenant and account via AttributeS
  • Store values for end user session auth and perform reseller account auth
  • Store values for reseller account session auth
  • If one fails then call is denied
  • On Call start send two CGR_CALL_START for each account with same Kamailio transaction ID but with different Origin IDs (store these also)
  • Balances will debit in parallel
  • On Call end send two CGR_CALL_END for each account to cut CDRs

Andrei-Sebastian Andronache

unread,
Jun 29, 2021, 8:31:27 AM6/29/21
to CGRateS
Hi Paul,

For your case we recommend you use multiple charging profiles.
Here is an example of something similar:
Attributes.csv:
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates,Attribute1,*chargers,,,,*req.RequestType,*constant,*prepaid,false,2
cgrates,Attribute1,,,,,*req.Account,*constant,1001,,

Chargers.csv:
#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight
cgrates,Charger1,,,*default,*none,0
cgrates,Charger2,,,prepaidChrg,Attribute1,0

You don't need double events, only one (with direction inbound ).

Thanks,
Andrei

Paul Walsh

unread,
Jun 29, 2021, 8:46:16 AM6/29/21
to cgr...@googlegroups.com
Thanks Andrei
> --
> You received this message because you are subscribed to the Google Groups "CGRateS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/12350527-2131-4a85-b80f-d205dd4c961bn%40googlegroups.com.

Paul Walsh

unread,
Jun 29, 2021, 9:59:33 AM6/29/21
to cgr...@googlegroups.com
Hi Andrei

I presume if I want to charge on different tenants then I do need
multiple events?

On Tue, Jun 29, 2021 at 1:31 PM Andrei-Sebastian Andronache
<andrei.a...@itsyscom.com> wrote:
>

Andrei-Sebastian Andronache

unread,
Jun 30, 2021, 7:28:39 AM6/30/21
to CGRateS
Hi Paul,

You can change the tenant using attributes.
Here is an example of one that will change the tenant:
Attributes.csv:
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR1,*any,,,,*tenant,*constant,ChangedTenant,,

Or you can do an inline filter(https://cgrates.readthedocs.io/en/latest/attributes.html):
*constant:*tenant:ChangedTenant

Thanks,
Andrei

Paul Walsh

unread,
Jun 30, 2021, 7:49:01 AM6/30/21
to cgr...@googlegroups.com
That’s perfect thank you


paulg...@gmail.com

unread,
Jul 3, 2021, 6:24:29 PM7/3/21
to CGRateS
Trying to implement the above derived rating example with dual prepaid debiting but struggling

Two Chargers are both setup and both are triggered.
The first charger does the Retail charging based in the end user account and tenant
The second charger substitutes the account and tenant for the reseller charger account and tenant via Attributes. The end user session sets these reseller values and then the wholesale charger attributesID swaps the values.
The initial response looks good as per below ngrep of the Sessions to Rals.

The retail charger then does GetMaxSessionTime and this comes back OK

When the wholesale charger attempts to do GetMaxSessionTime the tenant has reverted to the retail tenant even though the account has been substituted and I get ACCOUNT_NOT_FOUND (as its on the other tenant). I thought the principle of the Attribute substitution in Chargers was that it was maintained for the forked charging session. I have tried many combinations of substitution using *tenant, *req.Tenant and both but its the same result. 

Any ideas?

interface: any
filter: ( port 32051 ) and (ip || ip6)
#
  {"method":"AttributeSv1.ProcessEvent","params":[{"AttributeIDs":null,"Context":"*sessions","ProcessRuns":null,"Tenant":"reta.tn","ID":"23948b8","Time":"2021-07-03T23:03:00+01:00","Event":{"Account":"3532268
  03023","Destination":"35322392293","EvapiConnID":0,"OriginHost":"10.131.91.10:8448","SetupTime":"1625349780","Source":"KamailioAgent","Tenant":"reta.tn"}}],"id":166}.                                        
#
  {"id":166,"result":{"MatchedProfiles":["AT_SS_353226803023"],"AlteredFields":["*req.Password","*req.RequestType","*req.ResellerAccount","*req.ResellerTenant","*req.Country"],"CGREvent":{"Tenant":"reta.tn","
  ID":"23948b8","Time":"2021-07-03T23:03:00+01:00","Event":{"Account":"353226803023","Country":"IE","Destination":"35322392293","EvapiConnID":0,"OriginHost":"10.131.91.10:8448","Password":"blahblahb","Request
  Type":"*prepaid","ResellerAccount":"88100001","ResellerTenant":"wholes.ten","SetupTime":"1625349780","Source":"KamailioAgent","Tenant":"reta.tn"}}},"error":null}.                                            
##
  {"method":"ChargerSv1.ProcessEvent","params":[{"Tenant":"reta.tn","ID":"ba39304","Time":null,"Event":{"Account":"353226803023","CGRID":"6d41ec4f886f3cfab28cf043cfacb3e540e36ba1","Country":"IE","Destination"
  :"35322392293","EvapiConnID":0,"OriginHost":"10.131.91.10:8448","Password":"blahblahb","RequestType":"*prepaid","ResellerAccount":"88100001","ResellerTenant":"wholes.ten","SetupTime":"1625349780","Source":"
  KamailioAgent","Tenant":"reta.tn","Usage":43200000000000}}],"id":167}.                                                                                                                                        
#
  {"id":167,"result":[{"ChargerSProfile":"CG_RETAIL","AttributeSProfiles":["AT_CG_RETAIL"],"AlteredFields":["*req.RunID","*req.Subject"],"CGREvent":{"Tenant":"reta.tn","ID":"ba39304","Time":null,"Event":{"Acc
  ount":"353226803023","CGRID":"6d41ec4f886f3cfab28cf043cfacb3e540e36ba1","Country":"IE","Destination":"35322392293","EvapiConnID":0,"OriginHost":"10.131.91.10:8448","Password":"blahblahb","RequestType":"*pre
  paid","ResellerAccount":"88100001","ResellerTenant":"wholes.ten","RunID":"Retail","SetupTime":"1625349780","Source":"KamailioAgent","Subject":"Retail","Tenant":"reta.tn","Usage":43200000000000}}},{"ChargerS
  Profile":"CG_WHOLESALE","AttributeSProfiles":["AT_CG_WHOLESALE"],"AlteredFields":["*req.RunID","*req.Account","*req.OriginalAccount","*req.OriginalTenant","*req.Subject","*req.Tenant","*tenant","*req.Reques
  tType"],"CGREvent":{"Tenant":"wholes.ten","ID":"ba39304","Time":null,"Event":{"Account":"88100001","CGRID":"6d41ec4f886f3cfab28cf043cfacb3e540e36ba1","Country":"IE","Destination":"35322392293","EvapiConnID"
  :0,"OriginHost":"10.131.91.10:8448","OriginalAccount":"353226803023","OriginalTenant":"reta.tn","Password":"blahblahb","RequestType":"*prepaid","ResellerAccount":"88100001","ResellerTenant":"wholes.ten","Ru
  nID":"Wholesale","SetupTime":"1625349780","Source":"KamailioAgent","Subject":"Wholesale","Tenant":"wholes.ten","Usage":43200000000000}}}],"error":null}.                                                      
#
  {"method":"Responder.GetMaxSessionTime","params":[{"Category":"call","Tenant":"reta.tn","Subject":"Retail","Account":"353226803023","Destination":"35322392293","TimeStart":"2021-07-03T23:03:00+01:00","TimeE
  nd":"2021-07-04T11:03:00+01:00","LoopIndex":0,"DurationIndex":0,"FallbackSubject":"","RatingInfos":null,"Increments":null,"ToR":"","ExtraFields":{"Country":"IE","EvapiConnID":"0","Password":"blahblahb","Res
  ellerAccount":"88100001","ResellerTenant":"wholes.ten"},"MaxRate":0,"MaxRateUnit":0,"MaxCostSoFar":0,"CgrID":"6d41ec4f886f3cfab28cf043cfacb3e540e36ba1","RunID":"Retail","ForceDuration":false,"PerformRoundin
  g":false,"DryRun":false,"DenyNegativeAccount":false}],"id":168}.                                                                                                                                              
##
  {"id":168,"result":117000000000,"error":null}.                                                                                                                                                                
#
  {"method":"Responder.GetMaxSessionTime","params":[{"Category":"call","Tenant":"reta.tn","Subject":"Wholesale","Account":"88100001","Destination":"35322392293","TimeStart":"2021-07-03T23:03:00+01:00","TimeEn
  d":"2021-07-04T11:03:00+01:00","LoopIndex":0,"DurationIndex":0,"FallbackSubject":"","RatingInfos":null,"Increments":null,"ToR":"","ExtraFields":{"Country":"IE","EvapiConnID":"0","OriginalAccount":"353226803
  023","OriginalTenant":"reta.tn","Password":"blahblahb","ResellerAccount":"88100001","ResellerTenant":"wholes.ten"},"MaxRate":0,"MaxRateUnit":0,"MaxCostSoFar":0,"CgrID":"6d41ec4f886f3cfab28cf043cfacb3e540e36
  ba1","RunID":"Wholesale","ForceDuration":false,"PerformRounding":false,"DryRun":false,"DenyNegativeAccount":false}],"id":169}.                                                                                
##
  {"id":169,"result":null,"error":"ACCOUNT_NOT_FOUND"}.                                                                                                                                                         
#exit
12 received, 8 matched  

Andrei-Sebastian Andronache

unread,
Jul 5, 2021, 3:46:29 AM7/5/21
to CGRateS
Hi Paul,

From what we can see in the ngrep, the tenant in the event that was sent to chargers was changed, but the tenant of the SRun(the session that we have) didn't change.
Please open an issue regarding this, so that we can try our best to help you.

Thanks,
Andrei

Paul Walsh

unread,
Jul 5, 2021, 3:57:07 AM7/5/21
to cgr...@googlegroups.com
Thanks Andrei will raise an issue later today

On Mon, Jul 5, 2021 at 8:46 AM Andrei-Sebastian Andronache
> You received this message because you are subscribed to a topic in the Google Groups "CGRateS" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/cgrates/hH41EQI1Ams/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to cgrates+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/57829b63-e067-4cd4-aa35-8d040604bda6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages