Connecting Tech Pros Worldwide Forums | Help | Site Map

how to use fedex web service in php to calculate shipping fee

Newbie
 
Join Date: Jul 2008
Posts: 2
#1: Jul 10 '08
hi:

can sone one tell me how to use fedex web service in php to calculate shipping fee? i already have fedex account and 4 keys used to test application

Test Password:8pVQ6p5cHyQVuJJvrfosaBKqG
Developer Test Key: vfNOPSmeA69gJFdf
Test Account: 510087682
Test Meter: 1239156


and i also download source code:

Rate.php5
RateService_v3.xsd
fedex-common.php5
RateService_v3.wsdl

i did enter those 4 keys in rate.php5, and upload those files to my web host (at godaddy.com). but when i enter url Rate.php5, i gave me error like, can not connect to host...

fedex told me that they used xml to point to their server at https://gatewaybeta.fedex.com:443/web-services
but i do not know how to pass 4 keys using xml and point to this service. help!!!!!!





//************ Rate.php5 ***********************//

<?php

// Copyright 2008, FedEx Corporation. All rights reserved.
// Version 3.0.0

chdir('..');

require_once('library/fedex-common.php5');

$newline = "<br />";
$path_to_wsdl = "wsdl/RateService_v3.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information

$request['WebAuthenticationDetail'] = array('UserCredential' =>
array('Key' => 'vfNOPSmeA69gJFdf', 'Password' => '8pVQ6p5cHyQVuJJvrfosaBKqG')); // Replace 'XXX' and 'YYY' with FedEx provided credentials
$request['ClientDetail'] = array('AccountNumber' => '510087682', 'MeterNumber' => '1239156');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v3 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '3', 'Intermediate' => '0', Minor => '0');
$request['Origin'] = array('StreetLines' => array('Sender Address Line 1'), // Origin details
'City' => 'Memphis',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38115',
'CountryCode' => 'US');
$request['Destination'] = array('StreetLines' => array('Destination Address Line 1'), // Destination details
'City' => 'Herndon',
'StateOrProvinceCode' => 'VA',
'PostalCode' => '20171',
'CountryCode' => 'US');
$request['Payment'] = array('PaymentType' => 'SENDER'); // valid codes RECIPIENT, SENDER and THIRD_PARTY
$request['DropoffType'] = 'REGULAR_PICKUP'; // valid codes BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER and STATION
$request['ServiceType'] = 'FEDEX_GROUND'; // valid codes STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['PackagingType'] = 'YOUR_PACKAGING'; // valid codes FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['ShipDate'] = date('Y-m-d');
$request['RateRequestTypes'] = 'ACCOUNT'; // valid codes ACCOUNT, LIST

$PassRateRequestPackageSummary = true;

if ($PassRateRequestPackageSummary)
{
// Passing multi piece shipment rate request (by setting PieceCount > 1)
$request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 20.0, 'Units' => 'LB'), // valid codes LB and KG
'TotalInsuredValue' => array('Amount' => 100, 'Currency' => 'USD'),
'PieceCount' => 2,
'SpecialServicesRequested' => array('SpecialServiceTypes' => 'NON_STANDARD_CONTAINER')); // valid codes HOLD_AT_LOCATION, ...
}
else
{
// Passing single piece shipment rate request
$request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
$request['Packages'] = array(0 => array('Weight' => array('Value' => 10.0, 'Units' => 'LB'), // valid code LB and KG
'InsuredValue' => array('Amount' => 100, 'Currency' => 'USD'),
'Dimensions' => array('Length' => '1', 'Width' => '1', 'Height' => '1', 'Units' => 'IN'), // valid code IN and CM
'SpecialServicesRequested' => array('SpecialServiceTypes' => 'NON_STANDARD_CONTAINER'))); // valid codes HOLD_AT_LOCATION, ...
}

try
{
$response = $client ->getRate($request);

if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
printRequestResponse($client);
}
else
{
echo 'Error in processing transaction.'. $newline. $newline;
foreach ($response -> Notifications as $notification)
{
if(is_array($response -> Notifications))
{
echo $notification -> Severity;
echo ': ';
echo $notification -> Message . $newline;
}
else
{
echo $notification . $newline;
}
}
}

writeToLog($client); // Write to log file

} catch (SoapFault $exception) {
printFault($exception, $client);
}

?>

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jul 11 '08

re: how to use fedex web service in php to calculate shipping fee


This is not a coding problem, but how to use an API.

Fedex should have the proper documentation you need. Consult them.
Newbie
 
Join Date: Jul 2008
Posts: 2
#3: Jul 11 '08

re: how to use fedex web service in php to calculate shipping fee


please please at least give me a name of that document, so i can study....
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#4: Jul 11 '08

re: how to use fedex web service in php to calculate shipping fee


Quote:

Originally Posted by supperham

please please at least give me a name of that document, so i can study....

Please consult FedEx, they might have some appropriate information for you.
We won't be able to guide you, unless someone here has already used that (probability is quite low).
Reply