I want to apply FedEx API in PHP website. I did it but my client said that it gives wrong rates . my code is below:
// FedEx
$services['fedex']['PRIORITYOVERNIGHT'] = 'Priority Overnight';
$services['fedex']['STANDARDOVERNIGHT'] = 'Standard Overnight';
$services['fedex']['FIRSTOVERNIGHT'] = 'First Overnight';
$services['fedex']['FEDEX2DAY'] = '2 Day';
$services['fedex']['FEDEXEXPRESSSAVER'] = 'Express Saver';
$services['fedex']['FEDEXGROUND'] = 'Ground';
$services['fedex']['FEDEX1DAYFREIGHT'] = 'Overnight Day Freight';
$services['fedex']['FEDEX2DAYFREIGHT'] = '2 Day Freight';
$services['fedex']['FEDEX3DAYFREIGHT'] = '3 Day Freight';
$services['fedex']['GROUNDHOMEDELIVERY'] = 'Home Delivery';
$services['fedex']['INTERNATIONALECONOMY'] = 'International Economy';
$services['fedex']['INTERNATIONALFIRST'] = 'International First';
$services['fedex']['INTERNATIONALPRIORITY'] = 'International Priority';
// Config
$config = array(
// Services
'services' => $services,
// Weight
'weight' => 2, // Default = 1
'weight_units' => 'lb', // lb (default), oz, gram, kg
// Size
'size_length' => 5, // Default = 8
'size_width' => 6, // Default = 4
'size_height' => 3, // Default = 2
'size_units' => 'in', // in (default), feet, cm
// From
'from_zip' => 97210,
'from_state' => "OR", // Only Required for FedEx
'from_country' => "US",
// To
'to_zip' => 55455,
'to_state' => "MN", // Only Required for FedEx
'to_country' => "US",
// Service Logins
//'ups_access' => '0C2D05F55AF310D0', // UPS Access License Key
//'ups_user' => 'dwstudios', // UPS Username
//'ups_pass' => 'dwstudios', // UPS Password
//'ups_account' => '81476R', // UPS Account Number
//'fedex_account' =>'510087461', // FedEX Account Number
//'fedex_meter' => '100173462' // FedEx Meter Number
);
in my shipping calculator page :
// Calculate FedEX
function calculate_fedex($code) {
//print_R($this->weight);die;
// $url = "https://gatewaybeta.fedex.com/GatewayDC";
$url = "https://gateway.fedex.com/GatewayDC";
$data = '<?xml version="1.0" encoding="UTF-8" ?>
<FDXRateRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXRateRequest.xsd">
<RequestHeader>
<CustomerTransactionIdentifier>Express Rate</CustomerTransactionIdentifier>
<AccountNumber>'.$this->fedex_account.'</AccountNumber>
<MeterNumber>'.$this->fedex_meter.'</MeterNumber>
<CarrierCode>'.(in_array($code,array('FEDEXGROUND','GROUNDHOMEDELIVERY')) ? 'FDXG' : 'FDXE').'</CarrierCode>
</RequestHeader>
<DropoffType>REGULARPICKUP</DropoffType>
<Service>'.$code.'</Service>
<Packaging>YOURPACKAGING</Packaging>
<WeightUnits>LBS</WeightUnits>
<Weight>'.number_format(($this->weight_unit != 'lb' ? convert_weight($this->weight,$this->weight_unit,'lb') : $this->weight), 1, '.', '').'</Weight>
<OriginAddress>
<StateOrProvinceCode>'.$this->from_state.'</StateOrProvinceCode>
<PostalCode>'.$this->from_zip.'</PostalCode>
<CountryCode>'.$this->from_country.'</CountryCode>
</OriginAddress>
<DestinationAddress>
<StateOrProvinceCode>'.$this->to_state.'</StateOrProvinceCode>
<PostalCode>'.$this->to_zip.'</PostalCode>
<CountryCode>'.$this->to_country.'</CountryCode>
</DestinationAddress>
<Payment>
<PayorType>SENDER</PayorType>
</Payment>
<PackageCount>1</PackageCount>
</FDXRateRequest>';
// Curl
$results = $this->curl($url,$data);
// Debug
if($this->debug == true) {
print "<xmp>".$data."</xmp><br />";
print "<xmp>".$results."</xmp><br />";
}
// Match Rate
preg_match('/<NetCharge>(.*?)<\/NetCharge>/',$results,$rate);
//print_R($rate[1]);die;
return $rate[1];
}
and my output is:
Rates for sending a 2 lb, 5 x 6 x 3 in package from 97210 to 55455:
Array
(
[fedex] => Array
(
[PRIORITYOVERNIGHT] => 35.46
[STANDARDOVERNIGHT] => 32.93
[FIRSTOVERNIGHT] => 96.47
[FEDEX2DAY] => 16.87
[FEDEXEXPRESSSAVER] => 11.69
[FEDEXGROUND] => 6.71
[FEDEX1DAYFREIGHT] =>
[FEDEX2DAYFREIGHT] =>
[FEDEX3DAYFREIGHT] =>
[GROUNDHOMEDELIVERY] => 11.13
[INTERNATIONALECONOMY] => 16.87
[INTERNATIONALFIRST] => 96.47
[INTERNATIONALPRIORITY] => 35.46
)
)
Can smebody give me another code of FEDEX api . Thanks in advance