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

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.

Read more at http://blog.designs.codes/retain-customers/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s