Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

fedex

Ruby library to interact with FedEx Rate Web Service

Subscribe to updates I use fedex


Statistics on fedex

Number of watchers on Github 1
Number of open issues 1
Main language Ruby
Average time to merge a PR about 5 hours
Open pull requests 1+
Closed pull requests 2+
Last commit over 1 year ago
Repo Created over 6 years ago
Repo Last Updated over 2 years ago
Size 286 KB
Organization / Authorstitchfix
Contributors13
Page Updated
Do you use fedex? Leave a review!
View fedex activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating fedex for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Fedex Rate Web Service

For more information visit Fedex Web Services for Shipping.

This version uses the Non-SOAP Web Services so there is no need to download the Fedex WSDL files, note however that you will need to apply for development/production credentials.

Note: Please make sure to test your results.

Installation:

Rails 3.x using Bundler's Gemfile:

gem 'fedex'

Rails 2.x or without Rails or Bundler:

gem install fedex

Usage example:

Define the shipper:

shipper = { :name => "Sender",
            :company => "Company",
            :phone_number => "555-555-5555",
            :address => "Main Street",
            :city => "Harrison",
            :state => "AR",
            :postal_code => "72601",
            :country_code => "US" }

Define the recipient:

recipient = { :name => "Recipient",
              :company => "Company",
              :phone_number => "555-555-5555",
              :address => "Main Street",
              :city => "Franklin Park",
              :state => "IL",
              :postal_code => "60131",
              :country_code => "US",
              :residential => "false" }

Define the packages; multiple packages in a single shipment are allowed: Note that all the dimensions must be integers.

packages = []
packages << {
  :weight => {:units => "LB", :value => 2},
  :dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" }
}
packages << {
  :weight => {:units => "LB", :value => 6},
  :dimensions => {:length => 5, :width => 5, :height => 4, :units => "IN" }
}

By default packaging type is YOUR PACKAGING and the drop off type is REGULAR PICKUP. If you need something different you can pass an extra hash for shipping options

shipping_options = {
  :packaging_type => "YOUR_PACKAGING",
  :drop_off_type => "REGULAR_PICKUP"
}

Create a Fedex::Shipment object using your FedEx credentials; mode should be either production or development depending on what Fedex environment you want to use.

require 'fedex'
fedex = Fedex::Shipment.new(:key => 'xxx',
                            :password => 'xxxx',
                            :account_number => 'xxxx',
                            :meter => 'xxx',
                            :mode => 'production')

** Getting Shipping Rates **

To find a shipping rate:

rate = fedex.rate(:shipper=>shipper,
                  :recipient => recipient,
                  :packages => packages,
                  :service_type => "FEDEX_GROUND",
                  :shipping_options => shipping_options)

Fedex provides multiple total values; total_net_charge is the final amount you are looking for.

    $ rate.total_net_charge => "34.03"
    # Complete response
    $ <Fedex::Rate:0x1019ba5f8
          @total_net_charge="34.03",
          @total_surcharges="1.93",
          @total_billing_weight="8.0 LB",
          @total_taxes="0.0",
          @rate_type="PAYOR_ACCOUNT_PACKAGE",
          @total_base_charge="32.1",
          @total_freight_discounts=nil,
          @total_net_freight="32.1",
          @rate_zone="51">

** Get a Transit time **

ship = fedex.ship(:shipper=>shipper,
                  :recipient => recipient,
                  :packages => packages,
                  :service_type => "FEDEX_GROUND",
                  :shipping_options => shipping_options)
puts ship[:completed_shipment_detail][:operational_detail] [:transit_time]

Above code will give you the transit time.

** Generate a shipping label (PDF) **

To create a label for a shipment:

label = fedex.label(:filename => "my_dir/example.pdf",
                    :shipper=>shipper,
                    :recipient => recipient,
                    :packages => packages,
                    :service_type => "FEDEX_GROUND",
                    :shipping_options => shipping_options)

** Generate a shipping label in any available format **

Change the filename extension and pass a label_specification hash. For example:

