edoceo

After downloading the necessary WSDLs and documentation from FedEx it's a simple matter of building the proxy's. This docuemnt describes how it's done and provides some samples.

Generating the API Proxy

The proxy here is the stub code necessary to call the service described in the WSDL file. Using PEAR SOAP_WSDL class this can be accomplished with this simple snip. Oddly the FedEx developer resource center describes some FedEx provided PHP samples but they to not exist.

require_once('SOAP/Client.php');
$wsdl = new SOAP_WSDL(FEDEX_WSDL_DIR.'AddressValidationService.wsdl');
print $wsdl->generateAllProxies();

Replace the WSDL file name with the required API. This snip will output PHP code necessary to operate this API, from the above example the output is:

class WebService_AddressValidationService_AddressValidationServicePort extends SOAP_Client
{
  function WebService_AddressValidationService_AddressValidationServicePort($path = 'https://gatewaybeta.fedex.com:443/web-services')
  {
    $this->SOAP_Client($path, 0);
  }
  
  function &addressValidation($parameters)
  {
    $addressValidation = new SOAP_Value('{http://fedex.com/ws/addressvalidation}addressValidation',
                                        false,
                                        $v = array('parameters' => $parameters));

    $result = $this->call('addressValidation',
                          $v = array('addressValidation' => $addressValidation),
                          array('namespace' => 'http://fedex.com/ws/addressvalidation',
                                'soapaction' => 'addressValidation',
                                'style' => 'document',
                                'use' => 'literal'));
    return $result;
  }
}

The thought of creating a seperate class (with a huge name!) for every API necessary was a little much for us here at Edoceo so we created a top level class that provided methods to access the FedEx API. From there the above code was refactored into what's below as a method (AddressValidate) on the FedExConnection class.

$wsdl = new SOAP_WSDL(FEDEX_WSDL_DIR.'AddressValidationService.wsdl');

$args['AuthenticationDetail'] = array('UserCredential'=>$this->key_number);
$args['ClientDetail'] = array(
  'AccountNumber' => $this->account_number,
  'MeterNumber' => $this->meter_number,
);

$sc = $wsdl->getProxy();
$sc->setOpt('curl', CURLOPT_SSL_VERIFYPEER, false);

$sv = new SOAP_Value('{http://fedex.com/ws/addressvalidation}addressValidation',
                      false,
                      $v = array('AddressValidationRequest' => $args));

$sr = $sc->call('addressValidation',
                $x=array('addressValidation'=>$sv),
                array('namespace' => 'http://fedex.com/ws/addressvalidation',
                      'soapaction' => 'addressValidation',
                      'style' => 'document',
                      'use' => 'literal'));
return $sr;

Loading Comments from Disqus...