> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.14/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.14/api-reference/charging_api.md).

# Charging API

This module defines the Charging API. This API may be used to provision user accounts and
thereafter manage the user account objects. The API provides CRUD functionality to manage
charging account information.

The Charging API exposes the following data models to the consumer:

```
   object Account {
      ChargingAccountId : string
      TariffId : string
      ValidFrom : string
      ValidTill : string
      Balances : list of balance objects,
      TariffOptions : object
   }

   object Balance {
      BalanceId : string
      BalanceDefinitionId: uint64
      IMSI : string
      CarrierGroupId : string
      ValidityTime : uint64
      ValidFrom : string
      ValidTill : string
      TotalOctets : uint64
      InitialBalanceId : string
      IMEI : string
      CDF : string
   }

   object CarrierGroup {
      CarrierGroupId : string
      CarrierGroupName : string
      Carriers : list of Carrier objects
   }

   object Carrier {
      CountryName : string
      CarrierName : string
      CountryCode : string
      Mnc : string
      MccMnc : string
   }

   object TariffOptions {
     UnlimitedStreaming : bool
     UnlimitedStreamingCarrierGroups: list of Carrier groups
   }
```

|Attribute | Description
|---|---
| ChargingAccountId | Given by the 3rd party system AAX.
| TariffId | Unique identifier for the tariff which is associated with the charging account.
| IMSI | Unique identifier of a SIM card.
| CarrierGroupId | Represents the carriers that are combined in groups. `CarrierGroup` will be used to define the allowed Carriers for  usage of `Balance`.
| CarrierGroupName | Name for the carrier group.
| CountryName | Name of the country.
| CountryCode | ISO 3166-1 Alpha-2 code of country.
| Mnc | MNC of Carrier
| MccMnc | MCCMNC combination as defined in RADIUS Requests.
| ValidFrom | Validity range start date, in ISO 8601 format.
| ValidTill | Validity range end date, in ISO 8601 format.
| TotalOctets | Amount of traffic in bytes.
| IMEI | Optional field which contains unique identifier of a user device
| CDF | Optional field which specifies should CDRs be sent towards CDF or not
| TariffOptions | Optional field which specifies tariff options for the given Account

## Charging Accounts and Balances

The CCS does **NOT** delete Charging Accounts or Balances from the database if
requested by API calls. Instead these objects are marked for deletion and not
further visible by API consumers. An internal housekeeping process will finally
delete these objects from the database.

The balance object consists of integer units and different identification
parameters that defines the validity of the units. The Parameter
`ValidityTime` defines the absolute duration of the balance. The `ValidFrom`
date will be set to the date of provisioning the balance. `ValidTill`
describes the end of validity of the Balance.

Example of a Balance object:

```
   {
      "BalanceId": "13@balance.charging.<tenant>",
      "BalanceDefinitionId": 3,
      "IMSI": "262019876543210",
      "CarrierGroupId": "27@carriergroup.charging.<tenant>",
      "ValidityTime": 86400,
      "ValidFrom": "2017-12-31T00:00:00Z",
      "ValidTill": "2017-12-31T23:59:59Z",
      "TotalOctets": 52428800,
      "InitialBalanceId": "13@balance.charging.<tenant>",
      "IMEI": "012345678901237"
      "CDF": "IBMD"
   }
```

The `InitialBalanceId`, `CDF` and `IMEI` parameters are always optional.

Also note that a `TariffId` refers to a tariff which is responsible for
semantics of session initialization in TPOSS PCS and CCS. Please refer to the
TISP Operations Manual for a more detailed description of the tariffs.

## Methods

### Charging.Account.Create

