Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use GROUND_HOME_DELIVERY

  • Loading branch information...
commit ffe223795bf8b8704a45dc170a8c4cbda85fa320 1 parent cb427f0
@jazminschroeder authored
Showing with 83 additions and 28 deletions.
  1. +10 −2 lib/fedex/shipment.rb
  2. +73 −26 spec/fedex_spec.rb
View
12 lib/fedex/shipment.rb
@@ -64,7 +64,7 @@ def process_request
rate_details = [response[:rate_reply][:rate_reply_details][:rated_shipment_details]].flatten.first[:shipment_rate_detail]
rate = Fedex::Rate.new(rate_details)
else
- error_message = (response[:rate_reply].nil? ? api_response["Fault"]["detail"]["fault"]["details"]["ValidationFailureDetail"]["message"] : response[:rate_reply][:notifications][:message]) rescue "Unexpected error has occurred..."
+ error_message = (response[:rate_reply].nil? ? api_response["Fault"]["detail"]["fault"]["details"]["ValidationFailureDetail"]["message"] : [response[:rate_reply][:notifications]].flatten.first[:message]) rescue "Unexpected error has occurred"
raise RateError, error_message
end
end
@@ -129,7 +129,7 @@ def add_version(xml)
def add_requested_shipment(xml)
xml.RequestedShipment{
xml.DropoffType @shipping_options[:drop_off_type] ||= "REGULAR_PICKUP"
- xml.ServiceType @service_type
+ xml.ServiceType service_type
xml.PackagingType @shipping_options[:packaging_type] ||= "YOUR_PACKAGING"
add_shipper(xml)
add_recipient(xml)
@@ -276,5 +276,13 @@ def success?(response)
(!response[:rate_reply].nil? and %w{SUCCESS WARNING NOTE}.include? response[:rate_reply][:highest_severity])
end
+ # Use GROUND_HOME_DELIVERY for shipments going to a residential address within the US.
+ def service_type
+ if @recipient[:residential].to_s =~ /true/i and @service_type =~ /GROUND/i and @recipient[:country_code] =~ /US/i
+ "GROUND_HOME_DELIVERY"
+ else
+ @service_type
+ end
+ end
end
end
View
99 spec/fedex_spec.rb
@@ -1,8 +1,13 @@
require 'spec_helper'
describe Fedex::Shipment do
let(:test_keys) do
- {:key => "RSkI5uThcfmtpm3I", :password => "RHhaZOG1MpDJ6QvSzxG0N06Ue", :account_number => "510087143", :meter => "118546765", :mode => "test"}
+ {:key => "11111", :password => "11111", :account_number => "11111", :meter => "11111", :mode => "test"}
end
+
+ let(:production_keys) do
+ {:key => "11111", :password => "11111", :account_number => "11111", :meter => "11111", :mode => "production"}
+ end
+
context "missing required parameters" do
it "should raise Fedex::Rate exception" do
lambda{ Fedex::Shipment.new}.should raise_error(Fedex::RateError)
@@ -14,38 +19,80 @@
it "should create a valid instance" do
subject.should be_an_instance_of(Fedex::Shipment)
end
- end
-
- before(:each) do
- @fedex = Fedex::Shipment.new(test_keys)
- @shipper = {:name => "Sender", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Harrison", :state => "AR", :postal_code => "72601", :country_code => "US"}
- @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"}
- @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" } }
- @shipping_options = { :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
end
- context "Domestic Shipment" do
- describe "rate" do
- it "should return rate" do
- rate = @fedex.rate({:shipper=>@shipper, :recipient => @recipient, :packages => @packages, :service_type => "FEDEX_GROUND"})
- rate.should be_an_instance_of(Fedex::Rate)
+ context "Published Rates(Development Mode)" do
+ before(:each) do
+ @fedex = Fedex::Shipment.new(test_keys)
+ @shipper = {:name => "Sender", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Harrison", :state => "AR", :postal_code => "72601", :country_code => "US"}
+ @recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Frankin Park", :state => "IL", :postal_code => "60131", :country_code => "US", :residential => true }
+ @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" } }
+ @shipping_options = { :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
+ end
+
+ context "Domestic Shipment" do
+ describe "rate" do
+ it "should return rate" do
+ rate = @fedex.rate({:shipper=>@shipper, :recipient => @recipient, :packages => @packages, :service_type => "FEDEX_GROUND"})
+ rate.should be_an_instance_of(Fedex::Rate)
+ puts rate.total_net_charge
+
+ end
end
end
+
+ context "Canadian Shipment" do
+ describe "rate" do
+ it "shoule return international fees" do
+ recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC",
+ :postal_code => "V7C4V4", :country_code => "CA", :residential => "true" }
+ rate = @fedex.rate({:shipper => @shipper, :recipient => recipient, :packages => @packages, :service_type => "FEDEX_GROUND", :shipping_options => @shipping_options })
+ rate.should be_an_instance_of(Fedex::Rate)
+ puts rate.total_net_charge
+ end
+ end
+ end
end
- context "Canadian Shipment" do
- describe "rate" do
- it "shoule return international fees" do
- recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC",
- :postal_code => "V7C4V4", :country_code => "CA", :residential => false }
- rate = @fedex.rate({:shipper => @shipper, :recipient => recipient, :packages => @packages, :service_type => "FEDEX_GROUND", :shipping_options => @shipping_options })
- rate.should be_an_instance_of(Fedex::Rate)
+ context "Discounted Rates(Production Mode)" do
+ before(:each) do
+ @fedex = Fedex::Shipment.new(production_keys)
+ @shipper = {:name => "Sender", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Harrison", :state => "AR", :postal_code => "72601", :country_code => "US"}
+ @recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Frankin Park", :state => "IL", :postal_code => "60131", :country_code => "US", :residential => true }
+ @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" } }
+ @shipping_options = { :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
+ end
+
+ context "Domestic Shipment" do
+ describe "rate" do
+ it "should return rate" do
+ rate = @fedex.rate({:shipper=>@shipper, :recipient => @recipient, :packages => @packages, :service_type => "FEDEX_GROUND"})
+ rate.should be_an_instance_of(Fedex::Rate)
+ puts rate.total_net_charge
+
+ end
end
end
- end
+ context "Canadian Shipment" do
+ describe "rate" do
+ it "shoule return international fees" do
+ recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC",
+ :postal_code => "V7C4V4", :country_code => "CA", :residential => "true" }
+ rate = @fedex.rate({:shipper => @shipper, :recipient => recipient, :packages => @packages, :service_type => "FEDEX_GROUND", :shipping_options => @shipping_options })
+ rate.should be_an_instance_of(Fedex::Rate)
+ puts rate.total_net_charge
+ end
+ end
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.