Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FedEx: Pass Residential true unless localtion is commerial

closes #31
  • Loading branch information...
commit 933147c3da85af814af090f94df1e068e70c8b3a 1 parent f7e89a7
@jduff jduff authored
View
2  lib/active_shipping/shipping/carriers/fedex.rb
@@ -218,6 +218,8 @@ def build_location_node(name, location)
xml_node << XmlNode.new('Address') do |address_node|
address_node << XmlNode.new('PostalCode', location.postal_code)
address_node << XmlNode.new("CountryCode", location.country_code(:alpha2))
+
+ address_node << XmlNode.new("Residential", true) unless location.commercial?
end
end
end
View
29 lib/active_shipping/shipping/location.rb
@@ -14,13 +14,15 @@ class Location
:address3,
:phone,
:fax,
- :address_type
+ :address_type,
+ :company_name
alias_method :zip, :postal_code
alias_method :postal, :postal_code
alias_method :state, :province
alias_method :territory, :province
alias_method :region, :province
+ alias_method :company, :company_name
def initialize(options = {})
@country = (options[:country].nil? or options[:country].is_a?(ActiveMerchant::Country)) ?
@@ -41,6 +43,8 @@ def initialize(options = {})
raise ArgumentError.new("address_type must be one of #{ADDRESS_TYPES.map(&:inspect).join(', ')}")
end
end
+
+ @company_name = options[:company_name] || options[:company]
end
def self.from(object, options={})
@@ -56,7 +60,8 @@ def self.from(object, options={})
:address3 => [:address3],
:phone => [:phone, :phone_number],
:fax => [:fax, :fax_number],
- :address_type => [:address_type]
+ :address_type => [:address_type],
+ :company_name => [:company, :company_name]
}
attributes = {}
hash_access = begin
@@ -84,6 +89,24 @@ def country_code(format = :alpha2)
def residential?; @address_type == 'residential' end
def commercial?; @address_type == 'commercial' end
def po_box?; @address_type == 'po_box' end
+
+
+ def to_hash
+ {
+ :country => country_code,
+ :postal_code => postal_code,
+ :province => province,
+ :city => city,
+ :name => name,
+ :address1 => address1,
+ :address2 => address2,
+ :address3 => address3,
+ :phone => phone,
+ :fax => fax,
+ :address_type => address_type,
+ :company_name => company_name
+ }
+ end
def to_s
prettyprint.gsub(/\n/, ' ')
@@ -106,4 +129,4 @@ def inspect
end
end
-end
+end
View
68 test/fixtures/xml/fedex/ottawa_to_beverly_hills_commercial_rate_request.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<RateRequest xmlns="http://fedex.com/ws/rate/v6">
+ <WebAuthenticationDetail>
+ <UserCredential>
+ <Key>1111</Key>
+ <Password>2222</Password>
+ </UserCredential>
+ </WebAuthenticationDetail>
+ <ClientDetail>
+ <AccountNumber>3333</AccountNumber>
+ <MeterNumber>4444</MeterNumber>
+ </ClientDetail>
+ <TransactionDetail>
+ <CustomerTransactionId>ActiveShipping</CustomerTransactionId>
+ </TransactionDetail>
+ <Version>
+ <ServiceId>crs</ServiceId>
+ <Major>6</Major>
+ <Intermediate>0</Intermediate>
+ <Minor>0</Minor>
+ </Version>
+ <ReturnTransitAndCommit>true</ReturnTransitAndCommit>
+ <VariableOptions>SATURDAY_DELIVERY</VariableOptions>
+ <RequestedShipment>
+ <ShipTimestamp>2009-07-20T12:01:55-04:00</ShipTimestamp>
+ <DropoffType>REGULAR_PICKUP</DropoffType>
+ <PackagingType>YOUR_PACKAGING</PackagingType>
+ <Shipper>
+ <Address>
+ <PostalCode>K1P 1J1</PostalCode>
+ <CountryCode>CA</CountryCode>
+ <Residential>true</Residential>
+ </Address>
+ </Shipper>
+ <Recipient>
+ <Address>
+ <PostalCode>90210</PostalCode>
+ <CountryCode>US</CountryCode>
+ </Address>
+ </Recipient>
+ <RateRequestTypes>ACCOUNT</RateRequestTypes>
+ <PackageCount>2</PackageCount>
+ <RequestedPackages>
+ <Weight>
+ <Units>KG</Units>
+ <Value>0.25</Value>
+ </Weight>
+ <Dimensions>
+ <Length>19</Length>
+ <Width>14</Width>
+ <Height>2</Height>
+ <Units>CM</Units>
+ </Dimensions>
+ </RequestedPackages>
+ <RequestedPackages>
+ <Weight>
+ <Units>KG</Units>
+ <Value>3.402</Value>
+ </Weight>
+ <Dimensions>
+ <Length>39</Length>
+ <Width>26</Width>
+ <Height>12</Height>
+ <Units>CM</Units>
+ </Dimensions>
+ </RequestedPackages>
+ </RequestedShipment>
+</RateRequest>
View
2  test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml
@@ -29,12 +29,14 @@
<Address>
<PostalCode>K1P 1J1</PostalCode>
<CountryCode>CA</CountryCode>
+ <Residential>true</Residential>
</Address>
</Shipper>
<Recipient>
<Address>
<PostalCode>90210</PostalCode>
<CountryCode>US</CountryCode>
+ <Residential>true</Residential>
</Address>
</Recipient>
<RateRequestTypes>ACCOUNT</RateRequestTypes>
View
18 test/remote/fedex_test.rb
@@ -131,5 +131,19 @@ def test_tracking
@carrier.find_tracking_info('077973360403984', :test => true)
end
end
-
-end
+
+ def test_different_rates_for_commercial
+ residential_response = @carrier.find_rates(
+ @locations[:beverly_hills],
+ @locations[:ottawa],
+ @packages.values_at(:chocolate_stuff)
+ )
+ commercial_response = @carrier.find_rates(
+ @locations[:beverly_hills],
+ Location.from(@locations[:ottawa].to_hash, :address_type => :commercial),
+ @packages.values_at(:chocolate_stuff)
+ )
+
+ assert_not_equal residential_response.rates.map(&:price), commercial_response.rates.map(&:price)
+ end
+end
View
12 test/unit/carriers/fedex_test.rb
@@ -50,6 +50,18 @@ def test_find_tracking_info_should_not_include_events_without_an_address
end
end
+ def test_building_request_with_address_type_commercial_should_not_include_residential
+ mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
+ expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_commercial_rate_request')
+ Time.any_instance.expects(:to_xml_value).returns("2009-07-20T12:01:55-04:00")
+
+ @carrier.expects(:commit).with {|request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode}.returns(mock_response)
+ destination = ActiveMerchant::Shipping::Location.from(@locations[:beverly_hills].to_hash, :address_type => :commercial)
+ response = @carrier.find_rates( @locations[:ottawa],
+ destination,
+ @packages.values_at(:book, :wii), :test => true)
+ end
+
def test_building_request_and_parsing_response
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_rate_request')
mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
View
10 test/unit/location_test.rb
@@ -53,4 +53,12 @@ def test_name_is_nil_if_not_provided
location = Location.from({})
assert_nil location.name
end
-end
+
+ def test_location_with_company_name
+ location = Location.from(:company => "Mine")
+ assert_equal "Mine", location.company_name
+
+ location = Location.from(:company_name => "Mine")
+ assert_equal "Mine", location.company_name
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.