public
Description: Shipping API extension for Active Merchant.
Clone URL: git://github.com/Shopify/active_shipping.git
Location#address_type for UPS residential/commercial distinction
jamesmacaulay (author)
Wed Jun 11 14:23:30 -0700 2008
commit  c9d609983956292c8ea58289857ae714471b54c7
tree    79e41d8e63763818cfa2fc22ebbc287d7a0b67e1
parent  7f0640129e6f71d2da4e150428441ad414e07a95
...
199
200
201
 
202
203
204
...
199
200
201
202
203
204
205
0
@@ -199,6 +199,7 @@ module ActiveMerchant
0
               # StateProvinceCode required for negotiated rates but not otherwise, for some reason
0
             address << XmlNode.new("PostalCode", location.postal_code) unless location.postal_code.blank?
0
             address << XmlNode.new("CountryCode", location.country_code(:alpha2)) unless location.country_code(:alpha2).blank?
0
+ address << XmlNode.new("ResidentialAddressIndicator", true) if location.residential?
0
             # not implemented: Shipment/(Shipper|ShipTo|ShipFrom)/Address/ResidentialAddressIndicator element
0
           end
0
         end
...
11
12
13
14
 
 
15
16
17
...
31
32
33
 
34
35
36
...
44
45
46
47
 
 
48
49
50
...
61
62
63
 
64
65
66
...
68
69
70
 
 
 
 
 
 
 
 
71
72
73
...
11
12
13
 
14
15
16
17
18
...
32
33
34
35
36
37
38
...
46
47
48
 
49
50
51
52
53
...
64
65
66
67
68
69
70
...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
0
@@ -11,7 +11,8 @@ module ActiveMerchant #:nodoc:
0
                   :address2,
0
                   :address3,
0
                   :phone,
0
- :fax
0
+ :fax,
0
+ :address_type
0
       
0
       alias_method :zip, :postal_code
0
       alias_method :postal, :postal_code
0
@@ -31,6 +32,7 @@ module ActiveMerchant #:nodoc:
0
         @address3 = options[:address3]
0
         @phone = options[:phone]
0
         @fax = options[:fax]
0
+ @address_type = %{residential commercial}.include?(options[:address_type].to_s) ? options[:address_type] : raise ArgumentError.new('address_type must be either "residential" or "commercial"')
0
       end
0
       
0
       def self.from(object, options={})
0
@@ -44,7 +46,8 @@ module ActiveMerchant #:nodoc:
0
           :address2 => [:address2],
0
           :address3 => [:address3],
0
           :phone => [:phone, :phone_number],
0
- :fax => [:fax, :fax_number]
0
+ :fax => [:fax, :fax_number],
0
+ :address_type => [:address_type]
0
         }
0
         attributes = {}
0
         hash_access = begin
0
@@ -61,6 +64,7 @@ module ActiveMerchant #:nodoc:
0
             end
0
           end
0
         end
0
+ attributes.delete(:address_type) unless %{residential commercial}.include?(attributes[:address_type].to_s)
0
         self.new(attributes.update(options))
0
       end
0
       
0
@@ -68,6 +72,14 @@ module ActiveMerchant #:nodoc:
0
         @country.nil? ? nil : @country.code(format).first.value
0
       end
0
       
0
+ def residential?
0
+ @address_type == 'residential'
0
+ end
0
+
0
+ def commercial?
0
+ @address_type == 'commercial'
0
+ end
0
+
0
       def to_s
0
         prettyprint.gsub(/\n/, ' ')
0
       end

Comments

    No one has commented yet.