Web Services Code Samples
1. Generality
1.1. Introduction
1.2. Generating a valid AuthenticationToken
1.3. Additional purchase Information
1.3.1. When is it required
1.3.2. The PurchaseInfo complex type
1.3.3. How to validate the purchase info
1.4. Payment
1.4.1. The balance checker
1.5. Testing your implementation
2. Java
2.1. Requirements
2.2. Using Voxbone API
2.2.1. Retrieving countries list
2.2.2. Retrieving area code
2.2.3. Buying a DID
2.2.4. Buying a DID by product ID
2.2.5. Mapping a DID
2.2.6. Retrieving cities information
2.2.7. Testing purchase information validity
2.2.8. Retrieving DIDs information
2.2.9. Cancelling a DID
2.2.10. Retrieving your account balance
3. PHP
3.1. Using PHP 4.x
3.1.1. Requirements
3.1.2. Code Samples
3.1.2.1. Retrieving countries list
3.1.2.2. Retrieving area code
3.1.2.3. Buying a DID
3.1.2.4. Buying a DID by product ID
3.1.2.5. Setting the PurchaseInfo
3.1.2.6. Mapping a DID
3.1.2.7. Retrieving cities information
3.1.2.8. Testing purchase information validity
3.1.2.9. Retrieving DIDs information
3.1.2.10. Cancelling a DID
3.1.2.11. Retrieving your account balance
3.2. Using PHP 5.x
3.2.1. Requirements
3.2.2. Code Samples
3.2.2.1. Create the AuthenticationToken
3.2.2.2. Retrieving countries list
3.2.2.3. Retrieving area code
3.2.2.4. Buying a DID
3.2.2.5. Buying a DID by product ID
3.2.2.6. Setting the PurchaseInfo
3.2.2.7. Mapping a DID
3.2.2.8. Retrieving cities information
3.2.2.9. Testing purchase information validity
3.2.2.10. Retrieving DIDs information
3.2.2.11. Cancelling a DID
3.2.2.12. Retrieving your account balance
1.1 Introduction [up]
The Voxbone web service WSDL can be found here: http://www.voxbone.com/ws/services/VoxService?wsdl
We have already successfully tested the web service using Java, PHP and Perl.
For Java and PHP you will find instructions below.
For Perl and C#, the documentation and SDK's will soon be available.
For more information, please send a mail to support-dev@voxbone.com
1.2. Generating a valid AuthenticationToken [up]
An AuthenticationToken is a container used to authenticate a user within the web service.
The AuthenticationToken is composed by 3 values.
hash is encoded in Hex
where the definition of the key is:
key = YYYY-MM-DD HH:MM:ss:user_defined_value
and where:
Note that the key can only be used one time.
If you try to use the same key for a second web service call, an exception will be thrown.
An exception will also be thrown if the key you provided isn't valid.
A key can be invalidated for the following reason:
1.3. Additional Purchase Info [up]
The purchaseInfo is a container that allow you to send information about the customer that is purchasing a DID.
This is required by the following countries in order to activate the DID:
If the information aren't validated, the DID won't be activated.
Note that some country may use special character set to encode their cities name (as for germany).
The API is using UTF-8 encoding in order to prevent erroneous characters.
1.3.1. When is it required [up]
You can determine if the purchase info is required or not with the getAreaCodeForCountry method.
When invoking this method, it return a "needPurchaseInfo" parameter.
If the parameter is at true, then you will have to provide purchase information when buying a DID from this area. If the parameter is at false, then you can freely buy the DID without specifying additional info.
1.3.2. The PurchaseInfo complex type [up]
Here is an XML sample of what should a purchase info look like:
<purchaseInfo>
<city>Oberschleißheim</city>
<company>voxbone</company>
<country_code_a2>DE</country_code_a2>
<firstname>firstname</firstname>
<lastname>lastname</lastname>
<salutation>MR</salutation>
<street>a street</street>
<zip>85759</zip>
</purchaseInfo>A list of valid cities and their associated zip code can be retrieved from the API using the getCitiesInfo method.
Note that some countries may use different character set.
To prevent erroneous characters the API is using UTF-8 encoding in order .
Please use UTF-8 encoding when setting the purchase information or reading information from the getCitiesInfo method.
salutation should be in the following list :
Note that the salutation can be indifferently in upper or lower case.
1.3.3. How to validate the purchase info [up]
You can try to validate purchase information of a defined product before buying it using the "isPurchaseInfoValid" method.
This method will return a string that will determine the status of the validation
There's 3 differents case:
1.4. Payment [up]
The payments of all your operations are based on your Voxbone prepaid account.
You can check your account status from the Business Account page.
If you don't have enough money on your account to pay the order, you will receive a "Payment Error" soap message.
1.4.1. The balance checker [up]
The balance checker is a usefull tools that warn you when your account's balance is getting low.
This will send you an email to the address of your choice when your prepaid account reach the setted Thresold.
You can enable / disable the balance checker from our website at the following url : http://www.voxbone.com/members/accountBalanceChecker.jsf
Note that the balance checker won't warn you if you go below the specified thresold by manually buy DID from the website.
1.5. Testing your implementation [up]
In order to test your implementation without taking the risk of buying DID, you can use the Sandbox.
The sandbox is a dedicated server on which a copy of the web service run.
Within the sandbox, you can add/remove virtual funds to your account and safely test the buying methods.
To use the sandbox, go on http://sandbox.voxbone.com and create an account.
Note that older voxbone account were already copyied to the sandbox.
The WSDL of the sandbox can be found here: http://sandbox.voxbone.com/ws/services/VoxService?WSDL
The recommended way to invoke our web services is to use the Java Voxbone SDK we provide here: Voxbone SDK
You can also download the source code of the Voxbone SDK from:
http://www.voxbone.com/resources/ws/voxbone-sdk-src.zip
2.1. Requirements [up]
Using the Voxbone SDK requires the libraries (.jar) listed below:
Details on projects and links to download:
Now add the Voxbone SDK ( voxbone-sdk.jar ) in your project classpath and follow the code samples below.
2.2. Code sample using Voxbone API [up]
2.2.1. Retrieving countries list [up]
The following code sample shows you how to retrieve the countries in which Voxbone provides DIDs.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.Country;
public class TestGetCountriesList {
public static void main( String args[] ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
try {
Country[] countries = client.getCountriesList(token);
for( Country country : countries ){
System.out.println(country.getCountryCodeA2()+" "
+country.getCountryName()+" "
+country.getAvailableDidsCount());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}All prices are expressed in cents. The currency is the same as the currency configured in your Voxbone account.
2.2.2. Retrieving area code [up]
The following code sample shows how to retrieve the area codes we offer for a given country.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.AreaCode;
public class TestGetAreaCodeForCountry {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
String country_code_a2 = "BE";
try {
AreaCode[] areas = client.getAreaCodeForCountry(token,country_code_a2);
for( AreaCode area : areas ){
System.out.println(area.getAreaCode()+" "
+area.getCityName()+" "
+area.getAvailableDidCount() );
}
} catch (Exception e) {
e.printStackTrace();
}
}
}"BE" is the country_code_A2 for Belgium (also known as Country ISO code ), and can be obtained from the Country container.
Note that an exception will be thrown if the specified country_code_A2 doesn't exist, or if the country it refers to isn't offered by the Web Service.
2.2.3. Buying a DID [up]
The following code sample shows how to buy a DID.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.DID;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.Order;
public class TestBuyDIDs {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
DID[] dids = null;
/**
* Setting the customers inforations.
* This is needed to activate DID in some country.
* If this is not set and not validated the DID won't be activated
*/
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("BE");
info.setStreet("Avenue Louise");
info.setZip("1050");
int countryPhoneCode = 32;
int identifier = 59;
int quantity = 1;
String areaCode = "2";
String defaultURI = "test@fwd.pulver.com";
try {
Order order =
client.buyDIDs(token,areaCode,countryPhoneCode,identifier,quantity,defaultURI,info );
dids = order.getDIDList().getDID();
System.out.println("order reference: "+order.getOrder_reference());
if( dids == null )
{
System.out.println("DIDs IS NULL");
return;
}
for( DID d : dids ){
System.out.println(d.getDidFormatted()+" "
+d.getCountryName()+" "
+d.getCityName() );
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.4. Buying a DID by product ID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.Order;
import voxbone.webservices.clients.generated.DID;
public class TestBuyDIDsByProductID {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
int productID = 57;
int quantity = 1;
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("DE");
info.setStreet("Avenue Louise");
info.setZip("1050");
try {
Order order= client.buyDIDsByProductID(token,productID,quantity,"test@test.com", info );
System.out.println("Order Reference : "+order.getOrder_reference());
for( DID did : order.getDIDList().getDID() ){
System.out.println("didFormatted : "+did.getDidFormatted());
System.out.println("city : "+did.getCityName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.5. Mapping a DID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
public class TestMapDIDToURI {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
String didFormatted = "32127470313";
String URI = "test@fwd.pulver.com";
try {
boolean result = client.mapDIDToURI(token,didFormatted,URI);
if( result ){
System.out.println("DID successfully mapped");
} else {
System.out.println("Mapping failed");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.6. Retrieving cities information [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.CityInfo;
public class TestGetCitiesInfo {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
try {
CityInfo[] citiesInfo = client.getCitiesInfo(token,"DE","30");
for( CityInfo cityInfo : citiesInfo ){
System.out.println(cityInfo.getName());
for(String zip : cityInfo.getZip().getString() ){
System.out.println(zip);
}
System.out.println("\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.7. Testing purchase information validity [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.PurchaseInfoValidationStatus;
public class TestIsPurchaseInfoValid {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
int productID = 1;
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("BE");
info.setStreet("Avenue Louise");
info.setZip("1050");
try{
PurchaseInfoValidationStatus isValid = client.isPurchaseInfoValid(token,productID,info);
if( isValid == PurchaseInfoValidationStatus.VALID )
System.out.println("info are valid");
else if( isValid == PurchaseInfoValidationStatus.INVALID )
System.out.println("invalid information");
else if( isValid == PurchaseInfoValidationStatus.NO_VALIDATION_REQUIRED )
System.out.println("no validation required");
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.8. Retrieving DIDs information [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.Filter;
import voxbone.webservices.clients.generated.DID;
public class TestGetDIDsInfo {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
TokenFactory factory = TokenFactory.getInstance("your_login","your_password");
try{
/**
* Specifying a blank new Filter will allow you to retrieve information about
* ALL your DIDs
* use it carefully if you own several DIDs
*/
AuthenticationToken token = factory.generateToken("123123456789");
System.out.println("NO FILTER");
DID[] didsInfo = client.getDIDsInfo(token, new Filter());
for( DID did : didsInfo ){
System.out.println("formatted: "+did.getDidFormatted());
System.out.println("current mapping: "+did.getCurrentMapping());
}
/**
* You can filter the DID returned on the DID number
* Or/And on the DID URI
*
* The following exemple will return ALL DID number containing 55
* And mapped to test@test.com
*/
System.out.println("FILTERED RESULT");
Filter filter = new Filter();
filter.setDidPattern("55");
filter.setUri("test@test.com");
token = factory.generateToken("567123456987");
didsInfo = client.getDIDsInfo(token, filter);
for( DID did : didsInfo ){
System.out.println("formatted: "+did.getDidFormatted());
System.out.println("current mapping: "+did.getCurrentMapping());
}
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.9. Cancelling a DID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
public class TestCancelDID {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
try{
boolean hasbeenCanceled = client.cancelDID(token,"3202123234565");
System.out.println("canceled: "+hasbeenCanceled);
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.10. Retrieving your account balance [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.AccountBalance;
public class TestGetAccountBalance {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login", "your_password").generateToken("1231234567");
try{
AccountBalance balance = client.getAccountBalance(token);
System.out.println("account balance: "+balance.getBalance());
System.out.println("balance threshold: "+balance.getThreshold());
System.out.println("currency: "+balance.getCurrency());
}catch( Exception e ){
e.printStackTrace();
}
}
}
3.1. Using PHP 4.x [up]
3.1. Requirements [up]
this PHP tutorial on how to use our web services with PHP4.x use an extension named NuSOAP.
you can download it from: http://sourceforge.net/projects/nusoap
Unpack it and drop the lib folder in your web project directory then import the needed PHP classes.
Addtionnal information about NuSOAP can be found at: http://dietrich.ganx4.com/nusoap/
3.1.2. Code Samples [up]
3.1.2.1. Retrieving countries list [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params =
'<tns:getCountriesList xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'</tns:getCountriesList>';
$result = $client->call('getCountriesList', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.2. Retrieving area code [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$country_code_a2 = "BE";
$params =
'<tns:getAreaCodeForCountry xmlns:tns="http://www.voxbone.com/VoxService" '
.'xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:country_code_a2>'.$country_code_a2.'</tns:country_code_a2>'
.'</tns:getAreaCodeForCountry>';
$result = $client->call('getAreaCodeForCountry', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.3. Buying a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params =
'<tns:buyDIDs xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:countryPhoneCode>45</tns:countryPhoneCode>'
.'<tns:areaCode></tns:areaCode>'
.'<tns:areaCodeIdentifier>1</tns:areaCodeIdentifier>'
.'<tns:quantity>1</tns:quantity>'
.'<tns:defaultURI>"test@voxbone.com"</tns:defaultURI>'
.'<tns:purchaseInfo/>'
.'</tns:buyDIDs>';
$result = $client->call('buyDIDs', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.4. Buying a DID by products ID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:buyDIDsByProductsID xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:productIdentifier>1</tns:productIdentifier>'
.'<tns:quantity>1</tns:quantity>'
.'<tns:defaultURI>"echo@213.246.227.67"</tns:defaultURI>'
.'<tns:purchaseInfo/>'
.'</tns:buyDIDsByProductsID>';
$result = $client->call('buyDIDsByProductsID', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.5. Setting the PurchaseInfo [up]
In order to specify the PurchaseInfo when buying a DID, replace:
<purchaseInfo/>With:
<tns:purchaseInfo>
<ns1:city>Gerbrunn</ns1:city>
<ns1:company>voxbone</ns1:company>
<ns1:country_code_a2>DE</ns1:country_code_a2>
<ns1:firstname>firstname</ns1:firstname>
<ns1:lastname>lastname</ns1:lastname>
<ns1:salutation>MR</ns1:salutation>
<ns1:street>a street</ns1:street>
<ns1:zip>97216</ns1:zip>
</tns:purchaseInfo>
3.1.2.6. Mapping a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$did_ formatted = "#0321#37470321";
$URI = "test@fwd.pulver.com";
$params =
'<tns:mapDIDToURI xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:DIDNumberFormatted>'.$did_ formatted.'</tns:DIDNumberFormatted>'
.'<tns:URI>'.$URI.'</tns:URI>'
.'</tns:mapDIDToURI>';
$result = $client->call('mapDIDToURI', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.7. Retrieving cities information [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getCitiesInfo xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:country_code_a2>DE</tns:country_code_a2>'
.'<tns:areaCode>30</tns:areaCode>'
.'</tns:getCitiesInfo>';
$result = $client->call('getCitiesInfo', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.8. Testing purchase information validity [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:isPurchaseInfoValid xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:productIdentifier>1014</tns:productIdentifier>'
.'<tns:purchaseInfo>'
.'<ns1:city>Gerbrunn</ns1:city>'
.'<ns1:company>voxbone</ns1:company>'
.'<ns1:country_code_a2>DE</ns1:country_code_a2>'
.'<ns1:firstname>firstname</ns1:firstname>'
.'<ns1:lastname>lastname</ns1:lastname>'
.'<ns1:salutation>MR</ns1:salutation>'
.'<ns1:street>a street</ns1:street>'
.'<ns1:zip>97216</ns1:zip>'
.'</tns:purchaseInfo>'
.'</tns:isPurchaseInfoValid>';
$result = $client->call('isPurchaseInfoValid', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.9. Retrieving DIDs information [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getDIDsInfo xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'<tns:Filters>'
.'<ns1:didPattern>4577345790</ns1:didPattern>'
.'</tns:Filters>'
.'</tns:getDIDsInfo>';
$result = $client->call('getDIDsInfo', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.10. Cancelling a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:cancelDID xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'<tns:DIDNumberFormatted>551135237755</tns:DIDNumberFormatted>'
.'</tns:cancelDID>';
$result = $client->call('cancelDID', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.10. Cancelling a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "francois";
$password = "frans";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getAccountBalance xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'</tns:getAccountBalance>';
$result = $client->call('getAccountBalance', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.2. Using PHP 5.x
3.2.1. Requirements [up]
This PHP tutorial on how to use our web services use the PHP5 soap extension.
You can find more informations about the soap extension on the following urls:
3.2.2. Code Samples [up]
3.2.2.1. Create the AuthenticationToken [up]
The following code sample shows you how to create an AuthenticationToken using SHA1 (Secure Hash Algorithm)
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( "your_password".$date );
$token = array( "login" =>"your_login","hash"=>$hash,"key"=>$date);As the PHP date function don't generate the milisecond, we add ":123" to the date.
Note that 123 is an example and that you can add whatever you want unless it's a valid time.
3.2.2.2. Retrieving countries list [up]
The following code sample shows you how to retrieve the countries in which Voxbone provides DIDs.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token );
$result = $client->getCountriesList($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>All prices are expressed in cents. The currency is the same as the currency configured in your Voxbone account.
3.2.2.3. Retrieving area code [up]
The following code sample shows how to retrieve the area codes we offer for a given country.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token,
"country_code_a2"=>"DK");
$result = $client->getAreaCodeForCountry($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>"BE" is the country_code_A2 for Belgium (also known as Country ISO code ), and can be obtained from the Country container.
Note that an exception will be thrown if the specified country_code_A2 doesn't exist, or if the country it refers to isn't offered by the Web Service.
3.2.2.4. Buying a DID [up]
The following code sample shows how to buy a DID.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$purchaseInfo = "";
$param = array( "AuthenticationToken" => $token,
"countryPhoneCode"=>1,
"areaCode"=>613,
"areaCodeIdentifier"=>10,
"quantity"=>2,
"defaultURI"=>"test@voxbone.com",
"purchaseInfo"=> $purchaseInfo
);
$result = $client->buyDIDs($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.5. Buying a DID by product ID [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$purchaseInfo = "";
$param = array( "AuthenticationToken" => $token,
"productIdentifier"=>1,
"quantity"=>1,
"defaultURI"=>"test@test.com",
"purchaseInfo"=> $purchaseInfo
);
$result = $client->buyDIDsByProductsID($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.6. Setting the PurchaseInfo [up]
In order to specify the PurchaseInfo when buying a DID, replace:
$purchaseInfo = "";With :
3.2.2.7. Mapping a DID [up]
The following code sample shows you how to map a DID to an URI.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$didFormatted = "3237470319";
$param = array( "AuthenticationToken" => $token,
"DIDNumberFormatted"=>$didFormatted,
"URI"=>"test@voxbone.com");
$client->mapDIDToURI($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.8. Retrieving cities information [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1,"encoding"=>"UTF-8"));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$country_code_a2 = "DE";
$area_code = 30;
$param = array( "AuthenticationToken" => $token,
"country_code_a2"=>$country_code_a2,
"areaCode"=>$area_code
);
$result = $client->getCitiesInfo($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo( "<br/><br/>" );
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.9. Testing purchase information validity [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1,"encoding"=>"UTF-8"));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$productID = 59;
$city = utf8_encode("Gräfelfing");
$purchaseInfo = array( "city"=>$city,
"company"=>"Voxbone",
"country_code_a2"=>"DE",
"firstname"=>"Vincent",
"lastname"=>"Morsiani",
"salutation"=>"MR",
"street"=>"testing street",
"zip"=>82156
);
$param = array( "AuthenticationToken" => $token,
"productIdentifier"=>$productID,
"purchaseInfo"=>$purchaseInfo
);
$result = $client->isPurchaseInfoValid($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br><br>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?> 3.2.2.10. Retrieving DIDs information
3.2.2.11. Cancelling a DID
3.2.2.12. Retrieving your account balance
3.2.2.10. Retrieving DIDs information [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$filter = array("didPattern" =>"5532", "uri"=>"test@test.com");
$param = array( "AuthenticationToken" => $token,
"Filters" => $filter
);
$client->getDIDsInfo($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.11. Cancelling a DID [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token,
"DIDNumberFormatted" => "551133015382"
);
$client->cancelDID($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.12. Retrieving your account balance [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token
);
$client->getAccountBalance($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
1.1. Introduction
1.2. Generating a valid AuthenticationToken
1.3. Additional purchase Information
1.3.1. When is it required
1.3.2. The PurchaseInfo complex type
1.3.3. How to validate the purchase info
1.4. Payment
1.4.1. The balance checker
1.5. Testing your implementation
2. Java
2.1. Requirements
2.2. Using Voxbone API
2.2.1. Retrieving countries list
2.2.2. Retrieving area code
2.2.3. Buying a DID
2.2.4. Buying a DID by product ID
2.2.5. Mapping a DID
2.2.6. Retrieving cities information
2.2.7. Testing purchase information validity
2.2.8. Retrieving DIDs information
2.2.9. Cancelling a DID
2.2.10. Retrieving your account balance
3. PHP
3.1. Using PHP 4.x
3.1.1. Requirements
3.1.2. Code Samples
3.1.2.1. Retrieving countries list
3.1.2.2. Retrieving area code
3.1.2.3. Buying a DID
3.1.2.4. Buying a DID by product ID
3.1.2.5. Setting the PurchaseInfo
3.1.2.6. Mapping a DID
3.1.2.7. Retrieving cities information
3.1.2.8. Testing purchase information validity
3.1.2.9. Retrieving DIDs information
3.1.2.10. Cancelling a DID
3.1.2.11. Retrieving your account balance
3.2. Using PHP 5.x
3.2.1. Requirements
3.2.2. Code Samples
3.2.2.1. Create the AuthenticationToken
3.2.2.2. Retrieving countries list
3.2.2.3. Retrieving area code
3.2.2.4. Buying a DID
3.2.2.5. Buying a DID by product ID
3.2.2.6. Setting the PurchaseInfo
3.2.2.7. Mapping a DID
3.2.2.8. Retrieving cities information
3.2.2.9. Testing purchase information validity
3.2.2.10. Retrieving DIDs information
3.2.2.11. Cancelling a DID
3.2.2.12. Retrieving your account balance
1.1 Introduction [up]
The Voxbone web service WSDL can be found here: http://www.voxbone.com/ws/services/VoxService?wsdl
We have already successfully tested the web service using Java, PHP and Perl.
For Java and PHP you will find instructions below.
For Perl and C#, the documentation and SDK's will soon be available.
For more information, please send a mail to support-dev@voxbone.com
1.2. Generating a valid AuthenticationToken [up]
An AuthenticationToken is a container used to authenticate a user within the web service.
The AuthenticationToken is composed by 3 values.
1. your loginhash = SHA1( your_password + key )
2. a hash code
3. a key
hash is encoded in Hex
where the definition of the key is:
key = YYYY-MM-DD HH:MM:ss:user_defined_value
and where:
- YYYY : year with 4 digits.
- MM : month with 2 digits.
- DD : day in month with 2 digits.
- HH : hours. (00H-23H)
- MM : minutes
- ss : seconds.
- user_defined_Value : your unique reference of 12 characters long
Note that the key can only be used one time.
If you try to use the same key for a second web service call, an exception will be thrown.
An exception will also be thrown if the key you provided isn't valid.
A key can be invalidated for the following reason:
- It doesn't contain the date in the described format.
- It isn't 32 characters long.
- The date provided is more than 7 days old.
1.3. Additional Purchase Info [up]
The purchaseInfo is a container that allow you to send information about the customer that is purchasing a DID.
This is required by the following countries in order to activate the DID:
- Germany
- Italy (soon)
If the information aren't validated, the DID won't be activated.
Note that some country may use special character set to encode their cities name (as for germany).
The API is using UTF-8 encoding in order to prevent erroneous characters.
1.3.1. When is it required [up]
You can determine if the purchase info is required or not with the getAreaCodeForCountry method.
When invoking this method, it return a "needPurchaseInfo" parameter.
If the parameter is at true, then you will have to provide purchase information when buying a DID from this area. If the parameter is at false, then you can freely buy the DID without specifying additional info.
1.3.2. The PurchaseInfo complex type [up]
Here is an XML sample of what should a purchase info look like:
<purchaseInfo>
<city>Oberschleißheim</city>
<company>voxbone</company>
<country_code_a2>DE</country_code_a2>
<firstname>firstname</firstname>
<lastname>lastname</lastname>
<salutation>MR</salutation>
<street>a street</street>
<zip>85759</zip>
</purchaseInfo>
Note that some countries may use different character set.
To prevent erroneous characters the API is using UTF-8 encoding in order .
Please use UTF-8 encoding when setting the purchase information or reading information from the getCitiesInfo method.
salutation should be in the following list :
If the salutation you specified isn't in the list above, an exception will be thrown.
- MR
- MS
- COMPANY
Note that the salutation can be indifferently in upper or lower case.
1.3.3. How to validate the purchase info [up]
You can try to validate purchase information of a defined product before buying it using the "isPurchaseInfoValid" method.
This method will return a string that will determine the status of the validation
There's 3 differents case:
- VALID : the provided purchase info are valid.
- INVALID : the provided purchase info are invalid.
- NO_VALIDATION_REQUIRED : The specified product doesn't require purchase info validation to be bought
1.4. Payment [up]
The payments of all your operations are based on your Voxbone prepaid account.
You can check your account status from the Business Account page.
If you don't have enough money on your account to pay the order, you will receive a "Payment Error" soap message.
1.4.1. The balance checker [up]
The balance checker is a usefull tools that warn you when your account's balance is getting low.
This will send you an email to the address of your choice when your prepaid account reach the setted Thresold.
You can enable / disable the balance checker from our website at the following url : http://www.voxbone.com/members/accountBalanceChecker.jsf
Note that the balance checker won't warn you if you go below the specified thresold by manually buy DID from the website.
1.5. Testing your implementation [up]
In order to test your implementation without taking the risk of buying DID, you can use the Sandbox.
The sandbox is a dedicated server on which a copy of the web service run.
Within the sandbox, you can add/remove virtual funds to your account and safely test the buying methods.
To use the sandbox, go on http://sandbox.voxbone.com and create an account.
Note that older voxbone account were already copyied to the sandbox.
The WSDL of the sandbox can be found here: http://sandbox.voxbone.com/ws/services/VoxService?WSDL
The recommended way to invoke our web services is to use the Java Voxbone SDK we provide here: Voxbone SDK
You can also download the source code of the Voxbone SDK from:
http://www.voxbone.com/resources/ws/voxbone-sdk-src.zip
2.1. Requirements [up]
Using the Voxbone SDK requires the libraries (.jar) listed below:
- activation.jar
- FastInfoset.jar
- jaxrpc-api.jar
- jaxrpc-impl.jar
- jaxrpc-spi.jar
- jsr173_api.jar
- mail.jar
- saaj-api.jar
- saaj-impl.jar
Details on projects and links to download:
http://java.sun.com/webservices/jwsdp/index.jsp for:
- FastInfoset.jar
- jaxrpc-api.jar
- jaxrpc-impl.jar
- jaxrpc-spi.jar
- jsr173_api.jar
- saaj-api.jar
- saaj-impl.jar
http://java.sun.com/products/javabeans/glasgow/jaf.html for:
- activation.jar
http://java.sun.com/products/javamail/ for:
- mail.jar
Now add the Voxbone SDK ( voxbone-sdk.jar ) in your project classpath and follow the code samples below.
2.2. Code sample using Voxbone API [up]
2.2.1. Retrieving countries list [up]
The following code sample shows you how to retrieve the countries in which Voxbone provides DIDs.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.Country;
public class TestGetCountriesList {
public static void main( String args[] ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
try {
Country[] countries = client.getCountriesList(token);
for( Country country : countries ){
System.out.println(country.getCountryCodeA2()+" "
+country.getCountryName()+" "
+country.getAvailableDidsCount());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.2. Retrieving area code [up]
The following code sample shows how to retrieve the area codes we offer for a given country.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.AreaCode;
public class TestGetAreaCodeForCountry {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
String country_code_a2 = "BE";
try {
AreaCode[] areas = client.getAreaCodeForCountry(token,country_code_a2);
for( AreaCode area : areas ){
System.out.println(area.getAreaCode()+" "
+area.getCityName()+" "
+area.getAvailableDidCount() );
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Note that an exception will be thrown if the specified country_code_A2 doesn't exist, or if the country it refers to isn't offered by the Web Service.
2.2.3. Buying a DID [up]
The following code sample shows how to buy a DID.
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.DID;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.Order;
public class TestBuyDIDs {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
DID[] dids = null;
/**
* Setting the customers inforations.
* This is needed to activate DID in some country.
* If this is not set and not validated the DID won't be activated
*/
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("BE");
info.setStreet("Avenue Louise");
info.setZip("1050");
int countryPhoneCode = 32;
int identifier = 59;
int quantity = 1;
String areaCode = "2";
String defaultURI = "test@fwd.pulver.com";
try {
Order order =
client.buyDIDs(token,areaCode,countryPhoneCode,identifier,quantity,defaultURI,info );
dids = order.getDIDList().getDID();
System.out.println("order reference: "+order.getOrder_reference());
if( dids == null )
{
System.out.println("DIDs IS NULL");
return;
}
for( DID d : dids ){
System.out.println(d.getDidFormatted()+" "
+d.getCountryName()+" "
+d.getCityName() );
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.4. Buying a DID by product ID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.Order;
import voxbone.webservices.clients.generated.DID;
public class TestBuyDIDsByProductID {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
int productID = 57;
int quantity = 1;
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("DE");
info.setStreet("Avenue Louise");
info.setZip("1050");
try {
Order order= client.buyDIDsByProductID(token,productID,quantity,"test@test.com", info );
System.out.println("Order Reference : "+order.getOrder_reference());
for( DID did : order.getDIDList().getDID() ){
System.out.println("didFormatted : "+did.getDidFormatted());
System.out.println("city : "+did.getCityName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.5. Mapping a DID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
public class TestMapDIDToURI {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token =
TokenFactory.getInstance("login","password").generateToken("123123456789");
String didFormatted = "32127470313";
String URI = "test@fwd.pulver.com";
try {
boolean result = client.mapDIDToURI(token,didFormatted,URI);
if( result ){
System.out.println("DID successfully mapped");
} else {
System.out.println("Mapping failed");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.6. Retrieving cities information [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.CityInfo;
public class TestGetCitiesInfo {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
try {
CityInfo[] citiesInfo = client.getCitiesInfo(token,"DE","30");
for( CityInfo cityInfo : citiesInfo ){
System.out.println(cityInfo.getName());
for(String zip : cityInfo.getZip().getString() ){
System.out.println(zip);
}
System.out.println("\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.7. Testing purchase information validity [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.PurchaseInfo;
import voxbone.webservices.clients.generated.PurchaseInfoValidationStatus;
public class TestIsPurchaseInfoValid {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
int productID = 1;
PurchaseInfo info = new PurchaseInfo();
info.setCity("Brussels");
info.setCompany("Voxbone");
info.setFirstname("Vincent");
info.setLastname("Morsiani");
info.setSalutation("MR");
info.setCountry_code_a2("BE");
info.setStreet("Avenue Louise");
info.setZip("1050");
try{
PurchaseInfoValidationStatus isValid = client.isPurchaseInfoValid(token,productID,info);
if( isValid == PurchaseInfoValidationStatus.VALID )
System.out.println("info are valid");
else if( isValid == PurchaseInfoValidationStatus.INVALID )
System.out.println("invalid information");
else if( isValid == PurchaseInfoValidationStatus.NO_VALIDATION_REQUIRED )
System.out.println("no validation required");
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.8. Retrieving DIDs information [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.Filter;
import voxbone.webservices.clients.generated.DID;
public class TestGetDIDsInfo {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
TokenFactory factory = TokenFactory.getInstance("your_login","your_password");
try{
/**
* Specifying a blank new Filter will allow you to retrieve information about
* ALL your DIDs
* use it carefully if you own several DIDs
*/
AuthenticationToken token = factory.generateToken("123123456789");
System.out.println("NO FILTER");
DID[] didsInfo = client.getDIDsInfo(token, new Filter());
for( DID did : didsInfo ){
System.out.println("formatted: "+did.getDidFormatted());
System.out.println("current mapping: "+did.getCurrentMapping());
}
/**
* You can filter the DID returned on the DID number
* Or/And on the DID URI
*
* The following exemple will return ALL DID number containing 55
* And mapped to test@test.com
*/
System.out.println("FILTERED RESULT");
Filter filter = new Filter();
filter.setDidPattern("55");
filter.setUri("test@test.com");
token = factory.generateToken("567123456987");
didsInfo = client.getDIDsInfo(token, filter);
for( DID did : didsInfo ){
System.out.println("formatted: "+did.getDidFormatted());
System.out.println("current mapping: "+did.getCurrentMapping());
}
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.9. Cancelling a DID [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
public class TestCancelDID {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login","your_password").generateToken("123123456789");
try{
boolean hasbeenCanceled = client.cancelDID(token,"3202123234565");
System.out.println("canceled: "+hasbeenCanceled);
} catch( Exception e ){
e.printStackTrace();
}
}
}
2.2.10. Retrieving your account balance [up]
import voxbone.webservices.clients.VoxClient;
import voxbone.webservices.clients.security.TokenFactory;
import voxbone.webservices.clients.generated.AuthenticationToken;
import voxbone.webservices.clients.generated.AccountBalance;
public class TestGetAccountBalance {
public static void main( String[] args ){
VoxClient client = VoxClient.getInstance();
AuthenticationToken token = TokenFactory.getInstance("your_login", "your_password").generateToken("1231234567");
try{
AccountBalance balance = client.getAccountBalance(token);
System.out.println("account balance: "+balance.getBalance());
System.out.println("balance threshold: "+balance.getThreshold());
System.out.println("currency: "+balance.getCurrency());
}catch( Exception e ){
e.printStackTrace();
}
}
}
3.1. Using PHP 4.x [up]
3.1. Requirements [up]
this PHP tutorial on how to use our web services with PHP4.x use an extension named NuSOAP.
you can download it from: http://sourceforge.net/projects/nusoap
Unpack it and drop the lib folder in your web project directory then import the needed PHP classes.
Addtionnal information about NuSOAP can be found at: http://dietrich.ganx4.com/nusoap/
3.1.2. Code Samples [up]
3.1.2.1. Retrieving countries list [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params =
'<tns:getCountriesList xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'</tns:getCountriesList>';
$result = $client->call('getCountriesList', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.2. Retrieving area code [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$country_code_a2 = "BE";
$params =
'<tns:getAreaCodeForCountry xmlns:tns="http://www.voxbone.com/VoxService" '
.'xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:country_code_a2>'.$country_code_a2.'</tns:country_code_a2>'
.'</tns:getAreaCodeForCountry>';
$result = $client->call('getAreaCodeForCountry', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.3. Buying a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params =
'<tns:buyDIDs xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:countryPhoneCode>45</tns:countryPhoneCode>'
.'<tns:areaCode></tns:areaCode>'
.'<tns:areaCodeIdentifier>1</tns:areaCodeIdentifier>'
.'<tns:quantity>1</tns:quantity>'
.'<tns:defaultURI>"test@voxbone.com"</tns:defaultURI>'
.'<tns:purchaseInfo/>'
.'</tns:buyDIDs>';
$result = $client->call('buyDIDs', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.4. Buying a DID by products ID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:buyDIDsByProductsID xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:productIdentifier>1</tns:productIdentifier>'
.'<tns:quantity>1</tns:quantity>'
.'<tns:defaultURI>"echo@213.246.227.67"</tns:defaultURI>'
.'<tns:purchaseInfo/>'
.'</tns:buyDIDsByProductsID>';
$result = $client->call('buyDIDsByProductsID', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.5. Setting the PurchaseInfo [up]
In order to specify the PurchaseInfo when buying a DID, replace:
<purchaseInfo/>
<tns:purchaseInfo>
<ns1:city>Gerbrunn</ns1:city>
<ns1:company>voxbone</ns1:company>
<ns1:country_code_a2>DE</ns1:country_code_a2>
<ns1:firstname>firstname</ns1:firstname>
<ns1:lastname>lastname</ns1:lastname>
<ns1:salutation>MR</ns1:salutation>
<ns1:street>a street</ns1:street>
<ns1:zip>97216</ns1:zip>
</tns:purchaseInfo>
3.1.2.6. Mapping a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$did_ formatted = "#0321#37470321";
$URI = "test@fwd.pulver.com";
$params =
'<tns:mapDIDToURI xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:DIDNumberFormatted>'.$did_ formatted.'</tns:DIDNumberFormatted>'
.'<tns:URI>'.$URI.'</tns:URI>'
.'</tns:mapDIDToURI>';
$result = $client->call('mapDIDToURI', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.7. Retrieving cities information [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getCitiesInfo xmlns:tns="http://www.voxbone.com/VoxService"'
.' xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:country_code_a2>DE</tns:country_code_a2>'
.'<tns:areaCode>30</tns:areaCode>'
.'</tns:getCitiesInfo>';
$result = $client->call('getCitiesInfo', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.8. Testing purchase information validity [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://sandbox.voxbone.com/ws/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:isPurchaseInfoValid xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:login>'.$login.'</ns1:login>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'</tns:AuthenticationToken>'
.'<tns:productIdentifier>1014</tns:productIdentifier>'
.'<tns:purchaseInfo>'
.'<ns1:city>Gerbrunn</ns1:city>'
.'<ns1:company>voxbone</ns1:company>'
.'<ns1:country_code_a2>DE</ns1:country_code_a2>'
.'<ns1:firstname>firstname</ns1:firstname>'
.'<ns1:lastname>lastname</ns1:lastname>'
.'<ns1:salutation>MR</ns1:salutation>'
.'<ns1:street>a street</ns1:street>'
.'<ns1:zip>97216</ns1:zip>'
.'</tns:purchaseInfo>'
.'</tns:isPurchaseInfoValid>';
$result = $client->call('isPurchaseInfoValid', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.9. Retrieving DIDs information [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getDIDsInfo xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'<tns:Filters>'
.'<ns1:didPattern>4577345790</ns1:didPattern>'
.'</tns:Filters>'
.'</tns:getDIDsInfo>';
$result = $client->call('getDIDsInfo', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.10. Cancelling a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "your_login";
$password = "your_password";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:cancelDID xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'<tns:DIDNumberFormatted>551135237755</tns:DIDNumberFormatted>'
.'</tns:cancelDID>';
$result = $client->call('cancelDID', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.1.2.10. Cancelling a DID [up]
<?php
require_once('./lib/nusoap.php');
$client = new soapclient('http://local.www/VoxService/services/VoxService?wsdl', true );
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$login = "francois";
$password = "frans";
$key = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$key );
$params = '<tns:getAccountBalance xmlns:tns="http://www.voxbone.com/VoxService" xmlns:ns1="http://containers.services.webservices.voxbone">'
.'<tns:AuthenticationToken>'
.'<ns1:hash>'.$hash.'</ns1:hash>'
.'<ns1:key>'.$key.'</ns1:key>'
.'<ns1:login>'.$login.'</ns1:login>'
.'</tns:AuthenticationToken>'
.'</tns:getAccountBalance>';
$result = $client->call('getAccountBalance', $params);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
3.2. Using PHP 5.x
3.2.1. Requirements [up]
This PHP tutorial on how to use our web services use the PHP5 soap extension.
You can find more informations about the soap extension on the following urls:
3.2.2. Code Samples [up]
3.2.2.1. Create the AuthenticationToken [up]
The following code sample shows you how to create an AuthenticationToken using SHA1 (Secure Hash Algorithm)
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( "your_password".$date );
$token = array( "login" =>"your_login","hash"=>$hash,"key"=>$date);
Note that 123 is an example and that you can add whatever you want unless it's a valid time.
3.2.2.2. Retrieving countries list [up]
The following code sample shows you how to retrieve the countries in which Voxbone provides DIDs.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token );
$result = $client->getCountriesList($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.3. Retrieving area code [up]
The following code sample shows how to retrieve the area codes we offer for a given country.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token,
"country_code_a2"=>"DK");
$result = $client->getAreaCodeForCountry($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
Note that an exception will be thrown if the specified country_code_A2 doesn't exist, or if the country it refers to isn't offered by the Web Service.
3.2.2.4. Buying a DID [up]
The following code sample shows how to buy a DID.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$purchaseInfo = "";
$param = array( "AuthenticationToken" => $token,
"countryPhoneCode"=>1,
"areaCode"=>613,
"areaCodeIdentifier"=>10,
"quantity"=>2,
"defaultURI"=>"test@voxbone.com",
"purchaseInfo"=> $purchaseInfo
);
$result = $client->buyDIDs($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.5. Buying a DID by product ID [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$purchaseInfo = "";
$param = array( "AuthenticationToken" => $token,
"productIdentifier"=>1,
"quantity"=>1,
"defaultURI"=>"test@test.com",
"purchaseInfo"=> $purchaseInfo
);
$result = $client->buyDIDsByProductsID($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br/><br/>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.6. Setting the PurchaseInfo [up]
In order to specify the PurchaseInfo when buying a DID, replace:
$purchaseInfo = "";
$purchaseInfo = array( "city"=>"Brussels", "company"=>"Voxbone", "country_code_a2"=>"BE", "firstname"=>"Vincent", "lastname"=>"Morsiani", "salutation"=>"MR", "street"=>"Avenue Louise", "zip"=>1050 );
3.2.2.7. Mapping a DID [up]
The following code sample shows you how to map a DID to an URI.
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$didFormatted = "3237470319";
$param = array( "AuthenticationToken" => $token,
"DIDNumberFormatted"=>$didFormatted,
"URI"=>"test@voxbone.com");
$client->mapDIDToURI($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.8. Retrieving cities information [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1,"encoding"=>"UTF-8"));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$country_code_a2 = "DE";
$area_code = 30;
$param = array( "AuthenticationToken" => $token,
"country_code_a2"=>$country_code_a2,
"areaCode"=>$area_code
);
$result = $client->getCitiesInfo($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo( "<br/><br/>" );
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.9. Testing purchase information validity [up]
<?php
$client = new SoapClient("http://sandbox.voxbone.com/ws/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1,"encoding"=>"UTF-8"));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$productID = 59;
$city = utf8_encode("Gräfelfing");
$purchaseInfo = array( "city"=>$city,
"company"=>"Voxbone",
"country_code_a2"=>"DE",
"firstname"=>"Vincent",
"lastname"=>"Morsiani",
"salutation"=>"MR",
"street"=>"testing street",
"zip"=>82156
);
$param = array( "AuthenticationToken" => $token,
"productIdentifier"=>$productID,
"purchaseInfo"=>$purchaseInfo
);
$result = $client->isPurchaseInfoValid($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
echo("<br><br>");
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.11. Cancelling a DID
3.2.2.12. Retrieving your account balance
3.2.2.10. Retrieving DIDs information [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$filter = array("didPattern" =>"5532", "uri"=>"test@test.com");
$param = array( "AuthenticationToken" => $token,
"Filters" => $filter
);
$client->getDIDsInfo($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.11. Cancelling a DID [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token,
"DIDNumberFormatted" => "551133015382"
);
$client->cancelDID($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
3.2.2.12. Retrieving your account balance [up]
<?php
$client = new SoapClient("http://local.www/VoxService/services/VoxService?WSDL",array("trace"=>1,"exceptions"=>1));
$login = "your_login";
$password = "your_password";
$date = date("Y-m-d H:i:s").":123123456789";
$hash = sha1( $password.$date );
$token = array( "login" =>$login,"hash"=>$hash,"key"=>$date);
$param = array( "AuthenticationToken" => $token
);
$client->getAccountBalance($param);
echo "<pre>";
print_r( $result );
echo "</pre>";
print "<br/><br/>";
print "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
print "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
?>
