FedEx Web Intergration Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sync
Forum Newbie
Posts: 2
Joined: Tue Dec 16, 2003 10:27 am
Location: Kansas City
Contact:

FedEx Web Intergration Help

Post by sync »

This is the code that I was using for the integration. But it doesn't seem to work. I am not sure if there is something wrong with the code itself.

<?
class fedex
{
var $PostServ ='https://gatewaybeta.fedex.com';
var $PostHost ='https://www.memenethosting.com';

var $Name ='John Doe';
var $CompanyName ='Test Company';
var $CityName ='Test City';
var $StreetAddress ='555 55th St.';
var $PhoneNumber ='5555555';
var $State ='TX';
var $AccountNumber ='55555555';
var $ZipCode ='55555';
var $CountryCode ='US';

function BuildQuery()
{
$this->query_array = array(
0 => "211",
1 => "1st trans",
4003 => $this->Name,
4007 => $this->CompanyName,
4011 => $this->CityName,
4008 => $this->StreetAddress,
4015 => $this->PhoneNumber,
4012 => $this->State,
10 => $this->AccountNumber,
4013 => $this->ZipCode,
4014 => $this->CountryCode,
99 => ""
);

foreach($this->query_array as $key => $val)
{
$this->query .= "$key,\"$val\"";
}

$this->debug[] = array("Generated Query",$this->query);
}

function Post()
{
$this->ch = curl_init();
curl_setopt($this->ch,CURLOPT_URL,"$this->PostServ");
$this->debug[] = array("URL to POST to",$this->PostServ);
curl_setopt($this->ch,CURLOPT_HEADER,1);
curl_setopt($this->ch,CURLOPT_POST,1);
curl_setopt($this->ch,CURLOPT_POSTFIELDS,"?$this->query");
curl_setopt($this->ch,CURLOPT_VERBOSE,1);
curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);

$len = strlen($this->query);
$custom_header = "POST /GatewayDC HTTP/1.0\nReferer: $this->CompanyName\nHost:$this->PostHost\r\n
Accept: image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*\nContent-Type:image/gif\nContent-length:$len\n\n$this->query";

curl_setopt($this->ch,CURLOPT_CUSTOMREQUEST, $custom_header);

$this->result = curl_exec($this->ch);
$this->err_nr =curl_errno($this->ch);

$this->error = curl_error($this->ch);

curl_close($this->ch);

$this->debug[] = array("Query Result",$this->result);
$this->debug[] = array("Query Error",$this->err_nr);
$this->debug[] = array("Error Response",$this->error);
}

function ParseReply()
{
preg_match_all('/([0-9+),"([^"]*)"/',$this->result,$this->result_tmp);
$n = "0";
foreach($this->result_tmp[1] as $val)
{
$this->result_array[$val] = $this->result_tmp[2][$n];
$n++;
}

$this->debug[] = array("Result Array",$this->result_tmp);
$this->debug[] = array("Clean Result Array",$this->result_array);
}

function Go()
{
$this->BuildQuery();
$this->Post();
$this->ParseReply();
return $this->result_array;
}

function Debug()
{
print "<table borde=1>";
foreach($this->debug as $val)
{
print "<tr><td nowrap><b>$val[0]</b></td><td><pre>";
print_r($val[1]);
print "</pre></td></tr>";
}
print "</table>";
}
}


$fedex = new fedex;
$price = $fedex->Go();


$fedex->Debug();


?>


This is the error I get back:

URL to POST to https://gatewaybeta.fedex.com

Query Result

Query Error 52

Error Response Empty reply from server

Result Array Array
(
[0] => Array
(
)

[1] => Array
(
)

)


Clean Result Array


If anyone has done a fedex integration please get a hold of me and help me out. I have been workin on this for quite sometime, but I can't seem to get it right.

ICQ:4718571

Thanks ahead of time,
Sync
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Just easier to read no changes

Code: Select all

<?php
class fedex
{
var $PostServ ='https://gatewaybeta.fedex.com';
var $PostHost ='https://www.memenethosting.com';

var $Name ='John Doe';
var $CompanyName ='Test Company';
var $CityName ='Test City';
var $StreetAddress ='555 55th St.';
var $PhoneNumber ='5555555';
var $State ='TX';
var $AccountNumber ='55555555';
var $ZipCode ='55555';
var $CountryCode ='US';

function BuildQuery()
{
$this->query_array = array(
0 => "211",
1 => "1st trans",
4003 => $this->Name,
4007 => $this->CompanyName,
4011 => $this->CityName,
4008 => $this->StreetAddress,
4015 => $this->PhoneNumber,
4012 => $this->State,
10 => $this->AccountNumber,
4013 => $this->ZipCode,
4014 => $this->CountryCode,
99 => ""
);

foreach($this->query_array as $key => $val)
{
$this->query .= "$key,"$val"";
}

$this->debug[] = array("Generated Query",$this->query);
}

function Post()
{
$this->ch = curl_init();
curl_setopt($this->ch,CURLOPT_URL,"$this->PostServ");
$this->debug[] = array("URL to POST to",$this->PostServ);
curl_setopt($this->ch,CURLOPT_HEADER,1);
curl_setopt($this->ch,CURLOPT_POST,1);
curl_setopt($this->ch,CURLOPT_POSTFIELDS,"?$this->query");
curl_setopt($this->ch,CURLOPT_VERBOSE,1);
curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);

$len = strlen($this->query);
$custom_header = "POST /GatewayDC HTTP/1.0\nReferer: $this->CompanyName\nHost:$this->PostHost\r\n
Accept: image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*\nContent-Type:image/gif\nContent-length:$len\n\n$this->query";

curl_setopt($this->ch,CURLOPT_CUSTOMREQUEST, $custom_header);

$this->result = curl_exec($this->ch);
$this->err_nr =curl_errno($this->ch);

$this->error = curl_error($this->ch);

curl_close($this->ch);

$this->debug[] = array("Query Result",$this->result);
$this->debug[] = array("Query Error",$this->err_nr);
$this->debug[] = array("Error Response",$this->error);
}

function ParseReply()
{
preg_match_all('/([0-9+),"([^"]*)"/',$this->result,$this->result_tmp);
$n = "0";
foreach($this->result_tmp[1] as $val)
{
$this->result_array[$val] = $this->result_tmp[2][$n];
$n++;
}

$this->debug[] = array("Result Array",$this->result_tmp);
$this->debug[] = array("Clean Result Array",$this->result_array);
}

function Go()
{
$this->BuildQuery();
$this->Post();
$this->ParseReply();
return $this->result_array;
}

function Debug()
{
print "<table borde=1>";
foreach($this->debug as $val)
{
print "<tr><td nowrap><b>$val[0]</b></td><td><pre>";
print_r($val[1]);
print "</pre></td></tr>";
}
print "</table>";
}
}


$fedex = new fedex;
$price = $fedex->Go();


$fedex->Debug(); 
?>
Error Response Empty reply from server

Code: Select all

<?php
Result Array Array

(
[0] => Array
(
)

[1] => Array
(
)

) 

?>
sync
Forum Newbie
Posts: 2
Joined: Tue Dec 16, 2003 10:27 am
Location: Kansas City
Contact:

Thanks Draco_03

Post by sync »

Thank you.

I just hope that someone will be able to help, since I am still stuck on the first little thing on getting the meter number from fedex.

Sync
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You need [php_man]array_merge_recursive[/php_man]() I believe.

And your getting that responce from the code because the $val variable is not an array. Instead it's the values of the $this->debug array.
Post Reply