Support A2Billing :

provided by Star2Billing S.L.

Support A2Billing :
It is currently Sat Sep 19, 2020 2:36 am
Hosted Voice Broadcast


All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to use/implement different API features
PostPosted: Fri Apr 03, 2009 7:45 am 
Offline

Joined: Mon Mar 30, 2009 10:24 am
Posts: 6
Hello,

I need to do different operations from outside a2billing and playing with a2billing database:
-AddPayments
-AddCharges
-GetBalance of an account
-GetCallsList of an account
-DisplayRates (I guess api/display_ratecard.php)

I didn't see the first four operation in the API. I would go to implement in PHP and calling some a2billing functions (to not access the DataBase straight away). Is there any better method to do it? How are you doing it?

Thanks,

Carles


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 04, 2009 9:07 pm 
Offline
User avatar

Joined: Mon Apr 30, 2007 6:43 am
Posts: 1060
Location: Canada
Hello there,

With SOAP applications, the sky is the limit. You can use the already available soap servers and clients available in A2Billing to learn how to build your own. I am afraid that that's the only way.

Cheers


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Mon Mar 29, 2010 8:22 am 
Offline

Joined: Mon Dec 07, 2009 10:09 am
Posts: 62
Location: Assiut, Egypt
really, i ask my self many times about the bebefits of this folder in my A2B box.
so please i need more info about how to use it :D


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Mon Aug 01, 2011 11:02 am 
Offline

