[ic] Fedex www lookup

Bill Carr bill at bottlenose-wine.com
Tue Jun 15 15:31:12 UTC 2010


On Jun 15, 2010, at 10:44 AM, Peter wrote:

> On 16/06/10 02:08, Steve Graham wrote:
>> 
>>> 
>>> Do you use the CPAN Business::FedEx::DirectConnect perl module? The
>>> author might migrate the module to Web Services before the deadline
>>> and you'd be able to switch to that.
>>> 
>>> - Grant
>>> 
>> 
>>>> 
>> Yes I do use Business::FedEx::DirectConnect
>> Migrating the module to web services would be fantastic assuming that
>> will isolate this change by FedEx.
>> 
>> Jon
>> <<
>> 
>> 
>> Has anyone developed a drop in Fedex www module for the standard IC
>> store - I would be willing to kick in some funds for this.
>> It would be nice if it uses the cache data like the www ups module to
>> speed up requests, and fall back if fedex is offline for some reason.
> 
> I've made a start on one a while back, but it's not finished.  I think
> it was able to give some rate quotes or something before.  I'll toss it
> up tomorrow and you can see if you're interested in it.
I've been using this in production for a while now. I only use the getRates service.

I set it up in a way that's to specific to our setup but this should give you a good idea. Basically the parent Bottlenose module has a 'log' method and some default settings for 'key', 'password',  'account' and 'meter'. I think you could adjust the module below to make it look like something like Vend::Shipping::FedEx pretty easily.

I followed the steps in SOAP::WSDL::Manual and then made this module:

package Bottlenose::Shipping::FedEx;

# $Id: FedEx.pm 7747 2010-03-03 20:17:41Z bill $
use Object::InsideOut qw(Bottlenose::Shipping);
use warnings;
use strict;
use Carp;
use SOAP::WSDL;

use Bottlenose::Shipping::FedEx::Interfaces::RateService::RateServicePort;
my $interface
    = Bottlenose::Shipping::FedEx::Interfaces::RateService::RateServicePort
    ->new();

sub get_rates :MergeArgs {
    my $self = shift;
    my $opt  = shift;

    for (qw/key password account meter weight origin destination/) {
        my $get = qq{get_$_};
        $opt->{$_} ||= $self->$get || $::Variable->{ q{WI_FEDEX_} . uc($_) };
        croak qq{Required parameter $_ missing} unless $opt->{$_};
    }

    my $response = $interface->getRates(
        {

            # MyTypes::RateRequest
            WebAuthenticationDetail => {    # MyTypes::WebAuthenticationDetail
                UserCredential => {    # MyTypes::WebAuthenticationCredential
                    Key      => $opt->{key},         # string
                    Password => $opt->{password},    # string
                },
            },
            ClientDetail => {                        # MyTypes::ClientDetail
                AccountNumber => $opt->{account},    # string
                MeterNumber   => $opt->{meter},      # string
            },
            Version => {                             # MyTypes::VersionId
                ServiceId    => 'crs',               # string
                Major        => 7,                   # int
                Intermediate => 0,
                Minor        => 0
            },
            RequestedShipment => {
                TotalWeight => {                     # MyTypes::Weight
                    Units => 'LB',                   # WeightUnits
                    Value => $opt->{weight},         # decimal
                },
                PackagingType => 'YOUR_PACKAGING',
                Shipper       => {                   # MyTypes::Party
                    AccountNumber => $opt->{account},    # string
                    Address       => {                   # MyTypes::Address
                        PostalCode  => $opt->{origin},    # string
                        CountryCode => 'US',              # string
                        Residential => 0,                 # boolean
                    },
                },
                Recipient => {
                    Address => {
                        PostalCode  => $opt->{destination},    # string
                        CountryCode => 'US',                   # string
                        Residential => 1,                      # boolean
                    },
                },
                PackageDetail => 'PACKAGE_SUMMARY',
            }
        }
    );
    my $severity = $response->get_HighestSeverity;
    if ( $severity =~ /^ERROR|FAILURE|WARNING$/ ) {
        $self->log_notifications( $response->get_Notifications );
    }

    my $reply_details = $response->get_RateReplyDetails;
    do { $self->log('Could not get rate reply details'); return }
        unless ref $reply_details eq 'ARRAY';

    my $rates;
    for ( @$reply_details ) {
        $rates->{ $_->get_ServiceType->get_value }
            = $_->get_RatedShipmentDetails->[0]
            ->get_ShipmentRateDetail->get_TotalNetCharge->get_Amount
            ->get_value;
    }
    return $rates;
}

sub log_notifications {
    my $self  = shift;
    my $n_obj = shift;
    for ( @{$n_obj} ) {
        $self->log( $_->get_Message->get_value );
    }
}

1;

 
Bill Carr 
Bottlenose - Wine & Spirits eBusiness Specialists 
(413) 584-0400 



More information about the interchange-users mailing list