From f73935a47a1a039df5ea3e78450c1354534014c8 Mon Sep 17 00:00:00 2001 From: Chip Castle Date: Thu, 9 Jun 2011 18:27:18 -0500 Subject: [PATCH] Fixes per Fedex Tech Support (version, additional tags) --- lib/shippinglogic/fedex/request.rb | 18 +++++-- lib/shippinglogic/fedex/ship.rb | 82 +++++++++++------------------- 2 files changed, 45 insertions(+), 55 deletions(-) diff --git a/lib/shippinglogic/fedex/request.rb b/lib/shippinglogic/fedex/request.rb index 0d3c167..ab1d934 100644 --- a/lib/shippinglogic/fedex/request.rb +++ b/lib/shippinglogic/fedex/request.rb @@ -41,8 +41,7 @@ def build_authentication(b) end b.TransactionDetail do - b.CustomerTransactionId 'Express International Basic Shipment' - # b.CustomerTransactionId 'Express US Basic Shipment' + b.CustomerTransactionId 'ProcessShipmentRequest_Condor_US_CA_ADG_IE' end end @@ -91,8 +90,9 @@ def build_insured_value(b) # A convenience method for building the package block in your XML request def build_package(b) b.PackageCount package_count + b.PackageDetail package_detail - b.RequestedPackages do + b.RequestedPackageLineItems do b.SequenceNumber 1 b.Weight do @@ -109,6 +109,18 @@ def build_package(b) end end + b.CustomerReferences do + b.CustomerReferenceType customer_reference_type + b.Value customer_reference_value + end + + b.SpecialServicesRequested do + b.SpecialServiceTypes DANGEROUS_GOODS + b.DangerousGoodsDetail do + b.Accessibility ACCESSIBLE + end + end + if respond_to?(:signature) && signature self.special_services_requested << "SIGNATURE_OPTION" end diff --git a/lib/shippinglogic/fedex/ship.rb b/lib/shippinglogic/fedex/ship.rb index ab80a59..8af5924 100644 --- a/lib/shippinglogic/fedex/ship.rb +++ b/lib/shippinglogic/fedex/ship.rb @@ -107,7 +107,7 @@ class Ship < Service # The shipment result is an object of this class class Shipment; attr_accessor :rate, :currency, :delivery_date, :tracking_number, :label, :barcode; end - VERSION = {:major => 6, :intermediate => 0, :minor => 0} + VERSION = {:major => 9, :intermediate => 0, :minor => 0} # shipper options attribute :shipper_name, :string @@ -138,12 +138,13 @@ class Shipment; attr_accessor :rate, :currency, :delivery_date, :tracking_number # label options attribute :label_format, :string, :default => "COMMON2D" attribute :label_file_type, :string, :default => "PDF" - attribute :label_stock_type, :string, :default => "PAPER_8.5X11_TOP_HALF_LABEL" + attribute :label_stock_type, :string, :default => "PAPER_7X4.75" #"PAPER_8.5X11_TOP_HALF_LABEL" # packaging options attribute :packaging_type, :string, :default => "YOUR_PACKAGING" - attribute :packaging_type, :string, :default => "YOUR_PACKAGING" + attribute :preferred_currency, :string, :default => "USD" attribute :package_count, :integer, :default => 1 + attribute :package_detail, :string, :default => "INDIVIDUAL_PACKAGES" attribute :package_weight, :float attribute :package_weight_units, :string, :default => "LB" attribute :package_length, :integer @@ -151,16 +152,24 @@ class Shipment; attr_accessor :rate, :currency, :delivery_date, :tracking_number attribute :package_height, :integer attribute :package_dimension_units, :string, :default => "IN" + # customer reference + attribute :customer_reference_type, :string, :default => 'CUSTOMER_REFERENCE' + attribute :customer_reference_value, :string, :default => 'TC001_01_PT1_ST01_PK01_SNDUS_RCPCA_POS' + + # special services + attribute :special_service_types, :string, :default => 'DANGEROUS_GOODS' + attribute :accessibility, :string, :default => 'ACCESSIBLE' + # monetary options attribute :currency_type, :string attribute :insured_value, :decimal attribute :payment_type, :string, :default => "SENDER" attribute :payor_account_number, :string, :default => lambda { |shipment| shipment.base.account } - attribute :payor_country, :string + attribute :payor_country_code, :string, :default => 'US' # delivery options attribute :ship_time, :datetime, :default => lambda { |shipment| Time.now } - attribute :service_type, :string + attribute :service_type, :string, :default => "INTERNATIONAL_PRIORITY" attribute :dropoff_type, :string, :default => "REGULAR_PICKUP" attribute :special_services_requested, :array attribute :signature, :string @@ -169,6 +178,9 @@ class Shipment; attr_accessor :rate, :currency, :delivery_date, :tracking_number attribute :just_validate, :boolean, :default => false attribute :rate_request_types, :array, :default => ["ACCOUNT"] + # commercial invoice + attribute :terms_of_sale, :string, :default => "FOB_OR_FCA" + # customs options attribute :payment_type, :string, :default => "SENDER" attribute :document_content, :string, :default => "NON_DOCUMENTS" @@ -191,8 +203,8 @@ def target # Just building some XML to send off to FedEx using our various options def build_request @log = Logger.new('/tmp/fedex.log') - @log.info "build_request service_type = #{service_type}" - + @log.info "inside build request" + b = builder xml = b.tag!(just_validate ? "ValidateShipmentRequest" : "ProcessShipmentRequest", :xmlns => "http://fedex.com/ws/ship/v#{VERSION[:major]}") do build_authentication(b) @@ -202,8 +214,8 @@ def build_request b.ShipTimestamp ship_time.xmlschema if ship_time b.DropoffType dropoff_type if dropoff_type b.ServiceType service_type if service_type - # b.ServiceType 'INTERNATIONAL_PRIORITY' b.PackagingType packaging_type if packaging_type + b.PreferredCurrency preferred_currency if preferred_currency build_insured_value(b) b.Shipper do @@ -220,47 +232,9 @@ def build_request b.PaymentType payment_type if payment_type b.Payor do b.AccountNumber payor_account_number if payor_account_number - b.CountryCode payor_country if payor_country + b.CountryCode payor_country_code if payor_country_code end end - - # Per Proprietary_Developer_Guide.pdf from FedEx - # - # - # SENDER - # - # 123456789 - # US - # - # - # NON_DOCUMENTS - # - # USD - # 100.00 - # - # - # 1 - # Technical Book - # US - # - # LB - # 5 - # - # 1 - # EA - # - # USD - # 100.00 - # - # - # USD - # 100.00 - # - # - # - # NO EEI 30.36 - # - # b.CustomsClearanceDetail do b.DutiesPayment do @@ -275,6 +249,9 @@ def build_request b.Currency currency if currency b.Amount item_amount if item_amount end + b.CommercialInvoice do + b.TermsOfSale terms_of_sale if terms_of_sale + end b.Commodities do b.NumberOfPieces number_of_pieces if number_of_pieces b.Description description if description @@ -294,9 +271,9 @@ def build_request b.Amount item_amount if item_amount end end - b.ExportDetail do - b.ExportComplianceStatement export_compliance_statement if export_compliance_statement - end + # b.ExportDetail do + # b.ExportComplianceStatement export_compliance_statement if export_compliance_statement + # end end b.LabelSpecification do @@ -309,12 +286,13 @@ def build_request build_package(b) end end - @log.info "shippinglogic xml\n" + xml - xml end # Making sense of the reponse and grabbing the information we need. def parse_response(response) + @log = Logger.new('/tmp/fedex.log') + @log.info "parse_response = #{parse_response}" + details = response[:completed_shipment_detail] rate_details = details[:shipment_rating][:shipment_rate_details] rate = rate_details[:total_net_charge] || rate_details.first[:total_net_charge]