by

Debalina

19 May 2015, 07:07 am

about the author

She is a realist yet an avid dreamer. She believes in simple living high thinking. Currently working as developer in software industry, she loves adventure, sports, music, science, and creativity. She loves to see new places, and dream to travel around the world someday. Helping the less fortunate and needy in her own possible ways makes her feel good.

About Debalina

Fedex Web API Integration (Part 3) : Implementing Pickup Services

Fedex Web API

In my previous articles, I had explained the basic steps and requirements for integrating Fedex Web API into a website and discussed the implementation of the Rating API. We obtained the rates for different Fedex shipping services available from a source to destination using the Rating API.

 

Today I will discuss the Pickup Services, using which we can schedule a courier to pick up a shipment, cancel a pickup request, or check for pickup availability. Sometimes, after obtaining rates, we might want to further validate the availability of services in a location and the postal codes. In order to do that Fedex Web API standard services provides 2 more APIs, such as, Service Availability (under Validation Availability and Commitment) and Postal Code enquiry (under Country Service). As the names are self explanatory, here is a one line description about them.

Also Read: Importance Of Brand Positioning In Ecommerce

Postal Code Enquiry: This enables customers to validate postal codes and service commitment.

Service Availability: This determines which FedEx Express services are available between an origin and destination.

The basic file structure and implementation of these two and any other Fedex Web API is similar to the Rating API. However, I wont be going into the details of them today.

Getting back to the “Pickup Web Services”

It is one of the Advanced Services of the available Fedex Web API services. Go to the ‘Advanced Services’ tab of the Developer Resource Center once you have registered and logged into your account and followed the required steps to obtain the passwords and keys, as according to my previous articles.

Under the Advanced Services tab, you will find a header as ‘Pickup Services’ under which there are 3 APIs.

Fedex documentation explains as below:

The FedEx pickup web service allows you to schedule a courier to pick up a shipment, or to cancel a pickup request, or to check for pickup availability.

Pickup API: Use the Pickup Service to schedule courier pickup of a shipment at the location specified in the transaction.

Pickup Availability: Use Pickup Availability to obtain the cut-off and access the time required to request and schedule a pickup and pickup based on the specified area. You may check pickup availability for either FedEx Express or FedEx Ground shipments.

Pickup Availability

Once you have downloaded the API, unzip the files.

Note: Since I am not using PHP5, I have modified all the file extensions in PHP5 to PHP.

Note: Rather than using the file structure provided by the API, I have used the API code by implementing them into my functions for easier use and access as below. Though I had previously explained the Rating API as per the exact file structure given by Fedex Web API, I will be explaining implementation all the API codes through functions from now on. This makes them easier to implement, debug and use.

Fedex Web API Integration19

Soap request-response from server

The below function handles soap call requests and response to the Fedex server to obtain pickup availability data.


