SOAP API (affjet)

79 views
Skip to first unread message

hug0

unread,
Dec 11, 2013, 10:53:11 AM12/11/13
to joomla-de...@googlegroups.com
Hi, 

I have been using a website to organise data. It now offers an API to integrate the data in my own site.

The current code i have will show the data on my site as an array. 

<?php
 
defined( '_JEXEC' ) or die( 'Access Deny' ); 
 
 
//Creating AffJet client for SOAP
$client = new SoapClient($nameSpace."?wsdl");
 
$pageNumber = 0;
//Setting up parameters
$params = array();
$params["apiKey"] = "Your-api-key";
//Value for parameters (optional)
//$params["networkId"] = array(1,2);
//$params["merchantId"] = array(1,2);
//$params["startDate"] = "2013-12-01 00:00:00";
//$params["endDate"] = "2013-12-30 23:59:59";
//$params["pageNumber"] = 0;
//$params["pageSize"] = 3;
//Making Request
$response = $client->getTransactions($params);
//XML to SimpleXMLElement Object
$xmlResponse = new SimpleXMLElement($response);
if ($xmlResponse->success == "true"){
    while (isset($xmlResponse->dataList->data)) {
        //Iterate the results
        foreach ($xmlResponse->dataList->data as $data){
            var_dump(xml2array($data));
        }
        //Requesting next page of data
        $pageNumber++;
        $params["pageNumber"] = $pageNumber;
        //Making Request
        $response = $client->getTransactions($params);
        //XML to SimpleXMLElement Object
        $xmlResponse = new SimpleXMLElement($response);
    }
} else {
    //Error somewhere
    echo $xmlResponse->errorMessage;
}
     
/**
* Transforms the object SimpleXmlElement into an array, easier to handle
*/
function xml2array($xml) {
   $arr = array();
    foreach ($xml as $element) {
        $tag = $element->getName();
        $e = get_object_vars($element);
        if (!empty($e)) {
            $arr[$tag] = $element instanceof SimpleXMLElement ? xml2array($element) : $e;
        } else {
               $arr[$tag] = trim($element);
        }
    }
    return $arr;
 }
?>

I was wondering if i could get some advise on implementing this on a joomla site?

Any guidance would be great.

Cheers

H

also

The api data changes once a day so rather than call this site every time I load a page, would it be best to somehow store the data and only get/update this information once a day? 


Allon Moritz

unread,
Dec 11, 2013, 3:54:49 PM12/11/13
to joomla-de...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

Sam Coult

unread,
Dec 13, 2013, 10:38:17 AM12/13/13
to joomla-de...@googlegroups.com
Do yourself a favour and check out the docs for SoapClient with a fine tooth comb.  There are some absolutely essential hidden settings, such as SOAP_SINGLE_ELEMENT_ARRAYS that will save you a lot of hair pulling.

$myOptions = array(
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);

$client = new SoapClient($myWsdl, $myOptions)

I would also advise caching your wsdl, which is easy to configure in either your php.ini or using ini_set (probably not during development but definitely in production, otherwise you will be requesting the wsdl for each service call): 

$ttl = 86400; //1 day
ini_set('soap.wsdl_cache_enabled',1);
ini_set('soap.wsdl_cache_ttl',$wsdl_ttl);

//And you might want to set some timeout values, high or low depending on your requirements
ini_set('default_socket_timeout', 10);
ini_set('max_execution_time', 10);
Reply all
Reply to author
Forward
0 new messages