lib/fedex/request/base.rb in fedex-3.0.0 vs lib/fedex/request/base.rb in fedex-3.1.0

- old
+ new

@@ -45,10 +45,14 @@ requires!(options, :shipper, :recipient, :packages, :service_type) @credentials = credentials @shipper, @recipient, @packages, @service_type, @customs_clearance, @debug = options[:shipper], options[:recipient], options[:packages], options[:service_type], options[:customs_clearance], options[:debug] @debug = ENV['DEBUG'] == 'true' @shipping_options = options[:shipping_options] ||={} + # Expects hash with addr and port + if options[:http_proxy] + self.class.http_proxy options[:http_proxy][:host], options[:http_proxy][:port] + end end # Sends post request to Fedex web service and parse the response. # Implemented by each subclass def process_request @@ -76,11 +80,11 @@ xml.LocaleCode 'us' # United States } } end - # Add Version to xml request, using the latest version V10 Sept/2011 + # Add Version to xml request, using the version identified in the subclass def add_version(xml) xml.Version{ xml.ServiceId service[:id] xml.Major service[:version] xml.Intermediate 0 @@ -147,12 +151,23 @@ # Add shipping charges to xml request def add_shipping_charges_payment(xml) xml.ShippingChargesPayment{ xml.PaymentType "SENDER" xml.Payor{ - xml.AccountNumber @credentials.account_number - xml.CountryCode @shipper[:country_code] + if service[:version] >= 12 + xml.ResponsibleParty { + xml.AccountNumber @credentials.account_number + xml.Contact { + xml.PersonName @shipper[:name] + xml.CompanyName @shipper[:company] + xml.PhoneNumber @shipper[:phone_number] + } + } + else + xml.AccountNumber @credentials.account_number + xml.CountryCode @shipper[:country_code] + end } } end # Add packages to xml request @@ -172,18 +187,11 @@ xml.Width package[:dimensions][:width] xml.Height package[:dimensions][:height] xml.Units package[:dimensions][:units] } end - if package[:customer_refrences] - xml.CustomerReferences{ - package[:customer_refrences].each do |value| - xml.CustomerReferenceType 'CUSTOMER_REFERENCE' - xml.Value value - end - } - end + add_customer_references(xml, package) if package[:special_services_requested] && package[:special_services_requested][:special_service_types] xml.SpecialServicesRequested{ if package[:special_services_requested][:special_service_types].is_a? Array package[:special_services_requested][:special_service_types].each do |type| xml.SpecialServiceTypes type @@ -226,9 +234,32 @@ xml.PriorityAlertDetail package[:special_services_requested][:priority_alert_detail] end } end } + end + end + + def add_customer_references(xml, package) + # customer_refrences is a legacy misspelling + if refs = package[:customer_references] || package[:customer_refrences] + refs.each do |ref| + xml.CustomerReferences{ + if ref.is_a?(Hash) + # :type can specify custom type: + # + # BILL_OF_LADING, CUSTOMER_REFERENCE, DEPARTMENT_NUMBER, + # ELECTRONIC_PRODUCT_CODE, INTRACOUNTRY_REGULATORY_REFERENCE, + # INVOICE_NUMBER, P_O_NUMBER, RMA_ASSOCIATION, + # SHIPMENT_INTEGRITY, STORE_NUMBER + xml.CustomerReferenceType ref[:type] + xml.Value ref[:value] + else + xml.CustomerReferenceType 'CUSTOMER_REFERENCE' + xml.Value ref + end + } + end end end # Add customs clearance(for international shipments) def add_customs_clearance(xml)