# 19 Billing

### Overview

PortSIP PBX includes a comprehensive Call Accounting and Billing system that allows you to generate detailed call cost reports, both manually and automatically.

Billing can be applied at either the tenant or user (extension) level and supports both real-time balance enforcement and post-call cost calculation.

***

### Enabling Billing

1. Sign in to the PortSIP PBX Web Portal as a **Tenant Administrator**.
2. Navigate to **Billing > Settings**.
3. Enable or disable the billing feature as required.

***

### Billing Settings

#### Enable Call Billing

Turn this option **on** to activate the billing system.

#### Billing Profile

Defines where call charges are applied:

* **Tenant** – Charges are deducted from the tenant’s balance
* **User** – Charges are deducted from the extension user’s balance

#### Charge Mode

Defines how charges are calculated and enforced:

* **Online Charging**
  * The PBX checks the available balance **before and during** the call
  * If sufficient balance exists, the call proceeds
  * Call cost is deducted and recorded in the CDR after call completion
  * Balance verification applies to:
    * Tenant balance (if Billing Profile = Tenant)
    * User balance (if Billing Profile = User)
* **Offline Charging**
  * No balance check is performed
  * Call cost is calculated after the call and recorded in the CDR
  * No balance deduction or call blocking occurs

<figure><img src="https://846155343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfkamWLaD5pcQwlKWwC%2Fuploads%2FMd8xhBOsnMacKGJ4VnKm%2Fbilling_1.png?alt=media&#x26;token=93a55c2a-55f7-42bf-a42a-90335bddc66e" alt=""><figcaption></figcaption></figure>

***

### Account Recharge

#### Tenant Balance

* **Current Balance**\
  Displays the tenant’s current balance. This field is **read-only**.
* **Recharge**\
  Allows the tenant administrator to add funds to the tenant account.

***

#### Recharge for a User

To recharge an individual user’s balance:

1. Navigate to **Call Manager > Users**.
2. Edit the desired user.
3. Open the **Balance** tab.
4. Enter the recharge amount and save.

***

### Managing Billing Rules

To manage billing rules:

1. Navigate to **Billing > Billing Rules**.
2. From this page, you can:
   * Create new rules
   * Modify existing rules
   * Delete rules
   * Import or export billing rules

#### Rule Matching Logic

* Billing rules are matched using the **called number prefix**
* If the prefix matches, the call is billed
* **Prefixes must be unique** and cannot be duplicated

***

### Billing Rule Parameters

When creating a billing rule, the following parameters can be configured:

* **FreeSeconds** – Free call duration (seconds)
* **ConnectFee** – Fixed charge applied upon successful call connection
* **PostCallSurcharge** – Percentage surcharge (e.g., `0.01` = 1%)
* **GracePeriod** – Minimum call duration required for billing (seconds)
* **Price1** – Rate per minute for the initial billing interval
* **PriceN** – Rate per minute for subsequent billing intervals
* **Interval1** – Initial billing interval (seconds)
* **IntervalN** – Subsequent billing interval (seconds)

The simplest parameters are *ConnectFee*, which is a fixed amount of money charged for each successful call regardless of its duration; and *PostCallSurcharge* which is additional charge applied. It is calculated on the percentage of the amount charged, that is if the call costs 1 dollar and the *PostCallSurcharge* is 0.01, the actual amount charged will be 1.01 dollar.

The following picture illustrates how the calls are charged. The process starts with comparing value of the *GracePeriod* parameter with the duration of the call. The *GracePeriod* parameter determines the minimum duration of the call that will be subject of charge. Calls with durations of less than this value are not charged at all. *GracePeriod* value of 0 second and 1 second provide almost the same behavior except that when the *GracePeriod* is 1 second, connected calls with zero duration won't be charged with connection fee.

A *ConnectFee* is charged immediately upon connection, and all calls shorter than Interval’ will be rounded to *Interval1* seconds. *FreeSeconds* are granted after the *Interval1*, so this part of the call is not charged, and calls shorter than (*Interval1* + *FreeSeconds*) will be rounded to *Interval1* seconds. If call is longer than (*Interval1* + *FreeSeconds*) remaining portion will be rounded up to multiple *IntervalIN* seconds. After that, the *PostCallSurcharge* is applied to the total amount charged.

<figure><img src="https://846155343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfkamWLaD5pcQwlKWwC%2Fuploads%2F4mnTcTGIP25LUyeqItsz%2Fbilling_2.png?alt=media&#x26;token=1d2c8938-aeb5-45f0-ab7b-1ae72b4bcf0e" alt=""><figcaption></figcaption></figure>

***

### Call Cost Formula

The total call cost is calculated using:

* **ConnectFee**
* **Price1 × Interval1**
* **PriceN × IntervalN**
* **PostCallSurcharge**

Where:

* All time values are rounded according to billing intervals
* Surcharge is applied after base cost calculation

The call illustrated in the figure will be charged using the following formula:

<figure><img src="https://846155343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfkamWLaD5pcQwlKWwC%2Fuploads%2FT0vrvDT6DAkJ1y5mJiW4%2Fbilling_3.png?alt=media&#x26;token=8bb59622-ca4a-4c65-ad93-3168e15c7014" alt=""><figcaption></figcaption></figure>

* Connect fee - monetary units
* Price 1 - monetary units
* Price N - monetary units
* Interval 1 - seconds
* Interval N - seconds
* Post call surcharge - fractional based on the setting in the Tariff/Destination Set (E.g. for 10% fractional = 0.1)
