Double charge for *sms and *monetary balance

182 views
Skip to first unread message

Marcin Kowalczyk

unread,
Apr 16, 2022, 7:45:01 AM4/16/22
to CGRateS
Hi,

 I'm expiriencing very strange behaviour of cgrates. User has multiple balances ToR=*sms some of them are bonded towards Subject&category -


{"method":"ApierV1.SetBalance","params":[{"Tenant":"cgrates.org","Account":"kowalBulk","BalanceType":"*sms","BalanceId":"bulk:169e1864-fe5a-4b62-9577-68cd43d519ae","Categories":"bulk-sms-out","Weight":1650113360,"Value":1,"Cdrlog":true,"Overwrite":true,"DestinationIds":"","ExpiryTime":"1657884360048","RatingSubject":"169e1864-fe5a-4b62-9577-68cd43d519ae"}]}
##
T 127.0.0.1:60556 -> 127.0.0.1:2012 [AP] #248
{"method":"CDRsV1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"4bd9299","Time":null,"Event":{"Account":"kowalBulk","AnswerTime":"2022-04-16T11:26:00.17434258Z","CGRID":"c3f8c03d27bf4606e36573c9437710c98359877c","Category":"","Cost":1,"CostSource":"","Destination":"","ExtraInfo":"","OrderID":0,"OriginHost":"127.0.0.1","OriginID":"bc45019e-19fe-4f67-b9ad-4aaa139d1160","Partial":false,"PreRated":true,"RequestType":"*none","RunID":"*set_balance","SetupTime":"2022-04-16T11:26:00.174341237Z","Source":"*cdrlog","Subject":"kowalBulk","Tenant":"cgrates.org","ToR":"*sms","Usage":1},"AttributeS":null,"RALs":null,"ChargerS":null,"Store":null,"Export":null,"ThresholdS":null,"StatS":null}],"id":9}

#
T 127.0.0.1:2012 -> 127.0.0.1:60556 [AP] #249
{"id":9,"result":"OK","error":null}

##
T 127.0.0.1:60546 -> 127.0.0.1:2012 [AP] #251
{"method":"ChargerSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"4bd9299","Time":null,"Event":{"Account":"kowalBulk","AnswerTime":"2022-04-16T11:26:00.17434258Z","CGRID":"c3f8c03d27bf4606e36573c9437710c98359877c","Category":"","Cost":1,"CostSource":"","Destination":"","ExtraInfo":"","OrderID":0,"OriginHost":"127.0.0.1","OriginID":"bc45019e-19fe-4f67-b9ad-4aaa139d1160","Partial":false,"PreRated":true,"RequestType":"*none","RunID":"*set_balance","SetupTime":"2022-04-16T11:26:00.174341237Z","Source":"*cdrlog","Subject":"kowalBulk","Tenant":"cgrates.org","ToR":"*sms","Usage":1}}],"id":36}

#
T 127.0.0.1:2012 -> 127.0.0.1:60546 [AP] #252
{"id":36,"result":[{"ChargerSProfile":"CustomerCharges","AttributeSProfiles":null,"AlteredFields":null,"CGREvent":{"Tenant":"cgrates.org","ID":"4bd9299","Time":null,"Event":{"Account":"kowalBulk","AnswerTime":"2022-04-16T11:26:00.17434258Z","CGRID":"c3f8c03d27bf4606e36573c9437710c98359877c","Category":"","Cost":1,"CostSource":"","Destination":"","ExtraInfo":"","OrderID":0,"OriginHost":"127.0.0.1","OriginID":"bc45019e-19fe-4f67-b9ad-4aaa139d1160","Partial":false,"PreRated":true,"RequestType":"*none","RunID":"CustomerCharges","SetupTime":"2022-04-16T11:26:00.174341237Z","Source":"*cdrlog","Subject":"kowalBulk","Tenant":"cgrates.org","ToR":"*sms","Usage":1}}}],"error":null}



Next when doing ExternalCDR like below

#########
T 172.16.2.44:24948 -> 172.31.23.248:2080 [AP] #353
POST /jsonrpc HTTP/1.1.
accept: application/json.
user-agent: Needle/1.6.0 (Node.js v12.22.11; linux x64).
content-length: 720.
content-type: application/json; charset=utf-8.
host: 172.31.23.248:2080.
Connection: close.
.
{"method":"CDRsV2.ProcessExternalCDR","params":[{"OriginID":"5448843b-b872-4fb5-8827-81838f1920b5","ToR":"*sms","RequestType":"*pseudoprepaid","SetupTime":"1650108372702","AnswerTime":"1650108373262","Tenant":"cgrates.org","Account":"kowalBulk","Subject":"169e1864-fe5a-4b62-9577-68cd43d519ae","Destination":"48100000","Usage":"1","Category":"bulk-sms-out","ExtraFields":{"carrier":"MOCK","smsParams.characterCount":"10","smsParams.replaceDiacritics":"true","smsParams.isUnicode":"false","messageUUID":"011fc7a9-d7a4-42d9-ac19-5401cc636f02","env":"test","destinationId":"48_MOBILE","sourceNumber":"48100000"},"OriginHost":"7143eeec-946f-5c18-b4f6-b4383d9a657e_1","Source":"twoway-communications-test-MessageOut"}]}
##
T 127.0.0.1:60546 -> 127.0.0.1:2012 [AP] #355
{"method":"ChargerSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"295f883","Time":null,"Event":{"Account":"kowalBulk","AnswerTime":"2022-04-16T11:26:13.262Z","CGRID":"ac82c69fabbb5a022f6ab84f631284e376634eb6","Category":"bulk-sms-out","Cost":-1,"CostSource":"","Destination":"48100000","ExtraInfo":"","OrderID":0,"OriginHost":"7143eeec-946f-5c18-b4f6-b4383d9a657e_1","OriginID":"5448843b-b872-4fb5-8827-81838f1920b5","Partial":false,"PreRated":false,"RequestType":"*pseudoprepaid","RunID":"*raw","SetupTime":"2022-04-16T11:26:12.702Z","Source":"twoway-communications-test-MessageOut","Subject":"169e1864-fe5a-4b62-9577-68cd43d519ae","Tenant":"cgrates.org","ToR":"*sms","Usage":1,"carrier":"MOCK","destinationId":"48_MOBILE","env":"test","messageUUID":"011fc7a9-d7a4-42d9-ac19-5401cc636f02","smsParams.characterCount":"10","smsParams.isUnicode":"false","smsParams.replaceDiacritics":"true","sourceNumber":"48100000"}}],"id":39}

#
T 172.31.23.248:2080 -> 172.16.2.44:24948 [AP] #356
HTTP/1.1 200 OK.
Content-Type: application/json.
Date: Sat, 16 Apr 2022 11:26:13 GMT.
Content-Length: 39.
Connection: close.
.
{"id":null,"result":"OK","error":null}

#####
T 127.0.0.1:2012 -> 127.0.0.1:60546 [AP] #361
{"id":39,"result":[{"ChargerSProfile":"CustomerCharges","AttributeSProfiles":null,"AlteredFields":null,"CGREvent":{"Tenant":"cgrates.org","ID":"295f883","Time":null,"Event":{"Account":"kowalBulk","AnswerTime":"2022-04-16T11:26:13.262Z","CGRID":"ac82c69fabbb5a022f6ab84f631284e376634eb6","Category":"bulk-sms-out","Cost":-1,"CostSource":"","Destination":"48100000","ExtraInfo":"","OrderID":0,"OriginHost":"7143eeec-946f-5c18-b4f6-b4383d9a657e_1","OriginID":"5448843b-b872-4fb5-8827-81838f1920b5","Partial":false,"PreRated":false,"RequestType":"*pseudoprepaid","RunID":"CustomerCharges","SetupTime":"2022-04-16T11:26:12.702Z","Source":"twoway-communications-test-MessageOut","Subject":"169e1864-fe5a-4b62-9577-68cd43d519ae","Tenant":"cgrates.org","ToR":"*sms","Usage":1,"carrier":"MOCK","destinationId":"48_MOBILE","env":"test","messageUUID":"011fc7a9-d7a4-42d9-ac19-5401cc636f02","smsParams.characterCount":"10","smsParams.isUnicode":"false","smsParams.replaceDiacritics":"true","sourceNumber":"48100000"}}}],"error":null}

##
T 127.0.0.1:60548 -> 127.0.0.1:2012 [AP] #363
{"method":"Responder.Debit","params":[{"Category":"bulk-sms-out","Tenant":"cgrates.org","Subject":"169e1864-fe5a-4b62-9577-68cd43d519ae","Account":"kowalBulk","Destination":"48100000","TimeStart":"2022-04-16T11:26:13.262Z","TimeEnd":"2022-04-16T11:26:13.262000001Z","LoopIndex":0,"DurationIndex":1,"FallbackSubject":"","RatingInfos":null,"Increments":null,"TOR":"*sms","ExtraFields":null,"MaxRate":0,"MaxRateUnit":0,"MaxCostSoFar":0,"CgrID":"","RunID":"","ForceDuration":false,"PerformRounding":true,"DryRun":false,"DenyNegativeAccount":false}],"id":27}

#
T 127.0.0.1:2012 -> 127.0.0.1:60548 [AP] #364
{"id":27,"result":{"Category":"bulk-sms-out","Tenant":"cgrates.org","Subject":"169e1864-fe5a-4b62-9577-68cd43d519ae","Account":"kowalBulk","Destination":"48100000","TOR":"*sms","Cost":0.05,"Timespans":[{"TimeStart":"2022-04-16T11:26:13.262Z","TimeEnd":"2022-04-16T11:26:13.262000001Z","Cost":0.05,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"RoundingMethod":"*up","RoundingDecimals":2,"MaxCost":0,"MaxCostStrategy":"","Rates":[{"GroupIntervalStart":0,"Value":0.05,"RateIncrement":1,"RateUnit":1}]},"Weight":10},"DurationIndex":1,"Increments":[{"Duration":1,"Cost":0.05,"BalanceInfo":{"Unit":{"UUID":"3b552ad7-38dd-41c0-a664-bd7c4adb159d","ID":"bulk:169e1864-fe5a-4b62-9577-68cd43d519ae","Value":0,"DestinationID":"48100000","Consumed":1,"TOR":"*sms","RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"RoundingMethod":"*up","RoundingDecimals":2,"MaxCost":0,"MaxCostStrategy":"","Rates":[{"GroupIntervalStart":0,"Value":0.05,"RateIncrement":1,"RateUnit":1}]},"Weight":10}},"Monetary":{"UUID":"e13ed659-19bf-40cb-bd85-367a9aed3d45","ID":"monetary","Value":49.1,"RateInterval":null},"AccountID":"cgrates.org:kowalBulk"},"CompressFactor":1}],"RoundIncrement":null,"MatchedSubject":"*out:cgrates.org:bulk-sms-out:*any","MatchedPrefix":"48","MatchedDestId":"PL_Mobile","RatingPlanId":"RP_NO_PLAN_20220215_1559","CompressFactor":1}],"RatedUsage":1,"AccountSummary":{"Tenant":"cgrates.org","ID":"kowalBulk","BalanceSummaries":[{"UUID":"9859e4d5-79d3-469c-a5e4-e815e62b7dcf","ID":"sms-out_PL_Mobile:manual5","Type":"*sms","Value":0,"Disabled":false},{"UUID":"bba597db-a980-4519-84a6-e18179e69971","ID":"0ff96b48-8418-4020-85dd-5440902d3378","Type":"*sms","Value":0,"Disabled":false},{"UUID":"413ff3a4-0348-47bb-a2e1-d5d9f7641a5b","ID":"bulk-blocker","Type":"*sms","Value":10,"Disabled":false},{"UUID":"78777188-4b0b-495b-bc14-536b6596761b","ID":"bulk-blocker-unit","Type":"*sms","Value":10,"Disabled":false},{"UUID":"3658e92d-28d0-4300-897d-4ea536b37875","ID":"2ba99574-e3a1-4f53-81ff-45dc0f07bfc6","Type":"*sms","Value":0,"Disabled":false},{"UUID":"62adbfea-db57-4899-aa45-b72680c638ab","ID":"dfb5ed50-e006-45db-a417-ec7015c96659","Type":"*sms","Value":0,"Disabled":false},{"UUID":"f27e8262-78fb-4668-bc7b-dd0525f2447a","ID":"31639bae-48f0-457f-a0bb-6d8094bedfd9","Type":"*sms","Value":0,"Disabled":false},{"UUID":"f1eb58d9-029a-4b7f-9749-c47210e40824","ID":"a9cc01b4-bfb6-4525-a610-fbfc0bbb88a2","Type":"*sms","Value":0,"Disabled":false},{"UUID":"92c5cfb5-ebe7-4e5d-8945-11d682d07cac","ID":"bulk:6b4b98c2-d987-48fc-b6f5-0d776c322746","Type":"*sms","Value":0,"Disabled":false},{"UUID":"f10799f0-7a8b-4504-8c8d-c7f5b82d2615","ID":"bulk:e3fccf80-cec3-4b35-a981-486caf9ab5c4","Type":"*sms","Value":0,"Disabled":false},{"UUID":"3b552ad7-38dd-41c0-a664-bd7c4adb159d","ID":"bulk:169e1864-fe5a-4b62-9577-68cd43d519ae","Type":"*sms","Value":0,"Disabled":false},{"UUID":"e13ed659-19bf-40cb-bd85-367a9aed3d45","ID":"monetary","Type":"*monetary","Value":49.1,"Disabled":false}],"AllowNegative":false,"Disabled":false}},"error":null}

##


user get charged from *sms balance AND monetary balance

I never seen "ExtraChargeID" for *sms usage. 

{
   "CGRID":"b9a5fbee9a1440ac231395093b7fa3ee529fe5db",
   "RunID":"CustomerCharges",
   "StartTime":"2022-04-16T08:24:08.014Z",
   "Usage":1,
   "Cost":0.05,
   "Charges":[
      {
         "RatingID":"4ad599b",
         "Increments":[
            {
               "Usage":1,
               "Cost":0.05,
               "AccountingID":"91dcc8e",
               "CompressFactor":1
            }
         ],
         "CompressFactor":1
      }
   ],
   "AccountSummary":{
      "Tenant":"cgrates.org",
      "ID":"kowalBulk",
      "BalanceSummaries":[
         {
            "UUID":"fcddd20e-3725-44fa-a73e-ed47f89b9f73",
            "ID":"b7ae5d9f-f79f-4618-b8c7-f6266793d6ab",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"309b5d46-f25f-4efc-ae82-1776367c5595",
            "ID":"5cfcf447-8b9b-4c32-ac81-dcdd7be36b3a",
            "Type":"*sms",
            "Value":1000,
            "Disabled":false
         },
         {
            "UUID":"3f161e19-e2d8-400c-ad53-f170e386b20c",
            "ID":"5a6bfd92-ca45-4cf0-9a63-ed0aa31ae78b",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"ab3eb3cc-b4c5-4a46-96f3-771ca6e12f33",
            "ID":"3b080fd2-8779-4867-90e3-fcc11a9fc811",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"d8eba1e0-6dc8-46fe-8fc1-9e69dc926516",
            "ID":"3215f68a-d5d5-4c28-bb31-afe6f87b1cf2",
            "Type":"*sms",
            "Value":1000,
            "Disabled":false
         },
         {
            "UUID":"2d2dea1c-6fb3-45a1-a1a1-84438f8d999e",
            "ID":"bulk-blocker-unit",
            "Type":"*sms",
            "Value":10,
            "Disabled":false
         },
         {
            "UUID":"6e1d79dc-e3b9-4e69-8462-28c6d41036ab",
            "ID":"03ea7202-359f-45ab-9f95-49100da2c2b1",
            "Type":"*sms",
            "Value":1000,
            "Disabled":false
         },
         {
            "UUID":"aa3c04d8-f6da-493e-883d-61b3698268b8",
            "ID":"bulk-blocker",
            "Type":"*sms",
            "Value":10,
            "Disabled":false
         },
         {
            "UUID":"e4ea24b1-eb46-4735-ac7e-259026b7de04",
            "ID":"4ed40d63-3adc-431a-a816-0e89cb28cb8d",
            "Type":"*sms",
            "Value":895,
            "Disabled":false
         },
         {
            "UUID":"8765420e-5cd0-4403-9bd3-16b4a2bd1f0b",
            "ID":"0e8bf03d-bf04-4bb6-aae8-4d7aa09dd4cf",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"9859e4d5-79d3-469c-a5e4-e815e62b7dcf",
            "ID":"sms-out_PL_Mobile:manual5",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"20aac30d-a4f1-4668-984a-501c2839d2d9",
            "ID":"63a2665e-5f70-43fd-8ec0-e823342eaa91",
            "Type":"*sms",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"e13ed659-19bf-40cb-bd85-367a9aed3d45",
            "ID":"monetary",
            "Type":"*monetary",
            "Value":0,
            "Disabled":false
         },
         {
            "UUID":"f3289bf8-8233-4af9-8a6c-a3f776e23f41",
            "ID":"*default",
            "Type":"*monetary",
            "Value":-13.05058,
            "Disabled":false
         }
      ],
      "AllowNegative":false,
      "Disabled":false
   },
   "Rating":{
      "4ad599b":{
         "ConnectFee":0,
         "RoundingMethod":"*up",
         "RoundingDecimals":2,
         "MaxCost":0,
         "MaxCostStrategy":"",
         "TimingID":"c8f925d",
         "RatesID":"65b2cd8",
         "RatingFiltersID":"937050e"
      }
   },
   "Accounting":{
      "91dcc8e":{
         "AccountID":"cgrates.org:kowalBulk",
         "BalanceUUID":"20aac30d-a4f1-4668-984a-501c2839d2d9",
         "RatingID":"4ad599b",
         "Units":1,
         "ExtraChargeID":"c373dd3"
      },
      "c373dd3":{
         "AccountID":"cgrates.org:kowalBulk",
         "BalanceUUID":"f3289bf8-8233-4af9-8a6c-a3f776e23f41",
         "RatingID":"",
         "Units":0.05,
         "ExtraChargeID":""
      }
   },
   "RatingFilters":{
      "937050e":{
         "DestinationID":"PL_Mobile",
         "DestinationPrefix":"48",
         "RatingPlanID":"RP_NO_PLAN_20220215_1559",
         "Subject":"*out:cgrates.org:bulk-sms-out:*any"
      }
   },
   "Rates":{
      "65b2cd8":[
         {
            "GroupIntervalStart":0,
            "Value":0.05,
            "RateIncrement":1,
            "RateUnit":1
         }
      ]
   },
   "Timings":{
      "c8f925d":{
         "Years":[
           
         ],
         "Months":[
           
         ],
         "MonthDays":[
           
         ],
         "WeekDays":[
           
         ],
         "StartTime":"00:00:00"
      }
   }
}


Charger CustomerCharges

{
    "id": null,
    "result": {
        "Tenant": "cgrates.org",
        "ID": "CustomerCharges",
        "FilterIDs": null,
        "ActivationInterval": null,
        "RunID": "CustomerCharges",
        "AttributeIDs": [
            "*none"
        ],
        "Weight": 0
    },
    "error": null
}

Can you please guide me where to check for error ? 

Thanks,
Marcin

Adrian Porosnicu

unread,
Apr 27, 2022, 5:09:52 AM4/27/22
to CGRateS
Hi,

As  I can see in your ngrep, you have configured your sms balance with RatingSubject, and this will charge based on your rates. Also, by default, we do not do double charge since the rating subejct is 0, based on this configuration:  https://github.com/cgrates/cgrates/blob/master/config/config_defaults.go#L328

Thanks,
Adrian

Marcin Kowalczyk

unread,
Apr 27, 2022, 6:50:01 PM4/27/22
to cgr...@googlegroups.com
Hi Adrian,

Please correct me if I'm wrong: if sms balance is added with Rating Subject sms will be charged *both* from sms balance and from monetary based on RatingSubject rates?


--
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/UKuJuwMibk8/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/3a254784-be64-4a3d-a6fc-be6742fafb92n%40googlegroups.com.

Adrian Porosnicu

unread,
May 5, 2022, 4:05:58 AM5/5/22
to CGRateS
Hi Marcin,

Yes, you are right. Most of cases we do a double charge, exception is when we have a cost 0.

Thanks,
Adrian
Reply all
Reply to author
Forward
0 new messages