NAME

Business::FedEx::DirectConnect - FedEx Ship Manager Direct Connect

SYNOPSIS

use Business::FedEx::DirectConnect;

my $t = Business::FedEx::DirectConnect->new(uri=>'https://gatewaybeta.fedex.com/GatewayDC'
				,acc => '' #FedEx Account Number
				,meter => '' #FedEx Meter Number (This is given after you subscribe to FedEx)
				,referer => 'Vermonster' # Name or Company
				,host=> 'gatewaybeta.fedex.com' #Host
				);

# 2016 is the UTI for FedEx.  If you don't know what this is
# you need to read the FedEx Documentation.
# http://www.fedex.com/globaldeveloper/shipapi/
# The hash values are case insensitive.
$t->set_data(2016,
'customer_transaction_identifier' => 'unique1234'
'sender_company' => 'Vermonster LLC',
'sender_address_line_1' => '312 stuart st',
'sender_city' => 'Boston',
'sender_state' => 'MA',
'sender_postal_code' => '02134',
'recipient_contact_name' => 'Jay Powers',
'recipient_addre  _line_1' => '44 main street',
'recipient_city' => 'boston',
'recipient_state' => 'MA',
'recipient_postal_code' => '02116',
'recipient_phone_number' => '6173335555',
'weight_units' => 'lbs',
'sender_country_code' => 'US',
'recipient_country' => 'US',
'sender_phone_number' => '6175556985',
'future_day_shipment' => 'y',
'packaging_type' => '01',
'service_type' => '03',
'total_package_weight' => '1.0',
'label_type' => '1',
'label_printer_type' => '1',
'label_media_type' => '5',
'ship_date' => '20020828',
'customs_declared_value_currency_type' => 'USD',
'package_total' => 1
) or die $t->errstr;

$t->transaction() or die $t->errstr;

print $t->lookup('tracking_number');

$t->label("myLabel.png");

DESCRIPTION

This module provides the necessary requirements to send transactions to FedEx's Ship Manager Direct API. Precautions have been taken to enforce FedEx's API guidelines to allow for all transaction types. This module is an alternative to using the FedEx Ship Manager API ATOM product. Business::FedEx::DirectConnect will provide the necessary communication using LWP and Crypt::SSLeay. The main advantage is you will no longer need to install the JRE dependant API provided by FedEx. Instead, data is POST(ed) directly to the FedEx transaction servers.

When using this module please keep in mind FedEx will occasionally change some of the transaction codes for their API. This should not break existing code, but it is a good idea to check out changes when possible. I document all the changes in a "Changes" log.

REQUIREMENTS

In order to submit a transaction to FedEx's Gateway server you must have a valid FedEx Account Number and a FedEx Meter Number. To gain access and receive a Meter Number you must send a Subscribe request to FedEx containing your FedEx account number and contact information. There is an example of this request below. FedEx has two API servers a live one (https://gateway.fedex.com/GatewayDC) and a beta for testing (https://gatewaybeta.fedex.com/GatewayDC). You will need to subscribe to each server you intend to use. FedEx will also require you to send a batch of defined data to their live server in order to become certified for live label creation. This module uses LWP to POST request information so it is a requirement to have LWP installed. Also, you will need SSL encryption to access https URIs. I recommend installing Crypt::SSLeay Please refer to the FedEx documentation at http://www.fedex.com/globaldeveloper/shipapi/ Here you will find more information about using the FedEx API. You will need to know what UTI is needed to send your request.

Here is a sample Subscription Transaction

$t->set_data(3003,
1 => 'unique12345',
4003 => 'John Doe',
4008 => '123 Main St',
4011 => 'Boston',
4012 => 'MA',
4013 => '02116',
4014 => 'US',
4015 => '6175551111',
) or die $t->errstr;

This call will return a FedEx Meter number so you can use the FedEx API. The meter number will be referenced in field 498. $t->lookup(498);

FedEx UTI

Sited from FedEx Documentation. See http://www.fedex.com/globaldeveloper/shipapi/ for more information.

"The Universal Transaction Identifier (UTI) is a unique integral code that has been assigned to a given transaction type. For example, the UTI of the tagged Transaction Type "021" (FedEx Express global Ship a Package Request) is 2016. UTIs are unique not just within the tagged transaction set, but across all transaction sets that have been or will be approved for transmission via the API. The UTI accompanying a transaction indicates where it should be routed within the FedEx systems. The FedEx server recognizes the UTI passed and will direct the request to the correct business server."

Valid UTIs are listed below:

uti = request / reply Carrier Description

1002 = 007 / 107 FDXG End-of-day close
1005 = 023 / 123 FDXE FedEx Express Delete-A-Package
2016 = 021 / 121 FDXE FedEx Express Ship-A-Package
2017 = 022 / 122 FDXE Global Rate-A-Package
2018 = 019 / 119 FDXE Service Availability
2024 = 025 / 125 ALL Rate Available Services
3000 = 021 / 121 FDXE FedEx Ground Ship-A-Package
3001 = 023 / 123 FDXG FedEx Ground Delete-A-Package
3003 = 211 / 311 ALL Subscription
3004 = 022 / 122 FDXG Global Rate-A-Package
5000 = 402 / 502 ALL Track By Number, Destination, Ship Date, and Reference
5001 = 405 / 505 ALL Signature Proof of Delivery

COMMON METHODS

The methods described in this section are available for all FedEx::DirectConnect objects.

$t->set_data(UTI, $hash)

This method will accept a valid FedEx UTI number and a hash of values. The first arg must be a valid UTI. Using these values set_data will construct and return a valid FedEx request string. Assuming you pass a valid FedEx UTI this method will find the correct Transaction Number for you. You need not pass this in. Also no need to pass in your FedEx Account Number or Meter Number. You should pass these when creating a new Business::FedEx::DirectConnect object. This method will allow you to use either the number field provided in the FedEx documentation or the hash (case insensitive) $FE_RE found in Business::FedEx::Constants.

Here is a tracking example where 29 is the "tracking number" field FedEx has provided.

$t->set_data(5000, 'tracking_number'=>'836603877972') or die $t->errstr;

is the same as

$t->set_data(5000, 29 =>'836603877972') or die $t->errstr;
$t->required(UTI)

Method to return the required fields for a given FedEx UTI.

$t->transaction()

Send transaction to FedEx. Optionally you can pass the full request string if you choose not to use the set_data method. Returns the full reply from FedEx.

$t->label('someLabel.png')

This method will decode the binary image data from FedEx and save it to a file. If nothing is passed the binary data string will be returned.

$t->lookup('tracking_number')

This method will return the value for an item returned from FedEx. Refer to the Business::FedEx::Constants $FE_RE hash to see all possible values.

$t->rbuf()

Returns the decoded string portion of the FedEx reply.

$t->hash_ret()

Returns a hash of the FedEx reply values

my $stuff= $t->hash_ret;

foreach (keys %{$stuff}) {
	print $_. ' => ' . $stuff->{$_} . "\n";
}

IDEAS/TODO

Build methods for each type of transaction so you don't need to know UTIs and other FedEx codes. FedEx Express Ship-A-Package UTI 2016 would be called via $object->FDXE_ship();

Build for multiple request. FedEx currently can only accept one transaction per request. I might try something with LWP::Parallel::UserAgent.

AUTHOR

Jay Powers, <jpowers@cpan.org>

http://www.vermonster.com/perl

Copyright (c) 2003 Jay Powers

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself

If you have any questions, comments or suggestions please feel free to contact me.

SEE ALSO

Business::FedEx::Constants