Overview
In PortaBilling, three key entities determine how service usage is billed:
- Rate codes define how a service is used – for example, the destination of a call (such as phone prefix 420 for Czech numbers) or the type of data that is accessed (such as text code RG101 for video streaming or RG102 web browsing).
- Rates define how much to charge for that usage. For example, you might charge $0.05 per minute for calls to Czech phone numbers.
- Tariffs are price lists made up of rates. Tariffs can be assigned to vendors (to calculate your costs), customers (to apply charges according to their product), and resellers.
Each time a customer uses a service (e.g., makes a call), PortaBilling identifies the rate code and looks up the applicable rate in the assigned tariff.
These three entities – rate codes, rates, and tariffs – are especially important for pay-as-you-go billing, where both your cost (to the vendor) and revenue (the customer’s charge) depend on usage. However, even when a service is included in a plan at no extra cost (e.g., as part of a bundle), a tariff is still required. PortaBilling uses it to:
- authorize service usage, and
- apply charges once the included allowance is used up.
A customer with a prepaid bundle has 50 out of 100 included minutes for calls to the Czech Republic and makes a 10-minute call to 4201234567 (a Czech number). Even though the customer has remaining bundle minutes, PortaBilling first checks the assigned tariff and finds a matching rate – $0.05 per minute for the 420 prefix. This step ensures that the customer is allowed to call this destination.
Since the bundle still has 50 minutes left, PortaBilling deducts 10 minutes from the allowance, and no charges apply.
The following sections explain each concept in detail.
Rate codes
Rate codes represent the phone number prefixes (e.g., the Czech prefix 420, which covers all phone numbers starting with 420) or other service identifiers. Each rate code corresponds to a specific area or usage type, such as a country, city, mobile network, or type of content accessed (e.g., video streaming).
Rate codes can be defined in:
- E.164 format
- E.212 format
- Custom text format
For voice calls, we recommend defining all phone number prefixes in the format <country code><area or mobile network code>, without the “+” at the beginning (e.g., 420603). PortaBilling also supports special codes, such as VOICEONNETRX, used for calls between extensions of the same cloud PBX customer.
You need to add a new rate code when introducing a new area or usage type that should be billed differently from others. All required rate codes must be added before they can be used in rates – this helps prevent errors and ensures data consistency.
You don’t need to maintain a full list of global prefixes – it’s nearly impossible to manage and doesn’t bring real benefits. Just add the rate codes you plan to use. PortaBilling supplies a file with a set of default codes, which you can download and then upload to the server during the initial configuration of PortaBilling. When uploading rates to tariffs, any new codes are added automatically.
SMS rate codes (E.212 format)
If you are a mobile operator engaged in wholesale SMS delivery, you may need to define rate codes in the E.212 format. These consist of:
- MCC (Mobile Country Code) – e.g., 230 for the Czech Republic
- MNC (Mobile Network Code) – e.g., 03 for Vodafone
Rate codes for non-telephony services
For service types other than those based on phone numbers, you may add text rate codes such as WIFI, NETACCESS (for internet access), or MOVIE-BLOCKBUSTER (for pay-per-view content). These work like regular rate codes in tariffs but use service-specific identifiers instead of number prefixes.
Rates
A rate defines how much to charge for a specific type of service usage, based on a given rate code (e.g., a phone number prefix or service identifier) and specific conditions (e.g., time of day, rounding, etc.).
To simplify routine rate updates, each rate in PortaBilling has an Effective from date – the exact time when the rate becomes active. This allows you to schedule rate changes in advance. For example, you can enter a new rate today that will take effect after midnight on January 1st.
When a rate is updated, PortaBilling doesn’t overwrite the old one. Instead, it creates a new entry with the updated values and a new effective date. This ensures that a complete history of all rate changes is stored.
Discontinuing rates
To maintain a clear history of rate changes, rates that are no longer needed are not deleted from the system. Instead, they can be marked as discontinued. Discontinued rates are no longer used for rating but can be displayed in the web interface.
Tariffs
A tariff is a complete set of rates. It serves as a price sheet for billing service usage.
You can use the following types of tariffs:
- Vendor tariffs – specify how much your vendor charges you. These are defined at the vendor connection level.
- Customer tariffs – specify how much you charge your customers. These are defined at the main product level (main products are assigned to customer accounts).
- Reseller tariffs – specify how much you charge your resellers. These are defined at the product level (for main products managed by resellers).
When a customer uses a service (e.g., makes a phone call to 420602555123), PortaBilling searches for matching rates (such as 420602 – $0.01/min) in both the vendor and customer tariffs. If the customer belongs to a reseller, PortaBilling also searches for a matching rate in the reseller tariff.
Since tariffs for voice calls are the most complex case, they will be the primary focus of this chapter.
How PortaBilling finds the matching rate in the tariff
To determine how much to charge for a service, PortaBilling generates a rate pattern – a string that identifies the event (such as a call) and helps locate the appropriate rate in the tariff.
How rate patterns work
In the simplest case, for a voice call, the rate pattern is just the called number.
If a customer dials 420602555123, the rate pattern is also 420602555123. PortaBilling starts by looking for an exact match for this number in the rates defined in the tariff. If no match is found, PortaBilling removes the last digit and searches again:
- 42060255512
- 4206025551
- …
This process continues until a matching rate is found (e.g., 420602).
Longest match wins
If a tariff includes multiple matching rate codes, PortaBilling always applies the longest matching rate code.
A customer’s tariff includes the following rates:
- 420 – $0.02/min
- 420602 – $0.03/min
The customer makes an off-net call to 420602123456. The rate pattern is 420602123456. PortaBilling searches for a matching rate code in the tariff by shortening the number one digit at a time:
- 420602123456
- 42060212345
- …
- 420602 (match found)
Although both 420 and 420602 match the number, PortaBilling applies the longer match (420602) and charges $0.03 per minute.
If the longest matching rate is marked as forbidden, PortaBilling does not fall back to a shorter, allowed rate and does not authorize the call. For example, if 420602 is the longest match and the 420602 rate is marked as forbidden, the call is not authorized. The 420 rate is not used as a fallback.
Rate patterns with text codes
Rate patterns can also include keywords (text-based codes), which can be:
- Defined by PortaSwitch – e.g., VOICEONNET, which is automatically applied for outgoing on-net calls.
- Received from external systems – e.g., MOVIE_PREMIUM, used to charge for pay-per-view content.
Structure of a rate pattern (telephony)
For telephony events, the rate pattern may consist of:
- A text code (if applicable)
- The “pipe” (|) character as a separator
- The phone number
Rate matching priority
PortaBilling applies the following logic to determine the correct rate:
- Check for a match by text code (e.g., VOICEONNET)
- If no match is found, check by phone number (e.g., 42035). Typically, this is the destination number (CLD); however, in scenarios when it’s needed to charge based on the call origin, it can be the caller’s number (CLI).
- If a match has still not been found, check for the fallback rate defined for the wildcard code (|). This is commonly used for incoming calls, where a flat $0.00 rate applies regardless of the number.
You define the following rates in a customer tariff for outgoing calls:
- VOICEONNET – $0.00 (on-net call)
- 42035 – $0.10 (off-net call)
Now, two calls are made to the number that starts with 42035:
- Call 1: From one PortaSwitch account to another (on-net call)
The rate pattern is VOICEONNET|420351234567
PortaBilling finds the rate for VOICEONNET
Result: Call is free (rated at $0.00)
- Call 2: From a PortaSwitch account to a fixed line (off-net call)
No special keyword applies; the rate pattern is 420352223334
PortaBilling finds the rate for 42035
Result: Call is charged at $0.10 per minute
You don’t charge for incoming calls to regular numbers, so you define a single rate in a customer tariff for incoming calls:
- | - $0.00 (wildcard rate)
A customer receives an incoming call to 420351234567.
The rate pattern is: INCOMING|420351234567
PortaBilling searches for matching rate codes in the following order:
- INCOMING – no match
- 420351234567 – no match
- | – match found
Result: The call is rated at $0.00.
Rate patterns for different scenarios
These are examples of rate patterns and corresponding rates found in the tariff for different scenarios:
| Scenario | Rate pattern | Corresponding rate code found in the tariff |
|---|---|---|
| Outgoing call to fixed line | “441171239873” | 44117 |
| Outgoing on-net call (within PortaSwitch) | “VOICEONNET|420602555123” | VOICEONNET |
| Incoming call to a regular number | “INCOMING|420351234567” | “|” |
| Incoming call to a toll-free number | “INCOMING|420800123456” | 420800 |
| Pay-per-view content access | MOVIE_PREMIUM | MOVIE_PREMIUM |
What if no matching rate is found?
If a customer attempts to use a service (e.g., dials a number) and there’s no matching rate code in their tariff:
- If outgoing calls are authorized via PortaBilling, the customer will not be allowed to call this destination.
- If a third-party gateway or switch allows the call without authorization, the customer will still be able to make the call, but PortaBilling won’t be able to bill it correctly, as no matching rate is found. In this case, an email alert is sent, and a special CDR is created in the database to record the call for review.
Rounding for charged amounts
You can configure rounding precision (i.e., the number of decimal places) for each tariff to round up the charged amounts.
PortaBilling always rounds the charged amount upward in each individual xDR. For example, if rounding is set to two decimals, the values 1.204, 1.205, and 1.206 are all rounded up to 1.21.
To set the number of decimals:
Go to Tariff > General configuration, and choose the desired option in the Rounding precision field. The default value is 5 decimals.
Typical pricing setup flow
Here’s a typical flow for setting up pricing in PortaBilling:
- Define custom rate codes (for non-telephony services only)
For services like internet access or pay-per-view video, define custom rate codes manually.
For telephony services, this step is not needed – rate codes are created automatically when you upload rates to tariffs. - Create vendor tariffs
- For telephony services, import your vendors’ price lists into their respective tariffs.
- For non-telephony services, rates can be entered manually.
- Create customer tariffs
- For telephony services, upload customer-specific rates into the corresponding customer tariffs.
- For non-telephony services, rates can be entered manually.
- Assign tariffs
- Assign vendor tariffs to vendor connections.
- Assign customer tariffs to products.
- Monitor changes
- Schedule rate updates using effective dates to automate future pricing changes.
