Display of Balance

The softphone supports a displaying of the account balance.

Below screenshot demonstrates an example (balance is 2.79).

 

Display of Balance

 

The balance is received from the server. There are two possible methods of retreiving a balance from the server:

  1. HTTP request
  2. Parse SIP header (preferred method)

 

1. HTTP request

The softpone makes a request to a billing server via HTTP protocol (see below diagram).

Request Balance via HTTP


The softphone sends HTTP GET request to a Web server. It requests a web-page with URL like:
http://www.miaphone.net/balance.php?login=1234&password=5678, where 1234 and 5678 are user's login and password correspondingly.

Web server returns a simple web-page with a balance amount inside.
Returned web-page is parsed by softphone and a numeric value is displayed to the user (like on first screen-shot).

In above example, a web-script balance.php is executed on the server side. This script receives a login/password pair as a parameter and does a request to the local billing database.

Note, password may be encrypted with MD5 algorithm, so, it is not sent in open text. For example, password 5678 will be encrypted as 674f3c2c1a8a6f90461e8a66fb5550ba. The server should use the same algorithm to check a password validity.

Below is a sample balance.php script, which connects to MySQL database, executes SQL query and returns web-page with balance value inside.
You can use this sample script as a starting point for creating your own. First of all, you should change value of variables $db_host, $db_user, $db_password, $database, and modify SQL query (variable $query) in accordance with your database structure.

 

<HTML> 
<HEAD> </HEAD>
<BODY>

<?php

$login = $_GET['login'];
$password = $_GET['password'];

$db_host="localhost";
$db_user="username";
$db_password="password";
$database="database";


// Connecting, selecting database
$link = mysql_connect($db_host, $db_user, $db_password)
    or die('Could not connect: ' . mysql_error());

mysql_select_db($database) or die('Could not select database');

// Performing SQL query
$query = "SELECT balance FROM users WHERE login='$login' AND password='$password'";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
if($row = mysql_fetch_row($result))
  echo "\nBalance: " . $row[0] . "\n";
else
  echo "\nBalance: 0.0\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?> 

</BODY>
</HTML>


The format of URL, which is used by softphone, is flexible. It is possible to configure softphone to any format, for example:
http://www.miaphone.net/balance.php?login=1234&password=5678
or
http://www.miaphone.net/billing/bal.pl?login=1234&password=5678
or
http://www.miaphone.net/billing.php?account=1234&pwd=5678

URL for balance script is configured inside installation script (installer-brand.nsi).

 

2. Parse SIP headers

Some SIP softswitches support a sending of balance value inside SIP headers, for example PortaBilling.

The balance is encoded inside SIP response message to REGISTER and INVITE requests, for example:

SIP/2.0 200 OK
CSeq: 2 REGISTER
From: ...
To: ...
Balance-amount: 10.25

In above example, SIP message contains a custom header "Balance-amount", which is added by billing system. It has value 10.25

This header is parsed by softphone and the balance is displayed on the main application window.

 

The header name (in above example it is "Balance-amount") is configured inside configuration file installer-brand.nsi.

 

Comments (0)