Thanks for the tips superwormy.
I've made things a bit more complicated than they need to be with my script, however, I will try to explain:
order.php is a sort of "container" for all the parts of the sript.
All forms reside in order.php and POST to it as well.
fedex.php (class) is include()d when the third part of the checkout process is POSTed. (the fedex servers are communicated via curl)
The following is a copy of the fedex class. I could not get it to return $fedprice[1416] (commented out at the bottom), therefore I include()d my own page (fedextra.php) within the class, and retrieved necessary variables from there:
//////////////////////////////////////////////////////////////////////////////
<?
/-------------------------------------------------------------------------------------
fedex_class.php version 1.0
Copyright (c) 1999-2002 Koen Bok
Email: koen@mac.com
Website: http://www.koen.nu/scripts/phpfedex/
Licensed under the GNU GPL. For full terms see http://www.gnu.org/licenses/gpl.html.
-------------------------------------------------------------------------------------
*/
class fedex
{
YOU MAY WISH TO SET THESE STATICLY
// URL to send request to
var $postServ ='https://gateway.fedex.com';
var $postHost ='fedex.com';
var $companyName ='Engrave-a-remembrance';
var $accountNumber ='259302900';
var $shipperNumber ='1532317';
// Transaction Info
// Shipper Info
var $shipperCountryID = 'US';
// Destination info
var $destZip = '32817';
var $destCountryID = 'US';
// Package info
var $packWeight = '14.1';
var $packWeightUnit = 'LBS';
var $packTotal = '1';
// Payment info
var $payValue = '0.00';
var $payValueCur = 'USD';
var $payType = 'CC';
// Service Info
var $packageType = '01';
var $rateIndicator ='2';
var $homeDeliveryType ='1';
##########################################################################
function BuildQuery()
{
$this->query_array = array(
0 => "025", // r Start transaction
498 => $this->shipperNumber, // r Shipper Meter Number
3025 => $this->carrierCode, // r Carrier Code
9 => $this->shipperZip, // r Shipper Zip Code
8 => $this->shipperState, // r Shipper State
10 => $this->accountNumber, // r FedEx Account Number
16 => $this->destStateAbb, // r Destination state abbreviation
17 => $this->destZip, // r Destination Zip Code
50 => $this->destCountryID, // r Destination Country Code
117 => $this->shipperCountryID,// r Shipper Country Code
1401 => $this->packWeight, // r Total Package Weight
75 => $this->packWeightUnit, // r Weight Units
23 => $this->payType, // o Pay Type (Default: Bill Sender)
24 => $this->transactionDate, // o Shipping Date (Default: Today)
116 => $this->packTotal, // o Package Total Count
1415 => $this->payValue, // r Carriage Value
68 => $this->payValueCur, // r Value Type
1273 => $this->packageType, // r Packaging Type
1274 => $this->serviceType, // r Service Type
1529 => $this->rateIndicator, //
440 => $this->residentialDelivery, //
3020 => $this->homeDeliveryType, //
99 => "" // r Ending Tag, required for every transaction.
);
foreach ($this->query_array as $key => $val)
{
$this->query .= "$key,\"$val\"";
}
// Debug information
$this->debug[] = array("Generated Query",$this->query);
}
##########################################################################
function Post()
{
// Init the Curl engine.
$this->ch = curl_init ();
// Set curl options
curl_setopt ($this->ch, CURLOPT_URL,"$this->postServ"); // set the post-to url (do not include the ?query+string here!)
curl_setopt ($this->ch, CURLOPT_HEADER, 1); // Header control
curl_setopt ($this->ch, CURLOPT_POST, 1); // tell it to make a POST, not a GET
curl_setopt ($this->ch, CURLOPT_POSTFIELDS, ""); // put the query string here starting with "?"
curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1); // This allows the output to be set into a variable $xyz
$len = strlen($this->query);
$custom_header = "POST /GatewayDC HTTP/1.0\nReferer: $this->companyName\nHost: $this->postHost\r\nAccept: 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);
// Get the results
$this->result = curl_exec ($this->ch);
$this->err_nr = curl_errno($this->ch);
// Close the connection
curl_close ($this->ch);
// Debug information
$this->debug[] = array("Query Result",$this->result);
$this->debug[] = array("Query Error",$this->err_nr);
}
##########################################################################
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 IS IT, BELIEVE IT OR NOT, THE PLACE THAT IM SPITTING OUT THE RESULT. //
// IT IS A WORK AROUND, AND WILL PROBABLY NOT WORK IF FEDEX REARRANGES THEIR CODE. //
// I AM ADDING MY CODE FOR ENGRAVE'S SHIPPING/HANDLING COSTS HERE //
include ("fedextra.php");
// Debug information
$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 border=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>";
}
}
//* Usage Example
// Let's create a new object
$fedex = new fedex;
if ($method=="92"){
$gnd_or_express="FDXG";
}else{
$gnd_or_express="FDXE";
}
// Pass the object some required variables
$fedex->destZip = $shipzip;
$fedex->shipperZip = $shipperZip;
$fedex->serviceType = $method;
$fedex->carrierCode = $gnd_or_express;
$fedex->rushdelivery = $rush_delivery;
$fedex->homeDeliv = "2";
$fedex->packService = $gnd_or_express;
$fedex->residentialDelivery =$residentialDelivery;
$fedex->home_extra = $home_extra;
$fed_counter=1;
while ($fed_counter<=$qty){
$fedex->$ThirdLineglass[$fed_counter] = $ThirdLineglass[$fed_counter];
$fed_counter++;
}
// And execute the queries
$fedprice = $fedex->Go();
// THIS DOES NOT WORK //
// Field 1416 contains the base rate price
//echo $fedprice[1416];
// This is for optional debugging
$fedex->Debug();
?>
///////////////////////////////////////////////////////////////////////////
And here is fedextra.php:
<?
include ("includes/config.php");
$base_fedex_GND=$this->result_tmp[2][8]; // GROUND SERVICE
$base_fedex_EXP=$this->result_tmp[2][15]; //Fedex Express Service
if ($gnd_or_express=="FDXG"){
$display_rate=$base_fedex_GND;
}else
if ($gnd_or_express=="FDXE"){
$display_rate=$base_fedex_EXP;
}
if ($residentialDelivery=="Y"){
$total_shipping=$display_rate+$signature_fee+$padding+$rushfee+$home_extra;
} else
if ($residentialDelivery=="N"){
$total_shipping=$display_rate+$padding+$rushfee;
}
//echo $method . "<br>";
//echo "Baserate: " . $display_rate . "<br>";
//echo "Sig Fee: " . $signature_fee . "<br>";
//echo "Padding: " . $padding . "<br>";
$s_h=$display_rate+$signature_fee+$padding;
echo "<font style='font-family:Verdana,Arial;font-size:10px;'><b>$" . $s_h . "</b></font><br>";
if ($residentialDelivery=="Y"){
echo "<font style='font-family:Verdana,Arial;font-size:10px;'><b>$" . $home_extra . "</b></font><br>";
}else if ($residentialDelivery=="N"){
}
if ($rushfee>0){
echo "<font style='font-family:Verdana,Arial;font-size:10px;'><b>$" . $rushfee . "</b></font><br>";
}else{
echo "<font style='font-family:Verdana,Arial;font-size:10px;'> </font><br>";
}
echo "<font style='font-family:Verdana,Arial;font-size:12px;font-weight:bold;color:#CC0000;'>$" . $total_shipping . "</font><br>";
?>
//////////////////////////////////////////////////////////////////////
cont'd, see next message ->