Registers a new charging account with the given account information.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |
| TariffId | String | required | Unique identifier for the tariff which is associated with the charging account.
| ValidFrom | String | required | Validity range start date, in ISO 8601 format. |
| ValidTill | String | required | Validity range end date, in ISO 8601 format. |
| TariffOptions | Object | optional | Tariff options |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.Account.Create",
         "params": {
            "AuthKey": "secret",
            "FeId": "TPUIBrowser",
            "FeSId": "TPUIBrowser",
            "ChargingAccountId": "700030010@.account.charging.<tenant>",
            "TariffId": "online",
            "ValidFrom": "2015-03-01T18:12:00Z",
            "ValidTill": "2018-07-31T23:59:59Z",
            "TariffOptions": {
              "UnlimitedStreaming" => true,
             "UnlimitedStreamingCarrierGroups" => ["27@carriergroup.charging.<tenant>"]
            }
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of error following error codes could be returned:

- `-31801` - Duplicate account An account with the given Account-Id already exists
- `-31802` - Tariff not found There is no registered tariff with the given `TariffId`
- `-31803` - Validity range invalid Valid-From, Valid-Till date range is invalid

### Charging.Account.Read

Returns the object information for the charging account object associated with
the given `ChargingAccountId`. Returns an error if no associated charging
account object can be found.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method":"Charging.Account.Read",
         "params": {
            "AuthKey": "secret",
            "FeId": "TPUIBrowser",
            "FeSId": "TPUIBrowser",
            "ChargingAccountId": "700030010@account.charging.subscriber.<tenant>",
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": {
         "ChargingAccountId": "700030010@.account.charging.<tenant>",
         "TariffId": "online",
         "ValidFrom": "2015-03-01T18:12:00Z",
         "ValidTill": "2018-07-31T23:59:59Z",
         "Balances": [
            {
               "BalanceId": "13@balance.charging.<tenant>",
               "BalanceDefinitionId": 3,
               "IMSI": "262019876543210",
               "CarrierGroupId": "27@carriergroup.charging.<tenant>",
               "ValidityTime": 86400,
               "ValidFrom": "2017-12-01T00:00:00Z",
               "ValidTill": "2017-12-31T23:59:59Z",
               "TotalOctets": 52428800,
               "InitialBalanceId": null
            }
         ]
      }
   }
```

If a balance was provisioned with `IMEI` or/and `CDF` and account was provisioned
with tariff options, the response will also contain it:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": {
         "ChargingAccountId": "700030010@.account.charging.<tenant>",
         "TariffId": "online",
         "ValidFrom": "2015-03-01T18:12:00Z",
         "ValidTill": "2018-07-31T23:59:59Z",
         "TariffOptions": {
           "UnlimitedStreaming" => true,
           "UnlimitedStreamingCarrierGroups" => ["27@carriergroup.charging.<tenant>"]
         },
         "Balances": [
            {
               "BalanceId": "13@balance.charging.<tenant>",
               "BalanceDefinitionId": 3,
               "IMSI": "262019876543210",
               "CarrierGroupId": "27@carriergroup.charging.<tenant>",
               "ValidityTime": 86400,
               "ValidFrom": "2017-12-01T00:00:00Z",
               "ValidTill": "2017-12-31T23:59:59Z",
               "TotalOctets": 52428800,
               "InitialBalanceId": null,
               "Labels": {
                 "IMEI": "2620198765432101",
                 "CDF": "IBMD"
               }
            }
         ]
      }
   }
```

In a case of a charging account does not exists - `-31804` error code will be returned.

### Charging.Account.Delete