example_spec = {
  :image_type => "EPL2",
  :label_stock_type => "STOCK_4X6"
}

label = fedex.label(:filename => "my_dir/example_epl2.pcx",
                    :shipper=>shipper,
                    :recipient => recipient,
                    :packages => packages,
                    :service_type => "FEDEX_GROUND",
                    :shipping_options => shipping_options,
                    :label_specification => example_spec)

** Storing a label on Amazon S3 with Paperclip **

This is useful when you need to store the labels for later use, and are hosting your application on Heroku as they do not allow writing to the filesystem, save the tmp directory. With Paperclip setup up on a shipment model:

label = fedex.label(:filename => "tmp/example_label.pdf",
                    :shipper=>shipper,
                    :recipient => recipient,
                    :packages => packages,
                    :service_type => "FEDEX_GROUND",
                    :shipping_options => shipping_options,
                    :label_specification => example_spec)

Then attach the label to your Paperclip model:

shipment.fedex_label = label.file_name
shipment.save!

Documentation for setting up Paperclip with Amazon S3 can be found in the Paperclip README.

** Tracking a shipment **

To track a shipment:

results = fedex.track(:tracking_number => "1234567890123")
# => [#<Fedex::TrackingInformation>]

# Pull the first result from the returned array
#
tracking_info = results.first

tracking_info.tracking_number
# => "1234567890123"

tracking_info.status
# => "Delivered"

tracking_info.events.first.description
# => "On FedEx vehicle for delivery"

** Verifying an address **

To verify an address is valid and deliverable:


address = {
  :street      => "5 Elm Street",
  :city        => "Norwalk",
  :state       => "CT",
  :postal_code => "06850",
  :country     => "USA"
}

address_result = fedex.validate_address(:address => address)

address_result.residential
# => true

address_result.score
# => 100

address_result.postal_code
# => "06850-3901"

Services/Options Available

Fedex::Shipment::SERVICE_TYPES
Fedex::Shipment::PACKAGING_TYPES
Fedex::Shipment::DROP_OFF_TYPES

Contributors:

Copyright/License:

Copyright 2011 Jazmin Schroeder

This gem is made available under the MIT license.

fedex open pull requests (View All Pulls)
  • added the shipped_at method
fedex questions on Stackoverflow (View All Questions)
  • Fedex API process tag request error
  • Fedex how to set preferred currency in PHP
  • FedEx Ship (LTL) response with one FREIGHT_ADDRESS_LABEL
  • Error in fedex shipping method in magento
  • Is there anyway to get the label information by tracking number from UPS, USPS, FEDEX, etc?
  • fedex shipping web service, test account authentication failed
  • How do i view xml when i ship fedex?
  • Fedex API Rate request issues, php
  • Validate Fedex Location Search Request
  • Prestashop Fedex integration error
  • FedEx post-order process in Magento 1.9
  • Python - FedEx Rate Services API doesn't return any service on weekends
  • Is FedEx shipping api works in India Domestic
  • I am facing an issue to integrate FedEx with Magento 1.9 for domestic India
  • Integration of FedEx SOAP WS with Spring Restful WS Project
  • FedEx web Integration ERROR CODE 9004
  • Is Magento reaching out to Fedex and UPS on each product page load?
  • Magento Fedex currency
  • FEDEX shipment rate details missing in Shipping Label generation for Third party payment
  • FedEx TransitTime element from RateReply - business or normal days
  • FedEx PHP Soap "Could not connect to host"
  • FedEx API using PHP and Saturday Shipping
  • FedEx WSDL help on ASP.NET (VB) Web App
  • Validate shipping address using fedex API
  • How to get label using FedEx Web Services?
  • Fedex Shipping error in opencart
  • Fedex API - Authentication Failed for creating shipping labels only
  • Active Shipping gem - Find rates to multiple products in the same package using Fedex
  • FedEx API merge PDFs (Shipping Labels) PHP
  • Fedex Shipping not showing on the Magento Website Frontend
fedex list of languages used
Other projects in Ruby