gem install ShippingInfo
For more information visit Fedex Web Services for Shipping. This will use FEDEX API to get the shipment information, you will need a Fedex developer/production credentials.
Use Shipping_Info method.
def Shipping_Info (fromZipCode, toZipCode, weight)
where fromZipCode => source zipcode, toZipCode => destination zipcode, and weight => package weight in LB
Define the shipper:
shipper = { :name => "Sender",
:company => "Catprint",
:phone_number => "555-555-5555",
:address => "None",
:city => "None",
:state => "#{fromState}",
:postal_code => "#{fromZipCode}",
:country_code => "US"
}
Define the recipient:
recipient = { :name => "Recipient",
:company => "Company",
:phone_number => "555-555-5555",
:address => "Main Street",
:city => "None",
:state => "#{toState}",
:postal_code => "#{toZipCode}",
: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 details
shipping_details = {
: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')
To find a shipping rate:
rate = fedex.rate(:shipper=>shipper,
:recipient => recipient,
:packages => packages,
:service_type => "FEDEX_GROUND",
:shipping_details => shipping_details)
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 the Transit Time by
ship = fedex.ship(:shipper=>shipper,
:recipient => recipient,
:packages => packages,
:service_type => "FEDEX_GROUND",
:shipping_details => shipping_details)
puts ship[:completed_shipment_detail][:operational_detail] [:transit_time]
UPS shipping information, get UPS shipping rate and transit time.
access_options = { :access_license_number => '9CA349F0CB25A9DB',
:user_id => 'piyushkp',
:password => 'Admin123#',
:order_cutoff_time => 17 ,
:sender_city => 'None',
:sender_state => Fedex::UpsInfo.state_from_zip("#{fromZipCode}"),
:sender_zip => "#{fromZipCode}",
:sender_country_code => 'US'
}
request_options = { :total_packages => 1,
:unit_of_measurement => 'LBS',
:weight => 10,
:city => 'None',
:state => Fedex::UpsInfo.state_from_zip("#{toZipCode}"),
:zip => "#{toZipCode}",
:country_code => 'US',
:mode => 'test'
}
upsInfo = Fedex::UpsInfo.new(access_options)
"UPS Price" => upsInfo.getPrice(request_options)
"UPS GND Transit days" => upsInfo.getTransitTime(request_options)
- Piyush Patel (Piyush Patel)
Copyright 2012 Piyush Patel
This gem is made available under the MIT license.