Method: ActiveShipping::UPS#build_location_node

Defined in:
lib/active_shipping/carriers/ups.rb

#build_location_node(xml, name, location, options = {}) ⇒ Object (protected)



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/active_shipping/carriers/ups.rb', line 639

def build_location_node(xml, name, location, options = {})
  # not implemented:  * Shipment/Shipper/Name element
  #                   * Shipment/(ShipTo|ShipFrom)/CompanyName element
  #                   * Shipment/(Shipper|ShipTo|ShipFrom)/AttentionName element
  #                   * Shipment/(Shipper|ShipTo|ShipFrom)/TaxIdentificationNumber element
  xml.public_send(name) do
    if shipper_name = (location.name || location.company_name || options[:origin_name])
      xml.Name(shipper_name)
    end
    xml.PhoneNumber(location.phone.gsub(/[^\d]/, '')) unless location.phone.blank?
    xml.FaxNumber(location.fax.gsub(/[^\d]/, '')) unless location.fax.blank?

    if name == 'Shipper' and ( = options[:origin_account] || @options[:origin_account])
      xml.ShipperNumber()
    elsif name == 'ShipTo' and ( = options[:destination_account] || @options[:destination_account])
      xml.ShipperAssignedIdentificationNumber()
    end

    if name = (location.company_name || location.name || options[:origin_name])
      xml.CompanyName(name)
    end

    if phone = location.phone
      xml.PhoneNumber(phone)
    end

    if attn = location.name
      xml.AttentionName(attn)
    end

    xml.Address do
      xml.AddressLine1(location.address1) unless location.address1.blank?
      xml.AddressLine2(location.address2) unless location.address2.blank?
      xml.AddressLine3(location.address3) unless location.address3.blank?
      xml.City(location.city) unless location.city.blank?
      xml.StateProvinceCode(location.province) unless location.province.blank?
      # StateProvinceCode required for negotiated rates but not otherwise, for some reason
      xml.PostalCode(location.postal_code) unless location.postal_code.blank?
      xml.CountryCode(mapped_country_code(location.country_code(:alpha2))) unless location.country_code(:alpha2).blank?
      xml.ResidentialAddressIndicator(true) unless location.commercial? # the default should be that UPS returns residential rates for destinations that it doesn't know about
      # not implemented: Shipment/(Shipper|ShipTo|ShipFrom)/Address/ResidentialAddressIndicator element
    end
  end
end