Billing
The CommuniGate Pro Server can act as a Billing platform.
Each Account can have one or several Balances. CommuniGate Pro modules and components can post charges and credits to these balances, make refunds, etc.
The current amount is maintained for each Balance, along with active reservations.
The log of all transactions is kept in the Account data files. The Log format provides for easy backup and restore operations, and for Balance recovery after hardware failures.
The "default" or "generic" Balance uses an empty string as its name.
Monetary values (funds) are presented as 64-bit signed integer values.
Reservations
The Balance reservations are used when some billed activity takes time and/or a billing activity takes place in several steps.
The application first "reserves" a certain monetary amount, sufficient to pay for some initial stage of the billed activity. For example, it can be an amount needed to pay for the first minute of a call, or to play the first level of a game.
If the selected Balance does not have sufficient funds, the reservation request is rejected.
Otherwise, a reservation (with an application-supplied or server-generated name) is created inside the Balance. The total funds available in the Balance are decreased by the reserved amount, but not charge record is created in the transaction log.
As the payment amount of the billed activity approaches the reserved amount, the application "extends" the created reservation by some additional amount. If the Balance does have enough "free funds" (i.e. funds not reserved with other reservations), the reservation amount is extended.
The application can release the created reservation. The reservation is removed from the Balance, and the reserved amount is returned to the Balance "free funds". For example, this function can be used when a phone call was not connected, as the reserved funds must be released without recording any charge transaction.
Finally, the application charges the Balance, specifying the reservation. The charge amount should not exceed the amount reserved.
The transaction log record is created, and the charged amount is subtracted from the Balance and from the reservation reserved amount. Optionally, the reservation can be released, and the remaining funds returned to the Balance "free funds".
When a reservation is created or extended, the application can specify the reservation expiration time. The reservation is released automatically after the specified time. This feature can be used if the application can disconnect or quit without explicitly releasing its reservations.
When creating or extending a reservation, the application can specify the amount that should be charged if the reservation is timed-out and it is released automatically. For example, when a game application extends the reservation to cover the next game level, it can specify the amount that should be already be paid for the current game. If the application quits or disconnects without explicitly charging the Balance reservation, the reservation will be released automatically, but the specified amount will be changed first.
Interfaces
The CommuniGate Pro Billing subsystem is available for:
- CG/PL server-side applications (PBX Tasks, WebUser applets, etc.)
- XIMSS client applications.
- ParlayX client applications.
- CLI client applications.
Operations
The following Billing operations are available:
listThis operation lists all Balances available for this Account.
Parameters:
none
Results:
balancean array of available Balance names.
creditThis operation adds funds to a Balance.
Parameters:
balancea string: the Balance name. If the Balance with this name does not exist, it is created.
amounta non-negative number: the credited amount.
referencea string: arbitrary data used for references, dispute resolutions, etc.
descriptionan object (usually a string or an array of strings): arbitrary data describing the transaction.
Results:
amounta number: the current Balance value.
removeThis operation removes a Balance.
Note
The Balance history is not removed. If the current Balance value is not zero, a record is added to the Balance history, changing the Balance value to zero.
Parameters:
balancea string: the Balance name. The Balance with this name is removed.
Results:
amounta number: the removed Balance value.
reserveThis operation reserves funds from a Balance. The reserved amount cannot be used for other charges. The reservation can be released explicitly, returning funds to the Balance, or it can expire after the specified period of time.
Parameters:
balancea string: the Balance name. This Balance must already exist.
amounta number: the amount to reserve. If the reservation already exists, this value is used to increase the reserved amount.
reservea string, optional: if this parameter exists, it should specify the existing reservation. The
amountwill be added to this reserve. If this parameter is absent, a new reservation is created.expiresa timestamp, optional: if this parameter exists, it specifies when this reservation should expire.
overdraftoptional: if this parameter exists, it is possible to reserve an amount larger than the current Balance value. If this parameter does not exist, attempts to reserve an amount larger than the current Balance value are rejected.
chargea number: the amount to charge if this reservation expires and it is automatically released.
reference,descriptionthese strings can be specified if the
chargeparameter is specified. They have the same meaning as thecreditoperation parameters, and they are used if this reservation is automatically charged when it expires.
Results:
reservea string: the reservation name (the same as the
reserveparameter, if it was specified).amounta number: the current reservation value.
totala number: the current Balance "free funds".
releaseThis operation releases a reservation. The reserved amount is returned to the Balance.
Parameters:
balancea string: the Balance name. This Balance must already exist.
reservea string: the existing reservation name.
Results:
reservea string: the reservation name (the same as the
reserveparameter, if it was specified).amounta number: the released reservation value.
totala number: the current Balance "free funds".
chargeThis operation subtracts funds from a Balance or a reservation.
Parameters:
balancea string: the Balance name. This Balance must already exist.
amounta number: the amount to charge.
reservea string, optional: if this parameter exists, the charge is applied to the already existing reservation. If this parameter is absent, the charge is applied to the Balance itself.
overdraftoptional, cannot be specified together with the
reserveparameter: if this parameter exists, it is possible to charge an amount larger than the current Balance value. If this parameter does not exist, attempts to charge an amount larger than the current Balance value are rejected.releaseoptional, cannot be specified without the
reserveparameter: if this parameter exists, the reservation is released after the charge is made.reference,descriptionsame as for the
creditoperation.
Results:
amounta number: the current Balance "free funds" or reservation value.
totala number: the current Balance "free funds" (only if the
reserveparameter is specified).expiresa timestamp: the reservation expiration time (only if the
reserveparameter is specified and the reservation has an expiration time set).
readThis operation reads the current Balance or reservation value.
Parameters:
balancea string: the Balance name. This Balance must already exist.
reservea string, optional: if this parameter exists, it must specify an existing reservation. The operation reads that reservation value. If this parameter is absent, the operation reads the Balance value.
Results:
amounta number: the current Balance or reservation value.
expiresa timestamp: the reservation expiration time (only if the
reserveparameter is specified and the reservation has an expiration time set).
historyThis operation reads the Balance transaction log.
Parameters:
balancea string: the Balance name. This Balance must already exist.
timeFrom,timeTilltimestamps: Balance records from recorded on or after
timeFrombut beforetimeTill(exclusive) are read.limita number: the maximum number of records to display.
If this number is positive, the newest records are returned first, and the oldest records are discarded if the record number limit is reached.
If this number is negative, the oldest records are returned first, and the newest records are discarded if the record number limit is reached.
Results:
historyan array of transaction records. Each record contains the following elements:
Datea timestamp: the time of transaction.
amounta number: the transaction amount (positive for
creditoperations).balancea number: the Balance value after this transaction.
reference,descriptioncopies of the
creditandchargeoperation parameters.
calllogThis operation reads the Call Log files.
Parameters:
timeFrom,timeTilltimestamps: records for calls that took place on or after
timeFrombut beforetimeTill(exclusive) are read.limita number: the maximum number of records to display.
If this number is positive, the newest records are returned first, and the oldest records are discarded if the record number limit is reached.
If this number is negative, the oldest records are returned first, and the newest records are discarded if the record number limit is reached.filteroptional string: if specified, the operation returns only the calls with peers whose addresses or "real names" match the specified string.
Results:
callHistoryan array of transaction records. Each record contains the following elements:
Datea timestamp: call start time (GMT).
directionthe "inp" string for incoming calls, the "out" string for outgoing calls.
Tothe peer address string.
RealName(optional) the real name of the peer.
Call-IDthe call Call-ID string.
disconnecteda timestamp: call end time (GMT).
connecteda timestamp: call connected time (GMT). If absent, the call has not been connected.
dialogError(optional) call completion/failure error code string.
dialogApp(optional) if a call has been answered by a PBX application, the application program name string.
amountthe total number of found call records