lib/active_shipping/carriers/ups.rb in active_shipping-1.7.1 vs lib/active_shipping/carriers/ups.rb in active_shipping-1.7.2
- old
+ new
@@ -316,11 +316,11 @@
end
# Build XML node to request a shipping label for the given packages.
#
# options:
- # * origin_account: who will pay for the shipping label
+ # * origin_account: account number for the shipper
# * customer_context: a "guid like substance" -- according to UPS
# * shipper: who is sending the package and where it should be returned
# if it is undeliverable.
# * ship_from: where the package is picked up.
# * service_code: default to '03'
@@ -330,10 +330,11 @@
# * terms_of_shipment: used with paperless invoice to specify who pays duties and taxes
# * reference_numbers: Array of hashes with :value => a reference number value and optionally :code => reference number type
# * prepay: if truthy the shipper will be bill immediatly. Otherwise the shipper is billed when the label is used.
# * negotiated_rates: if truthy negotiated rates will be requested from ups. Only valid if shipper account has negotiated rates.
# * delivery_confirmation: Can be set to any key from SHIPMENT_DELIVERY_CONFIRMATION_CODES. Can also be set on package level via package.options
+ # * bill_third_party: When truthy, bill an account other than the shipper's. Specified by billing_(account, zip and country)
def build_shipment_request(origin, destination, packages, options={})
packages = Array(packages)
shipper = options[:shipper] || origin
options[:international] = origin.country.name != destination.country.name
options[:imperial] ||= IMPERIAL_COUNTRIES.include?(shipper.country_code(:alpha2))
@@ -379,11 +380,11 @@
xml.ShipmentServiceOptions do
xml.SaturdayDelivery
end
end
- if options[:origin_account]
+ if options[:negotiated_rates]
xml.RateInformation do
xml.NegotiatedRatesIndicator
end
end
@@ -395,47 +396,27 @@
end
if options[:prepay]
xml.PaymentInformation do
xml.Prepaid do
- xml.BillShipper do
- xml.AccountNumber(options[:origin_account])
- end
+ build_billing_info_node(xml, options)
end
end
- elsif options[:bill_third_party]
- xml.PaymentInformation do
- xml.BillThirdParty do
- xml.BillThirdPartyShipper do
- xml.AccountNumber(options[:billing_account])
- xml.ThirdParty do
- xml.Address do
- xml.PostalCode(options[:billing_zip])
- xml.CountryCode(options[:billing_country])
- end
- end
- end
- end
- end
else
xml.ItemizedPaymentInformation do
xml.ShipmentCharge do
# Type '01' means 'Transportation'
# This node specifies who will be billed for transportation.
xml.Type('01')
- xml.BillShipper do
- xml.AccountNumber(options[:origin_account])
- end
+ build_billing_info_node(xml, options)
end
- if options[:terms_of_shipment] == 'DDP'
+ if options[:terms_of_shipment] == 'DDP' && options[:international]
# DDP stands for delivery duty paid and means the shipper will cover duties and taxes
# Otherwise UPS will charge the receiver
xml.ShipmentCharge do
xml.Type('02') # Type '02' means 'Duties and Taxes'
- xml.BillShipper do
- xml.AccountNumber(options[:origin_account])
- end
+ build_billing_info_node(xml, options.merge(bill_to_consignee: true))
end
end
end
end
@@ -757,9 +738,30 @@
end
end
# not implemented: * Shipment/Package/LargePackageIndicator element
# * Shipment/Package/AdditionalHandling element
+ end
+ end
+
+ def build_billing_info_node(xml, options={})
+ if options[:bill_third_party]
+ xml.BillThirdParty do
+ node_type = options[:bill_to_consignee] ? :BillThirdPartyConsignee : :BillThirdPartyShipper
+ xml.public_send(node_type) do
+ xml.AccountNumber(options[:billing_account])
+ xml.ThirdParty do
+ xml.Address do
+ xml.PostalCode(options[:billing_zip])
+ xml.CountryCode(options[:billing_country])
+ end
+ end
+ end
+ end
+ else
+ xml.BillShipper do
+ xml.AccountNumber(options[:origin_account])
+ end
end
end
def build_document(xml, expected_root_tag)
document = Nokogiri.XML(xml)