function fed_get_pickup_avail()
{
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 5.0.0

require_once('< provide path to “fedex-common.php” file >');

//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = < provide your path to “PickupService_v9.wsdl" >

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

$client = new SoapClient($path_to_wsdl, array('trace' => 1));

$request['WebAuthenticationDetail'] = array(
'UserCredential' => array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Pickup Availability Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'disp',
'Major' => 9,
'Intermediate' => 0,
'Minor' => 0
);
$request['PickupAddress'] = getProperty('address1');
$request['PickupRequestType'] = array('SAME_DAY', ‘FUTURE_DAY’);
$request['DispatchDate'] = getProperty('pickupdate');
//$request['PackageReadyTime'] = getProperty('readytime'); //optional field
//$request['CustomerCloseTime'] = getProperty('closetime'); //optiona fieldl

$request['Carriers'] = array('FDXE','FDXG'); //FDXE => Fedex express
//FDXG => Fedex ground

try{
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}

$response = $client->getPickupAvailability($request);

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

return $response;

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

As you can see, it includes a ‘fedex-common.php’ file and a PickupService_v9.wsdl file. Both these files are present in the unzipped folder of the API.

fedex-common.php

This is basically the file which is common for all APIs and holds parameters and their values which will be accessed from different APIs and are necessary to process the requests.
You might already be accustomed with the file if you have gone through my previous article about the Rating API.

Most important function here is the getProperty() function.
In the function, replace the ‘key’, ‘password’, ‘shipaccount’, ‘billaccount’, and ‘meter’ with the credentials that you had obtained while registration, as below:
‘key’ => Developer Test Key
‘meter’ => Test Meter Number
‘password’ => Password
‘shipaccount’/’billaccount'(or any other ‘account’ parameter) => Test Account Number
These will authenticate the API and help in accessing information from the fedex server.

Below I have highlighted only the fields that are required for the pickup availability API implementation.


function getProperty($var){
if($var == 'key') Return '<put your key here>';
if($var == 'password') Return '<put your password here>';
if($var == 'shipaccount') Return '<put your account number>';
if($var == 'billaccount') Return '<put your account number>';
. . . . .
. . . . .
if($var == 'meter') Return '<put your meter number>';
. . . . .
. . . . .
//This should hold your pickup date
if($var == 'pickupdate') Return date("Y-m-d", mktime(date("m") , date("d"), date("Y")));

if($var == 'address1') Return array(
'StreetLines' => array('10 Fed Ex Pkwy'), //optional field
'City' => 'Memphis', //optional field
'StateOrProvinceCode' => 'TN', //optional field
'PostalCode' => '38115',
'CountryCode' => 'US',
'Residential' => 1
);

. . . . .
. . . . .
}

I have displayed only those fields of the getProperty() function, that are required for the pickup availability API, some of which are optional. The optional fields have been marked.

The soap call request to the Fedex server will return a stdClass Object.
“Options” node in the response will contain all the pickup available dates and times as given in the below example.

example:


[Options] => Array
(
[0] => stdClass Object
(
[Carrier] => FDXE
[ScheduleDay] => SAME_DAY
[Available] => 1
[PickupDate] => 2015-05-13
[CutOffTime] => 22:00:00
[AccessTime] => PT1H0M
[ResidentialAvailable] =>
[CountryRelationship] => DOMESTIC
)

[1] => stdClass Object
(
[Carrier] => FDXE
[ScheduleDay] => FUTURE_DAY
[Available] => 1
[PickupDate] => 2015-05-13
[CutOffTime] => 22:00:00
[AccessTime] => PT1H0M
[ResidentialAvailable] =>
[CountryRelationship] => DOMESTIC
)
[2] => stdClass Object
(
[Carrier] => FDXE
[ScheduleDay] => SAME_DAY
[Available] => 1
[PickupDate] => 2015-05-14
[CutOffTime] => 22:00:00
[AccessTime] => PT1H0M
[ResidentialAvailable] =>
[CountryRelationship] => DOMESTIC
)

[3] => stdClass Object
(
[Carrier] => FDXE
[ScheduleDay] => FUTURE_DAY
[Available] => 1
[PickupDate] => 2015-05-14
[CutOffTime] => 22:00:00
[AccessTime] => PT1H0M
[ResidentialAvailable] =>
[CountryRelationship] => DOMESTIC
)
)

It also contains a node showing the current time-stamp, during which the pickup availability request has been made:

[RequestTimestamp] => 2015-05-13T09:04:00

You can arrange this response as per your requirement to display the dates available for pickup from a source to destination at a point of time.

It also contains two very important parameters, “CutOffTime” and “AccessTime”, which will be required to create pickup requests using the Pickup API.

Note: Saturday pickup might be available from Fedex with separate charges.

This is the basic implementation and integration of Pickup availability API. For further details regarding the service , please refer to the documentation available in the Fedex Developer Resource Center for each API.

by

Debalina

19 May 2015, 07:07 am

about the author

She is a realist yet an avid dreamer. She believes in simple living high thinking. Currently working as developer in software industry, she loves adventure, sports, music, science, and creativity. She loves to see new places, and dream to travel around the world someday. Helping the less fortunate and needy in her own possible ways makes her feel good.

About Debalina
Comment with Facebook

trending

Featured Posts

Editors Choice

Reviews