PHP Code Samples
Our PHP codes samples use the NuSOAP SOAP Toolkit for PHP. NuSOAP is a set of PHP classes that allows delevopers to easily consume webs ervices without needing PHP extensions.
Example getProducts() in PHP
// 1) Get Products Call
// Input
$strSoapUsername = "123456"; //Your API Key
$strSoapPassword = "abcd"; //Your API Password
$strCategory = "bd"; //Product category 'bd' is for Birthday flowers
$intProductCount = "10"; //Nnumber of products to retrieve
$intStart = "1"; //Start at the first product
$this->getProductDetails($strSoapUsername,$strSoapPassword,$strCategory,$intProductCount,$intStart);
//Get Product Details
function getProductDetails($strSoapUsername,$strSoapPassword,$strCategory,$intProductCount,$intStart="")
{
$blnResult = false;
// Create the client instance
$client = new nusoap_client($this->strSoapServer,true);
// Check for an error
$strErrors = $client->getError();
if ($strErrors) {
if(is_array($strErrors)) {
$this->strSoapServerError = implode("\r\n",$strErrors);
} else {
$this->strSoapServerError = $strErrors;
}
//echo("ERORR in Connecting with SOAP server");
return $blnResult;
}
// Call the SOAP method
$result = $client->call('getProducts', array("APIKey"=>$strSoapUsername,"APIPassword"=>$strSoapPassword,"category
"=>$strCategory,"numProducts"=>$intProductCount,"startAt"=>$intStart));
// Check for a fault
if(count($result['errors']) > 0 ) {
$strErrors = null;
if(is_array($result['errors'])) {
foreach ($result['errors'] as $key=>$strTempError) {
$strErrors .= $result['errors'][$key]['field']." : ".$result['errors'][$key]['message
']."\r\n";
}
$this->strSoapServerError = $strErrors;
} else {
$this->strSoapServerError = $result['errors'];
}
} elseif(count($result['products']) > 0 ) {
$arrInput = $result['products'];
$arrOurput = array();
foreach ($arrInput as $arrTemp ) {
$arrOurput[] = array_map("trim",$arrTemp);
}
$this->arrProducts = $arrOurput;
unset($arrInput);
unset($arrOurput);
unset($arrTemp);
$blnResult = true;
} elseif($strErrors = $client->getError()) {
if(is_array($strErrors) && count($strErrors) > 0) {
$this->strSoapServerError = implode("\r\n",$strErrors);
} else {
$this->strSoapServerError = $strErrors;
}
} else {
$this->strSoapServerError = $client->response;
}
return $blnResult;
}
|