Joined: Wed Jun 29, 2011 11:38 am
Posts: 9
Nobody wants to share this :(


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Tue Aug 30, 2011 11:35 am 
Offline

Joined: Tue Aug 30, 2011 11:31 am
Posts: 2
Hi,

Where is the documentation to use the api?

Someone has said: /Doc/a2b_SOAP_webservice.txt, which does not exist.

Kindest Regards
Craig Edmonds


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Tue Nov 22, 2011 4:17 pm 
Offline

Joined: Wed Nov 16, 2011 11:16 am
Posts: 8
Hi

Did anybody find out how to use the webservices API in 1.9.4?

Thanks

-Barry


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Sun Feb 03, 2013 8:53 pm 
Offline

Joined: Tue Jan 02, 2007 9:59 pm
Posts: 2
I am on the same situation, I want to implement on my WHMCS system some modules for automatic creation of a customer account on A2Billing, adding funds, but I can not find, anywhere, the SOAP implementation that A2Billing has done, what SOAP methods are exposed, and a small sample to use them...

To have an API to call A2Billing Services would add a lot of possibilities to that platform, if I do not have a SOAP way to access such as methods, I would have to go to other alternatives .. :-( And would like to avoid that..

MOR, for example (the commercial alternative to a2billing) has a good api, and is reasonably documented...

Can any one, please, provide me any point to the documentaiton fo the API of A2Billing ? Does A2Billing really has an API for some critical methods (ie, create account, add funds, check funds, that 3 simple ones would be enough for me) ? Please, an hint would be welcomed.

Thks.


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Mon Feb 04, 2013 10:43 am 
Offline

Joined: Wed Nov 16, 2011 11:16 am
Posts: 8
agorosti wrote:
I am on the same situation, I want to implement on my WHMCS system some modules for automatic creation of a customer account on A2Billing, adding funds, but I can not find, anywhere, the SOAP implementation that A2Billing has done, what SOAP methods are exposed, and a small sample to use them...



Hi,

Good news for you :-)

Yes, there are indeed SOAP APIs available, and they do actually work.

In the main a2billing installation archive, there is a webservice directory. This needs to be in your web server DocumentRoot somewhere (you will also want to protect this directory so that it can only be accessed by the IP addresses you define). Remember that webservice/lib is a symlink to ../common/lib so you can't just place only the webservice directory into your Document Root, the common directory needs to be along side it. For example, if you installed the Web UI as per the install instructions into /var/www/a2billing/, you will want to place the webservice into /var/www/a2billing as well.

The main SOAP server is then available at the URL

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php

...you will need to change the YOUR_WEB_SERVER and PATH_TO_A2BILLING to fit your installation.

If you make a request to

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php?wsdl

...this will return the WSDL which gives the details of all the SOAP methods available.

I have included below a working example PHP script which demonstrates getting the balance of an account. All the other methods are largely similar so you should be able to figure them out from this. Just remember that the order in which you pass the parameters must match the order in the WSDL as only the values are passed, not the parameter names.

I have actually extended the API to suit my own needs by creating my own Class which extends the main SOAP_A2Billing class. I also include below an example of how to do this.

A2Billing SOAP Webservice Example
This script should be placed on the web server which you want to make the SOAP request from, and then loaded in your browser like "http://localhost/a2billing_ws_example.php".

You need to change the $security_key and the $accountnumber to match your system.

Code:
<?php

// You need to have the php-soap module installed on both the server running the a2billing webservices,
// and on the client server making the SOAP request.(on Ubuntu do "sudo apt-get install php-soap")
require('SOAP/Client.php');


// you need to set the below $security_key to the same value both here and also in the a2billing settings
// under web_ui -> api_security_key (do this via the Admin web UI)
$security_key = 'changethistoyourapi_security_key';

/*
This is the SOAP endpoint, which should be changed to point to the correct path. You can check this
and also pick up the WSDL file by pointing your browser at

http://<YOUR WEB SERVER>/<PATH_TO>/webservice/SOAP/soap-a2billing-server.php?wsdl

..and it should return the WSDL file for this SOAP webservice.
*/
$endpoint = 'http://<YOUR WEB SERVER>/<PATH_TO>/webservice/SOAP/soap-a2billing-server.php';


// Create SOAP Client
$a2b = new SOAP_Client($endpoint);



/*
These are the parameters you will be sending to the server. Order is very important and must follow
the order stated in the WSDL
Set the $attribute to the attribute you wish to have returned (for example 'credit' to get the current balance).
The $accountnumber should be set the the account number you wish to query.
*/

$attribute = 'credit';
$accountnumber = '9408554516';

$params = array(
'security_key' => md5($security_key),
'attribute' => $attribute,
'accountnumber' => $accountnumber);



$method = 'Get_Account_Attribute';

$arr_result = $a2b -> call($method, $params);


echo "<pre>";

$account_details = $arr_result[0];
$response = $arr_result[1];

echo "Response: " . $response;
echo "\n\n\n";
echo "$attribute: $account_details";


?>


Class.My_SOAP-function.php
This is an example of how you can extend the API to suit your own needs. Save it as Class.My_SOAP-function.php in to the webservice/lib directory.
Code:
<?php

include (dirname(__FILE__)."/Class.SOAP-function.php");
class My_SOAP_A2Billing extends SOAP_A2Billing
{

      public function My_SOAP_A2Billing() {
           parent::SOAP_A2Billing();

        /*
        The dispatch_map creates the WSDL entry for your available SOAP methods. 
        You can create additional methods by creating a dispatch_map similar to the one below, and then creating the
        corresponding function.
        */
        $this->__dispatch_map['Get_Account_Attributes'] =
                 array('in' => array('security_key' => 'string', 'attribute' => 'string', 'accountnumber' => 'string'),
                       'out' => array('result' => 'array', 'message' => 'string')
                       );
   }


    /*
   *      Get all cc_card attributes from A2Billing for a given account number
   *
   *      Get_Account_Attributes($security_key, '235412356')
   */

    function Get_Account_Attributes($security_key, $accountnumber)
    {
        if (!$this->Check_SecurityKey ($security_key)) {
         return array(false, "ERROR INVALID KEY");
     }

      $this->DBHandle->SetFetchMode(ADODB_FETCH_ASSOC);

      $QUERY = "SELECT * FROM cc_card WHERE username = '$accountnumber' LIMIT 1";
      $result = $this->instance_table -> SQLExec ($this->DBHandle, $QUERY);
      if (!is_array($result))
      {
          return array(false, "ERROR CANNOT LOAD THE ACCOUNT DETAILS for $accountnumber");
      }
      return array(serialize($result[0]), 'Get_Account_Attributes SUCCESS');
      }
}

?>


You now need to change webservice/SOAP/soap-a2billing-server.php to use this rather than the Class.SOAP-function.php by changing it as follows:

Code:
include '../lib/Class.My_SOAP-function.php';

$server = new SOAP_Server();

$webservice = new My_SOAP_A2Billing();


This will make it so that you can use all the built-in methods but can also add your own, with minimal change to the actual a2b code, making upgrades easier.

Sorry for the in-line code, but attachments seem to be broken.

Hope this helps.

-Barry


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Wed Feb 06, 2013 3:41 am 
Offline

Joined: Thu Apr 21, 2011 5:22 pm
Posts: 106
Contact star2billing the company behind a2billing and they will help you. They helped me a lot for a very small fee.


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Tue Feb 26, 2013 7:06 pm 
Offline

Joined: Tue Feb 26, 2013 6:15 pm
Posts: 11
I build API's on the regular and I've always found that SOAP is the harder one between itself and REST for new comers. I've just built a API for A2Billing but a bit differently. Everything A2 Billing does is stored in the MySQL database so I decided to build my own API (on a separate server) and simply have it query/update/input data into the MySQL database that powers my A2Billing installation in the cloud. Many will warn against this because directly changing the database is always risky, but I'd like to point out that the SOAP API built into A2 does the exact same thing. Make sure you do ample testing before changing anything important.

Here is a quick example of how you can do this. Don't forget to allow remote access to your MySQL server. When I get some time I may built this out further and make all the functions available in a ZIP, I'm currently not even finished with all the functions though.

This is a really simple example but it may help someone in the future.


Creating a Customer/Card

Code:
<?
## CONNECT TO YOur A2BILLING SQL SERVER

$link = mysql_pconnect("166.44.14.344","root","yourpassword")
or die("Could Not connect! Error: " .mysql_error());
mysql_select_db("mya2billing",$link)
or die("Could not open database!
Error: " .mysql_error());

## GENERATE ACCOUNT CREDENTIALS
$digits = 10; $username = rand(pow(10, $digits-1), pow(10, $digits)-1); // Ganerate username
$digits = 15; $alias = rand(pow(10, $digits-1), pow(10, $digits)-1); // Generate alias
$password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') , 0 , 20); // Generate a password


## CREATE THE CUSTOMER/CARD

//Be sure to change values here so they match with you rate card etc.

mysql_query("INSERT INTO cc_card (creationdate,expirationdate,enableexpire,expiredays,username,useralias,uipass,credit,tariff,id_didgroup,activated,status,lastname,firstname,country,zipcode,email,inuse,simultaccess,currency,nbused,typepaid,creditlimit,voipcall,sip_buddy,iax_buddy,language,id_campaign,initialbalance,invoiceday,id_timezone,max_concurrent)
values (NOW(),'2022-01-01 00:00:00','0','0','".$username."','".$alias."','".$password."','50.00','1','-1','f','1','".$lastname."','".$firstname."','USA','".$zipcode."','[email protected]','0','1','USD','0','0','0','0','1','1','en','-1','0.00','1','67','2')");
$a2billing_id = mysql_insert_id();   
$newaccount = $a2billing_id;


## CHECK IF THE CUSTOMER/CARD WAS CREATED, IF SO ADD THE SIP CREDENTIALS (sip buddy)

if ($newaccount != "") {

$secret = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') , 0 , 12); //Create the secret

mysql_query("INSERT INTO cc_sip_buddies (id_cc_card,name,accountcode,regexten,amaflags,canreinvite,context,dtmfmode,host,nat,qualify,secret,type,username,disallow,allow,cancallforward)
values ('".$newaccount."','".$username."','".$username."','".$username."','billing','YES','a2billing','RFC2833','dynamic','yes','no','".$secret."','friend','".$username."','ALL','ulaw,alaw,gsm,g729','yes')");
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
$a2billing_sip_id = mysql_insert_id();   
$newsip = $a2billing_sip_id;


## OUTPUT THE XML

print <<<A2RETURN
<return>
<createcustomer>
<accountid>$newaccount</accountid>
<sipid>$newsip</sipid>
<username>$username</username>
<password>$secret</password>
</createcustomer>
</return>
A2RETURN;
?>


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Wed Sep 04, 2013 10:13 am 
Offline

Joined: Fri Aug 30, 2013 11:51 am
Posts: 2
As instructed in the previous posts I have created a symlink to the webservice folder in var/www/html/a2billing,
yet when I post this url in my browser, http://mydomain.com/a2billing/webservic ... r.php?wsdl
The reply is just a blank page. neither is any error displayed.
This is a fresh Setup of a2billing.

Please guide towards setting this up.

Thank You


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Mon Sep 30, 2013 7:44 pm 
Offline

Joined: Fri Aug 30, 2013 11:51 am
Posts: 2
barryflanagan wrote:

Hi,

Good news for you :-)

Yes, there are indeed SOAP APIs available, and they do actually work.

In the main a2billing installation archive, there is a webservice directory. This needs to be in your web server DocumentRoot somewhere (you will also want to protect this directory so that it can only be accessed by the IP addresses you define). Remember that webservice/lib is a symlink to ../common/lib so you can't just place only the webservice directory into your Document Root, the common directory needs to be along side it. For example, if you installed the Web UI as per the install instructions into /var/www/a2billing/, you will want to place the webservice into /var/www/a2billing as well.

The main SOAP server is then available at the URL

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php

...you will need to change the YOUR_WEB_SERVER and PATH_TO_A2BILLING to fit your installation.

If you make a request to

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php?wsdl

...this will return the WSDL which gives the details of all the SOAP methods available.

I have included below a working example PHP script which demonstrates getting the balance of an account. All the other methods are largely similar so you should be able to figure them out from this. Just remember that the order in which you pass the parameters must match the order in the WSDL as only the values are passed, not the parameter names.

-Barry


Hello,
I have set the path as instructed in this post by creating the symlink, yet am unable to receive a WSDL reply.

Will appreciate a little help with more explanation towards setting up the Soap webservice.

Thank You

Alikheri


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Fri Nov 01, 2013 2:04 am 
Offline

Joined: Thu Oct 10, 2013 7:23 am
Posts: 3
Hi,

Thank you for your info, i try to follow your suggestion

Move the folder webservice in my /var/www/html/a2billing directory , this mean have /var/www/html/a2billing/webservice

but receive only one forbidden access

I check the permission folder but is same of a2billing/admin

I try also to create one symlink to webservice in /var/www/html/a2billing but have the same result.


I check the doc in doc folder but no found any indication for install and/or configure it, or i am not able to found it

Please can give me some suggestion or indicate some documentation that i can use about ?

Thank you

Regards


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Fri May 23, 2014 9:13 pm 
Offline

Joined: Fri May 23, 2014 9:04 pm
Posts: 2
Location: Ireland
barryflanagan wrote:
agorosti wrote:
I am on the same situation, I want to implement on my WHMCS system some modules for automatic creation of a customer account on A2Billing, adding funds, but I can not find, anywhere, the SOAP implementation that A2Billing has done, what SOAP methods are exposed, and a small sample to use them...



Hi,

Good news for you :-)

Yes, there are indeed SOAP APIs available, and they do actually work.

In the main a2billing installation archive, there is a webservice directory. This needs to be in your web server DocumentRoot somewhere (you will also want to protect this directory so that it can only be accessed by the IP addresses you define). Remember that webservice/lib is a symlink to ../common/lib so you can't just place only the webservice directory into your Document Root, the common directory needs to be along side it. For example, if you installed the Web UI as per the install instructions into /var/www/a2billing/, you will want to place the webservice into /var/www/a2billing as well.

The main SOAP server is then available at the URL

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php

...you will need to change the YOUR_WEB_SERVER and PATH_TO_A2BILLING to fit your installation.

If you make a request to

http://<YOUR_WEB_SERVER>/<PATH_TO_A2BILLING>/webservice/SOAP/soap-a2billing-server.php?wsdl

...this will return the WSDL which gives the details of all the SOAP methods available.

I have included below a working example PHP script which demonstrates getting the balance of an account. All the other methods are largely similar so you should be able to figure them out from this. Just remember that the order in which you pass the parameters must match the order in the WSDL as only the values are passed, not the parameter names.

I have actually extended the API to suit my own needs by creating my own Class which extends the main SOAP_A2Billing class. I also include below an example of how to do this.

A2Billing SOAP Webservice Example
This script should be placed on the web server which you want to make the SOAP request from, and then loaded in your browser like "http://localhost/a2billing_ws_example.php".

You need to change the $security_key and the $accountnumber to match your system.

Code:
<?php

// You need to have the php-soap module installed on both the server running the a2billing webservices,
// and on the client server making the SOAP request.(on Ubuntu do "sudo apt-get install php-soap")
require('SOAP/Client.php');


// you need to set the below $security_key to the same value both here and also in the a2billing settings
// under web_ui -> api_security_key (do this via the Admin web UI)
$security_key = 'changethistoyourapi_security_key';

/*
This is the SOAP endpoint, which should be changed to point to the correct path. You can check this
and also pick up the WSDL file by pointing your browser at

http://<YOUR WEB SERVER>/<PATH_TO>/webservice/SOAP/soap-a2billing-server.php?wsdl

..and it should return the WSDL file for this SOAP webservice.
*/
$endpoint = 'http://<YOUR WEB SERVER>/<PATH_TO>/webservice/SOAP/soap-a2billing-server.php';


// Create SOAP Client
$a2b = new SOAP_Client($endpoint);



/*
These are the parameters you will be sending to the server. Order is very important and must follow
the order stated in the WSDL
Set the $attribute to the attribute you wish to have returned (for example 'credit' to get the current balance).
The $accountnumber should be set the the account number you wish to query.
*/

$attribute = 'credit';
$accountnumber = '9408554516';

$params = array(
'security_key' => md5($security_key),
'attribute' => $attribute,
'accountnumber' => $accountnumber);



$method = 'Get_Account_Attribute';

$arr_result = $a2b -> call($method, $params);


echo "<pre>";

$account_details = $arr_result[0];
$response = $arr_result[1];

echo "Response: " . $response;
echo "\n\n\n";
echo "$attribute: $account_details";


?>


Class.My_SOAP-function.php
This is an example of how you can extend the API to suit your own needs. Save it as Class.My_SOAP-function.php in to the webservice/lib directory.
Code:
<?php

include (dirname(__FILE__)."/Class.SOAP-function.php");
class My_SOAP_A2Billing extends SOAP_A2Billing
{

      public function My_SOAP_A2Billing() {
           parent::SOAP_A2Billing();

        /*
        The dispatch_map creates the WSDL entry for your available SOAP methods. 
        You can create additional methods by creating a dispatch_map similar to the one below, and then creating the
        corresponding function.
        */
        $this->__dispatch_map['Get_Account_Attributes'] =
                 array('in' => array('security_key' => 'string', 'attribute' => 'string', 'accountnumber' => 'string'),
                       'out' => array('result' => 'array', 'message' => 'string')
                       );
   }


    /*
   *      Get all cc_card attributes from A2Billing for a given account number
   *
   *      Get_Account_Attributes($security_key, '235412356')
   */

    function Get_Account_Attributes($security_key, $accountnumber)
    {
        if (!$this->Check_SecurityKey ($security_key)) {
         return array(false, "ERROR INVALID KEY");
     }

      $this->DBHandle->SetFetchMode(ADODB_FETCH_ASSOC);

      $QUERY = "SELECT * FROM cc_card WHERE username = '$accountnumber' LIMIT 1";
      $result = $this->instance_table -> SQLExec ($this->DBHandle, $QUERY);
      if (!is_array($result))
      {
          return array(false, "ERROR CANNOT LOAD THE ACCOUNT DETAILS for $accountnumber");
      }
      return array(serialize($result[0]), 'Get_Account_Attributes SUCCESS');
      }
}

?>


You now need to change webservice/SOAP/soap-a2billing-server.php to use this rather than the Class.SOAP-function.php by changing it as follows:

Code:
include '../lib/Class.My_SOAP-function.php';

$server = new SOAP_Server();

$webservice = new My_SOAP_A2Billing();


This will make it so that you can use all the built-in methods but can also add your own, with minimal change to the actual a2b code, making upgrades easier.

Sorry for the in-line code, but attachments seem to be broken.

Hope this helps.

-Barry


I just wanted to say a huge thanks for this very helpful post. I search for hours and days on the A2Billing API until I came across this. Not only did you make it clear how to use the current API but you explained very simply how to extend it.

I now have a working SOAP API and I have already customised the customer / DID create process for my scenario (to ensure internal DID, SIP username and Caller ID are all the same on customer create)

I have only one small issue that I cant figure out. I cant get the wsdl to come back in a response (even though the actual server calls work)

When I customise

http://<YOUR WEB SERVER>/<PATH_TO>/webservice/SOAP/soap-a2billing-server.php?wsdl

to my server I just get a 500 error. I am pretty sure I am calling correctly

Any help would be appreciated


Top
 Profile  
 
 Post subject: Re: How to use/implement different API features
PostPosted: Fri May 23, 2014 10:41 pm 
Offline

Joined: Fri May 23, 2014 9:04 pm
Posts: 2
Location: Ireland
OK figured it out...same error as here

viewtopic.php?f=11&t=10660&start=0

Had to yum install php-pear-SOAP in my centos build

API all working now


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Predictive Dialer


All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group