Deletes all account information associated with a charging account object.
Returns an error if no account can be found.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.Account.Delete",
         "params": {
            "AuthKey": "secret",
            "FeId": "TPUIBrowser",
            "FeSId": "TPUIBrowser",
            "ChargingAccountId": "700030010@account.charging.<tenant>"
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "101", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of a charging account does not exists - `-31804` error code will be returned.

### Charging.Account.Update

Updates the account information for a charging account object. Returns an error if no
associated account cannot be found or an update fails.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |
| TariffId | String | required | Unique identifier for the tariff which is associated with the charging account.
| ValidFrom | String | required | Validity range start date, in ISO 8601 format. |
| ValidTill | String | required | Validity range end date, in ISO 8601 format. |
| TariffOptions | Object | optional | Tariff options |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.Account.Update",
         "params": {
            "AuthKey": "secret",
            "FeId": "TPUIBrowser",
            "FeSId": "TPUIBrowser",
            "ChargingAccountId": "700030010@.account.charging.<tenant>",
            "TariffId": "online",
            "ValidFrom": "2015-03-01T18:12:00Z",
            "ValidTill": "2018-07-31T23:59:59Z",
            "TariffOptions": {
              "UnlimitedStreaming" => false,
              "UnlimitedStreamingCarrierGroups" => ["27@carriergroup.charging.<tenant>"]
            }
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of error following error codes could be returned:

- `-31802` - The requested tariff is not provisioned.
- `-31803` - Valid-From, Valid-Till date range is invalid.
- `-31804` - There is no charging account with the given Account Id.

### Charging.Balance.Add

Add a balance object to a charging account. If `ValidityTime` is present then
`ValidFrom` and `ValidTill` are calculated based on this value and provision
time. If `ValidFrom` and `ValidTill` is present then `ValidityTime` is
calculated based on these values. If all three parameters are present at the
same time or none of the three parameters are given then an error message will
be returned.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |
| Balance | Object | required | Balance object. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "205", "jsonrpc": "2.0",
         "method": "Charging.Balance.Add",
         "params": {
            "AuthKey": "secret",
            "FeId": "bss1.<tenant>",
            "FeSId": "13.bss1.<tenant>",
            "ChargingAccountId": "700032310@account.<tenant>",
            "Balance": {
               "BalanceId": "13@balance.charging.<tenant>",
               "BalanceDefinitionId": 3,
               "IMSI": "262019876543210",
               "CarrierGroupId": "27@carriergroup.charging.<tenant>",
               "ValidityTime": 86400,
               "TotalOctets": 52428800,
               "IMEI": "012345678901237",
               "CDF": "IBMD",
            }
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of error following error codes could be returned:

- `-31803` - Either all three validity time parameters are present or none at all
- `-31804` - There is no charging account with the given Account Id
- `-31805` - A balance with the given BalanceId already exists

### Charging.Balance.VolumeUpgrade

The method can be used to extend the allowed volume in the parent balance of a
charging account. The parent balance will be found using the parameters
`ChargingAccountId`, `IMSI` and `CarrierGroupId`. The parent balance will
be referenced by the `BalanceId` attribute.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |
| Balance | Object | required | Balance object. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.Balance.VolumeUpgrade",
         "params": {
            "AuthKey": "secret",
            "FeId": "bss1.<tenant>",
            "FeSId": "13.bss1.<tenant>",
            "ChargingAccountId": "700032310@account.charging.<tenant>",
            "Balance": {
               "BalanceId": "13@balance.charging.<tenant>",
               "BalanceDefinitionId": 3,
               "IMSI": "262019876543210",
               "CarrierGroupId": "27@carriergroup.charging.<tenant>",
               "TotalOctets": 52428800,
               "IMEI": "012345678901237",
               "CDF": "IBMD"
            }
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of error following error codes could be returned:

- `-31804` - There is no charging account with the given Account Id
- `-31805` - A balance with the given BalanceId already exists
- `-31807` - There is no balance existing that can be used for add the volume to it

### Charging.Balance.Delete

Marks the balance object associated with the given id as candidate for delete.
Returns an error if no balance object can be found.

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| ChargingAccountId | String | required | Unique identifier for the charging account. |
| BalanceId | String | required | A unique identifier for the balance. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.Balance.Delete",
         "params": {
            "AuthKey": "secret",
            "FeId": "bss1.<tenant>",
            "FeSId": "13.bss1.<tenant>",
            "BalanceId": "13@balance.charging.<tenant>"
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```

In a case of error following error code could be returned:

- `-31806` - There is no balance object with the given BalanceId

### Charging.CarrierGroup.Import

This Method Imports a complete list of carrier groups with the related carriers.
The source data derived from a JSON structure with all defined CarrierGroups and
Carriers. This import methos do a diff with this source data compared with the
existing destination CarrierGroup and Carrier data in CCS. The result of this
diff will be applied to the destination. As a result the CarrierGroups and
Carriers in CCS is a 1 by 1 mapping to the data from the source JSON from the
original request.

For each Carrier from the provided source data within a CarrierGroup the
following checks will be done during import:

- Carrier already exists with the identical values? -> skip this record
- Carrier already exists with different values? -> update the changed values
  for this Carrier
- Carrier does not exist? -> insert the Carrier to this CarrierGroup
- Carrier exists in destination CarrierGroup, but not in provided source data?
  -> Delete Carrier from the CarrierGroup

Following parameters could be passed:

| Name | Type | Requirement | Note |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| CarrierGroups | Object | required | List of CarrierGroups. |

Example of request:

```
   $ curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d
     '{
         "id": "1", "jsonrpc": "2.0",
         "method": "Charging.CarrierGroup.Import",
         "params": {
            "AuthKey": "secret",
            "FeId": "bss1.<tenant>",
            "FeSId": "13.bss1.<tenant>",
            "CarrierGroups": [
               {
                  "CarrierGroupId": "27@carriergroup.charging.<tenant>",
                  "CarrierGroupName": "Europe",
                  "Carriers": [
                     {
                        "CountryName": "GERMANY",
                        "CarrierName": " Telekom Deutschland GmbH ",
                        "CountryCode": "DE",
                        "Mnc": "01",
                        "MccMnc": "26201"
                     },
                     {
                        "CountryName": "AUSTRIA",
                        "CarrierName": "T-Mobile Austria",
                        "CountryCode": "AT",
                        "Mnc": "03",
                        "MccMnc": "23203"
                     }
                  ]
               }
            ]
         }
      }' http://127.0.0.1:12001
```

Example of response:

```
   {
      "id": "1", "jsonrpc": "2.0",
      "result": "true"
   }
```
