Перейти к содержимому

External balance daemon

Это содержимое пока не доступно на вашем языке.

The switch keeps the balances of accounts, customers and vendors in its own balance subsystem. Instead of it, you can run your own balance service, for example to share one balance between FlySIP and other platforms. The switch then calls your service for every balance check and every charge.

This is not an XML-RPC method. The interface is an RPC schema in the Thrift interface description language, which FlySIP provides on request. Your service implements the methods below; the call engine, the panel and the XML-RPC API are its clients.

The interface works with abstract balance entities, called accounts in the schema. Each FlySIP account, customer or vendor is linked to one of them.

Attribute Meaning
i_balance Unique ID of the balance entity
balance Current balance
credit limit How far the balance may go below zero
commodity Read-only grouping key, set at creation. For accounts, customers and vendors it is the three-letter currency code
reference counter Number of FlySIP objects that use the entity. At zero the entity is unused and safe to delete

Most methods return a BalanceInfo structure with the current values.

The call engine calls these methods in real time during call setup and after each call, so they must answer fast.

Method What it does
register_service(service_id) Binds the current session to a service ID, an arbitrary constant string that identifies the client. Call it first in every session
next_i_balance_update() Returns a unique transaction ID for the next make_debit, add_credit or block_amount. The ID makes sure a transaction is never applied twice
get_balance(i_balance) Returns the BalanceInfo of an entity
make_debit(i_balance, amount, i_balance_update, unblock_ids[]) Decreases the balance by amount, which must be greater than zero, and releases the blocked amounts in unblock_ids. The balance may go negative. Returns the updated BalanceInfo
add_credit(i_balance, amount, i_balance_update) Increases the balance by amount, which must be greater than zero. Returns the updated BalanceInfo
block_amount(i_balance, amount, i_balance_update, service_id, expires, unblock_ids[]) Reserves amount for a call in progress and returns the block ID with the updated BalanceInfo. Fails if the balance would drop below zero or the entity does not exist. The block is released automatically after expires, by default 10 minutes
unblock_amount(i_blocked_amount) Releases one blocked amount
clear_blocked_amounts() Releases every amount blocked under the current service ID. A client calls it once at start-up, to release blocks left over from a crash

block_amount and clear_blocked_amounts fail when register_service has not been called in the session.

Methods used by the panel and the XML-RPC API

Section titled “Methods used by the panel and the XML-RPC API”
Method What it does
create_balance(balance, credit_limit, commodity, ref_count) Creates an entity and returns its i_balance. ref_count must be at least 1
inc_ref_count(i_balance, i_balance_update) Increments the reference counter
dec_ref_count(i_balance, i_balance_update) Decrements the reference counter. The interface has no delete method: an entity at zero is simply no longer used
get_balances(i_balances[], filter) Returns the entities of the list whose balance, credit limit or available balance match the filter expression
get_totals(i_balances[]) Returns the sums of balance and credit limit of the listed entities, grouped by commodity
set_credit_limit(i_balance, new_credit_limit) Sets a new credit limit