Canceling a Shipment


The situation may arise where you need to cancel a shipment to a customer. This cancellation must be made before the end of business on the day the request was placed. The request and response for this operation are very short:

 $request = <<< XMLREQUEST <?xml version="1.0" encoding="UTF-8" ?>  <FDXShipDeleteRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXShipDeleteRequest.xsd">   <RequestHeader>     <CustomerTransactionIdentifier>Test Delete</CustomerTransactionIdentifier>     <AccountNumber>$accountNumber</AccountNumber>     <MeterNumber>$meterNumber</MeterNumber>     <CarrierCode>$carrier</CarrierCode>   </RequestHeader>  <TrackingNumber>470034028693</TrackingNumber> </FDXShipDeleteRequest> XMLREQUEST; 

The TrackingNumber is of course the tracking number you received when you scheduled the item to be shipped. The response is brief to say the least:

 <?xml version="1.0" encoding="UTF-8"?> <FDXShipDeleteReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXShipDeleteReply.xsd">   <ReplyHeader>     <CustomerTransactionIdentifier>Test Delete</CustomerTransactionIdentifier>   </ReplyHeader> </FDXShipDeleteReply> 

Had a CustomerTransactionIdentifier not been present, the response would have been practically non-existent. The code required to submit the request remains very similar to previous examples:

 echo "<h3>Request</h3>\n"; echo "<pre>\n"; print_r(simplexml_load_string($request)); echo "</pre>\n"; echo "<h3>Response</h3>\n"; $response = callFedEx($request); if (isset($response->Error->Code)) {   echo "There was a problem canceling that request"; }else {   echo "Shipment Cancelled"; } echo "<pre>"; print_r($response); echo "</pre>"; 

I've added a check for the error condition here just as an example to show how it would be done. As mentioned at the beginning of the chapter, the test API contains only very basic functionality, which doesn't appear to check for existence or even validity of the tracking number provided in the request. This makes it very difficult to test for an error condition (there is a sample response showing an error in the xml transaction guide provided by FedEx).




Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
ISBN: 764589547
EAN: N/A
Year: 2006
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net