friendly_shipping 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.env.template +3 -0
- data/.env.test.local.template +6 -0
- data/.gitignore +1 -0
- data/.rubocop-relaxed.yml +7 -23
- data/.rubocop.yml +11 -2
- data/.rubocop_todo.yml +21 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +17 -0
- data/friendly_shipping.gemspec +4 -13
- data/lib/friendly_shipping/api_error.rb +6 -4
- data/lib/friendly_shipping/api_error_handler.rb +10 -6
- data/lib/friendly_shipping/api_failure.rb +4 -0
- data/lib/friendly_shipping/api_result.rb +16 -4
- data/lib/friendly_shipping/carrier.rb +28 -8
- data/lib/friendly_shipping/http_client.rb +25 -2
- data/lib/friendly_shipping/inflections.rb +10 -0
- data/lib/friendly_shipping/item_options.rb +3 -0
- data/lib/friendly_shipping/label.rb +41 -20
- data/lib/friendly_shipping/package_options.rb +21 -2
- data/lib/friendly_shipping/rate.rb +50 -15
- data/lib/friendly_shipping/request.rb +23 -7
- data/lib/friendly_shipping/response.rb +21 -6
- data/lib/friendly_shipping/services/rl/api_error.rb +33 -0
- data/lib/friendly_shipping/services/rl/bol_options.rb +107 -0
- data/lib/friendly_shipping/services/rl/bol_packages_serializer.rb +32 -0
- data/lib/friendly_shipping/services/rl/bol_structures_serializer.rb +31 -0
- data/lib/friendly_shipping/services/rl/item_options.rb +38 -0
- data/lib/friendly_shipping/services/rl/package_options.rb +40 -0
- data/lib/friendly_shipping/services/rl/parse_create_bol_response.rb +46 -0
- data/lib/friendly_shipping/services/rl/parse_invoice_response.rb +50 -0
- data/lib/friendly_shipping/services/rl/parse_print_bol_response.rb +47 -0
- data/lib/friendly_shipping/services/rl/parse_print_shipping_labels_response.rb +47 -0
- data/lib/friendly_shipping/services/rl/parse_rate_quote_response.rb +66 -0
- data/lib/friendly_shipping/services/rl/parse_transit_times_response.rb +76 -0
- data/lib/friendly_shipping/services/rl/rate_quote_options.rb +86 -0
- data/lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb +54 -0
- data/lib/friendly_shipping/services/rl/rate_quote_structures_serializer.rb +53 -0
- data/lib/friendly_shipping/services/rl/serialize_create_bol_request.rb +86 -0
- data/lib/friendly_shipping/services/rl/serialize_location.rb +46 -0
- data/lib/friendly_shipping/services/rl/serialize_rate_quote_request.rb +69 -0
- data/lib/friendly_shipping/services/rl/serialize_transit_times_request.rb +38 -0
- data/lib/friendly_shipping/services/rl/shipment_document.rb +40 -0
- data/lib/friendly_shipping/services/rl/shipment_information.rb +41 -0
- data/lib/friendly_shipping/services/rl/shipment_options.rb +50 -0
- data/lib/friendly_shipping/services/rl/shipping_methods.rb +28 -0
- data/lib/friendly_shipping/services/rl/structure_options.rb +13 -0
- data/lib/friendly_shipping/services/rl.rb +204 -0
- data/lib/friendly_shipping/services/ship_engine/api_error.rb +33 -0
- data/lib/friendly_shipping/services/ship_engine/customs_items_serializer.rb +36 -0
- data/lib/friendly_shipping/services/ship_engine/label_customs_options.rb +10 -7
- data/lib/friendly_shipping/services/ship_engine/label_item_options.rb +10 -5
- data/lib/friendly_shipping/services/ship_engine/label_options.rb +31 -14
- data/lib/friendly_shipping/services/ship_engine/label_package_options.rb +18 -11
- data/lib/friendly_shipping/services/ship_engine/parse_address_validation_response.rb +77 -0
- data/lib/friendly_shipping/services/ship_engine/parse_carrier_response.rb +9 -0
- data/lib/friendly_shipping/services/ship_engine/parse_label_response.rb +4 -0
- data/lib/friendly_shipping/services/ship_engine/{parse_rate_estimate_response.rb → parse_rate_estimates_response.rb} +26 -6
- data/lib/friendly_shipping/services/ship_engine/parse_rates_response.rb +101 -0
- data/lib/friendly_shipping/services/ship_engine/parse_void_response.rb +4 -0
- data/lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb +17 -4
- data/lib/friendly_shipping/services/ship_engine/rates_item_options.rb +28 -0
- data/lib/friendly_shipping/services/ship_engine/rates_options.rb +61 -0
- data/lib/friendly_shipping/services/ship_engine/rates_package_options.rb +20 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_address_residential_indicator.rb +27 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_address_validation_request.rb +31 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb +22 -27
- data/lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb +41 -16
- data/lib/friendly_shipping/services/ship_engine/serialize_rates_request.rb +126 -0
- data/lib/friendly_shipping/services/ship_engine.rb +94 -21
- data/lib/friendly_shipping/services/ship_engine_ltl/api_error.rb +12 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/item_options.rb +24 -5
- data/lib/friendly_shipping/services/ship_engine_ltl/package_options.rb +39 -4
- data/lib/friendly_shipping/services/ship_engine_ltl/parse_carrier_response.rb +4 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb +10 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/quote_options.rb +29 -11
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_packages.rb +7 -2
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_quote_request.rb +50 -16
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_structures.rb +42 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/shipment_options.rb +47 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/structure_options.rb +17 -0
- data/lib/friendly_shipping/services/ship_engine_ltl.rb +50 -30
- data/lib/friendly_shipping/services/tforce_freight/access_token.rb +43 -0
- data/lib/friendly_shipping/services/tforce_freight/api_error.rb +42 -0
- data/lib/friendly_shipping/services/tforce_freight/bol_options.rb +180 -0
- data/lib/friendly_shipping/services/tforce_freight/document_options.rb +100 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_commodity_information.rb +92 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_create_bol_request_hash.rb +165 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_document_options_hash.rb +36 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_handling_units_hash.rb +51 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_location_hash.rb +25 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_pickup_request_hash.rb +113 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_rates_request_hash.rb +65 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_reference_hash.rb +28 -0
- data/lib/friendly_shipping/services/tforce_freight/item_options.rb +93 -0
- data/lib/friendly_shipping/services/tforce_freight/package_options.rb +121 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_create_bol_response.rb +94 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_pickup_response.rb +45 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_rates_response.rb +58 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_shipment_document.rb +31 -0
- data/lib/friendly_shipping/services/tforce_freight/pickup_options.rb +82 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_item_options.rb +12 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_options.rb +162 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_package_options.rb +12 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_document.rb +38 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_information.rb +104 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_options.rb +49 -0
- data/lib/friendly_shipping/services/tforce_freight/shipping_methods.rb +25 -0
- data/lib/friendly_shipping/services/tforce_freight/structure_options.rb +44 -0
- data/lib/friendly_shipping/services/tforce_freight.rb +202 -0
- data/lib/friendly_shipping/services/ups/label_options.rb +14 -2
- data/lib/friendly_shipping/services/ups/label_package_options.rb +1 -1
- data/lib/friendly_shipping/services/ups/parse_modifier_element.rb +29 -0
- data/lib/friendly_shipping/services/ups/parse_rate_response.rb +12 -0
- data/lib/friendly_shipping/services/ups/parse_time_in_transit_response.rb +1 -1
- data/lib/friendly_shipping/services/ups/rate_estimate_options.rb +14 -1
- data/lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb +10 -1
- data/lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb +1 -1
- data/lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb +2 -1
- data/lib/friendly_shipping/services/ups/shipping_methods.rb +1 -1
- data/lib/friendly_shipping/services/ups.rb +1 -1
- data/lib/friendly_shipping/services/ups_freight/api_error.rb +8 -5
- data/lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb +65 -19
- data/lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb +3 -20
- data/lib/friendly_shipping/services/ups_freight/generate_freight_ship_request_hash.rb +2 -20
- data/lib/friendly_shipping/services/ups_freight/generate_handling_units_hash.rb +54 -0
- data/lib/friendly_shipping/services/ups_freight/label_options.rb +36 -10
- data/lib/friendly_shipping/services/ups_freight/label_structure_options.rb +13 -0
- data/lib/friendly_shipping/services/ups_freight/parse_freight_label_response.rb +2 -2
- data/lib/friendly_shipping/services/ups_freight/parse_shipment_document.rb +1 -1
- data/lib/friendly_shipping/services/ups_freight/rates_item_options.rb +18 -9
- data/lib/friendly_shipping/services/ups_freight/rates_options.rb +31 -21
- data/lib/friendly_shipping/services/ups_freight/rates_package_options.rb +79 -8
- data/lib/friendly_shipping/services/ups_freight/rates_structure_options.rb +46 -0
- data/lib/friendly_shipping/services/ups_freight/shipment_information.rb +7 -3
- data/lib/friendly_shipping/services/ups_freight/shipment_options.rb +49 -0
- data/lib/friendly_shipping/services/ups_freight.rb +3 -1
- data/lib/friendly_shipping/services/ups_json/access_token.rb +29 -0
- data/lib/friendly_shipping/services/ups_json/api_error.rb +29 -0
- data/lib/friendly_shipping/services/ups_json/generate_address_classification_payload.rb +29 -0
- data/lib/friendly_shipping/services/ups_json/generate_address_hash.rb +30 -0
- data/lib/friendly_shipping/services/ups_json/generate_labels_payload.rb +211 -0
- data/lib/friendly_shipping/services/ups_json/generate_package_hash.rb +76 -0
- data/lib/friendly_shipping/services/ups_json/generate_rates_payload.rb +86 -0
- data/lib/friendly_shipping/services/ups_json/generate_timings_payload.rb +44 -0
- data/lib/friendly_shipping/services/ups_json/label.rb +20 -0
- data/lib/friendly_shipping/services/ups_json/label_billing_options.rb +41 -0
- data/lib/friendly_shipping/services/ups_json/label_item_options.rb +77 -0
- data/lib/friendly_shipping/services/ups_json/label_options.rb +177 -0
- data/lib/friendly_shipping/services/ups_json/label_package_options.rb +51 -0
- data/lib/friendly_shipping/services/ups_json/parse_address_classification_response.rb +31 -0
- data/lib/friendly_shipping/services/ups_json/parse_json_response.rb +44 -0
- data/lib/friendly_shipping/services/ups_json/parse_labels_response.rb +71 -0
- data/lib/friendly_shipping/services/ups_json/parse_money_hash.rb +128 -0
- data/lib/friendly_shipping/services/ups_json/parse_rate_modifier_hash.rb +28 -0
- data/lib/friendly_shipping/services/ups_json/parse_rates_response.rb +105 -0
- data/lib/friendly_shipping/services/ups_json/parse_timings_response.rb +56 -0
- data/lib/friendly_shipping/services/ups_json/parse_void_response.rb +32 -0
- data/lib/friendly_shipping/services/ups_json/rates_item_options.rb +22 -0
- data/lib/friendly_shipping/services/ups_json/rates_options.rb +113 -0
- data/lib/friendly_shipping/services/ups_json/rates_package_options.rb +17 -0
- data/lib/friendly_shipping/services/ups_json/shipping_methods.rb +111 -0
- data/lib/friendly_shipping/services/ups_json/timings_options.rb +33 -0
- data/lib/friendly_shipping/services/ups_json.rb +216 -0
- data/lib/friendly_shipping/services/usps/choose_package_rate.rb +3 -3
- data/lib/friendly_shipping/services/usps/machinable_package.rb +1 -1
- data/lib/friendly_shipping/services/usps/parse_package_rate.rb +6 -6
- data/lib/friendly_shipping/services/usps/parse_time_in_transit_response.rb +6 -6
- data/lib/friendly_shipping/services/usps/rate_estimate_options.rb +1 -1
- data/lib/friendly_shipping/services/usps/rate_estimate_package_options.rb +6 -1
- data/lib/friendly_shipping/services/usps/serialize_rate_request.rb +2 -2
- data/lib/friendly_shipping/services/usps/shipping_methods.rb +4 -3
- data/lib/friendly_shipping/services/usps.rb +1 -1
- data/lib/friendly_shipping/services/usps_international/parse_package_rate.rb +3 -3
- data/lib/friendly_shipping/services/usps_international/rate_estimate_options.rb +1 -1
- data/lib/friendly_shipping/services/usps_international/serialize_rate_request.rb +1 -1
- data/lib/friendly_shipping/services/usps_international.rb +1 -1
- data/lib/friendly_shipping/services/usps_ship/access_token.rb +37 -0
- data/lib/friendly_shipping/services/usps_ship/api_error.rb +29 -0
- data/lib/friendly_shipping/services/usps_ship/machinable_package.rb +53 -0
- data/lib/friendly_shipping/services/usps_ship/parse_rate_estimates_response.rb +80 -0
- data/lib/friendly_shipping/services/usps_ship/parse_timings_response.rb +80 -0
- data/lib/friendly_shipping/services/usps_ship/rate_estimate_options.rb +45 -0
- data/lib/friendly_shipping/services/usps_ship/rate_estimate_package_options.rb +124 -0
- data/lib/friendly_shipping/services/usps_ship/serialize_rate_estimates_request.rb +55 -0
- data/lib/friendly_shipping/services/usps_ship/shipping_methods.rb +38 -0
- data/lib/friendly_shipping/services/{ship_engine_ltl/bad_request.rb → usps_ship/timing_options.rb} +2 -2
- data/lib/friendly_shipping/services/usps_ship.rb +199 -0
- data/lib/friendly_shipping/shipment_options.rb +13 -1
- data/lib/friendly_shipping/shipping_method.rb +38 -11
- data/lib/friendly_shipping/structure_options.rb +38 -0
- data/lib/friendly_shipping/timing.rb +42 -7
- data/lib/friendly_shipping/version.rb +1 -1
- data/lib/friendly_shipping.rb +6 -0
- metadata +140 -174
- data/lib/friendly_shipping/services/ship_engine/bad_request.rb +0 -29
- data/lib/friendly_shipping/services/ship_engine/bad_request_handler.rb +0 -33
- data/lib/friendly_shipping/services/ship_engine_ltl/bad_request_handler.rb +0 -33
@@ -16,6 +16,7 @@ module FriendlyShipping
|
|
16
16
|
# Optional:
|
17
17
|
#
|
18
18
|
# @param shipper [Physical::Location] The company sending the shipment. Defaults to the shipment's origin.
|
19
|
+
# @param sub_version [String] The UPS API sub-version to use for requests. Default: 1707
|
19
20
|
# @param customer_context [String ] Optional element to identify transactions between client and server
|
20
21
|
# @param validate_address [Boolean] Validate the city field with ZIP code and state. If false, only ZIP code
|
21
22
|
# and state are validated. Default: true
|
@@ -40,6 +41,7 @@ module FriendlyShipping
|
|
40
41
|
# @option reason_for_export [String] A reason to export the current shipment. Possible values: 'SALE', 'GIFT', 'SAMPLE',
|
41
42
|
# 'RETURN', 'REPAIR', 'INTERCOMPANYDATA', Any other reason. Default: 'SALE'.
|
42
43
|
# @option invoice_date [Date] The invoice date for the shipment
|
44
|
+
# @param declaration_statement [String ] Optional element to add customs declaration text
|
43
45
|
#
|
44
46
|
class Ups
|
45
47
|
class LabelOptions < FriendlyShipping::ShipmentOptions
|
@@ -83,9 +85,12 @@ module FriendlyShipping
|
|
83
85
|
ups_pack_collect_3_attemt_box_5: 20 # UPS Pack & Collect Service 1-Attempt Box 5
|
84
86
|
}.freeze
|
85
87
|
|
88
|
+
SUB_VERSIONS = %w[1601 1607 1701 1707 1801 1807 2108 2205].freeze
|
89
|
+
|
86
90
|
attr_reader :shipping_method,
|
87
91
|
:shipper_number,
|
88
92
|
:shipper,
|
93
|
+
:sub_version,
|
89
94
|
:customer_context,
|
90
95
|
:validate_address,
|
91
96
|
:negotiated_rates,
|
@@ -97,12 +102,14 @@ module FriendlyShipping
|
|
97
102
|
:carbon_neutral,
|
98
103
|
:paperless_invoice,
|
99
104
|
:reason_for_export,
|
100
|
-
:invoice_date
|
105
|
+
:invoice_date,
|
106
|
+
:declaration_statement
|
101
107
|
|
102
108
|
def initialize(
|
103
109
|
shipping_method:,
|
104
110
|
shipper_number:,
|
105
111
|
shipper: nil,
|
112
|
+
sub_version: '1707',
|
106
113
|
customer_context: nil,
|
107
114
|
validate_address: true,
|
108
115
|
negotiated_rates: false,
|
@@ -119,11 +126,15 @@ module FriendlyShipping
|
|
119
126
|
reason_for_export: 'SALE',
|
120
127
|
invoice_date: nil,
|
121
128
|
package_options_class: LabelPackageOptions,
|
129
|
+
declaration_statement: nil,
|
122
130
|
**kwargs
|
123
131
|
)
|
132
|
+
raise ArgumentError, "Invalid sub-version: #{sub_version}" unless sub_version.in?(SUB_VERSIONS)
|
133
|
+
|
124
134
|
@shipping_method = shipping_method
|
125
135
|
@shipper_number = shipper_number
|
126
136
|
@shipper = shipper
|
137
|
+
@sub_version = sub_version
|
127
138
|
@customer_context = customer_context
|
128
139
|
@validate_address = validate_address
|
129
140
|
@negotiated_rates = negotiated_rates
|
@@ -139,7 +150,8 @@ module FriendlyShipping
|
|
139
150
|
@terms_of_shipment = terms_of_shipment
|
140
151
|
@reason_for_export = reason_for_export
|
141
152
|
@invoice_date = invoice_date
|
142
|
-
|
153
|
+
@declaration_statement = declaration_statement
|
154
|
+
super(**kwargs.reverse_merge(package_options_class: package_options_class))
|
143
155
|
end
|
144
156
|
|
145
157
|
def delivery_confirmation_code
|
@@ -35,7 +35,7 @@ module FriendlyShipping
|
|
35
35
|
@delivery_confirmation = delivery_confirmation
|
36
36
|
@shipper_release = shipper_release
|
37
37
|
@declared_value = declared_value
|
38
|
-
super(**kwargs.
|
38
|
+
super(**kwargs.reverse_merge(item_options_class: LabelItemOptions))
|
39
39
|
end
|
40
40
|
|
41
41
|
def delivery_confirmation_code
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class Ups
|
6
|
+
class ParseModifierElement
|
7
|
+
# @param [Nokogiri::XML::Element] element The modifier element from the source XML
|
8
|
+
# @param [String] currency_code The currency code for this modifier's amount (i.e. 'USD')
|
9
|
+
# @return [Array<String, Money>]
|
10
|
+
def self.call(element, currency_code:)
|
11
|
+
return unless element
|
12
|
+
|
13
|
+
amount = element.at('Amount').text.to_d
|
14
|
+
return if amount.zero?
|
15
|
+
|
16
|
+
currency = Money::Currency.new(currency_code)
|
17
|
+
amount = Money.new(amount * currency.subunit_to_unit, currency)
|
18
|
+
|
19
|
+
modifier_type = element.at('ModifierType').text
|
20
|
+
modifier_description = element.at('ModifierDesc').text
|
21
|
+
|
22
|
+
label = "#{modifier_type} (#{modifier_description})"
|
23
|
+
|
24
|
+
[label, amount]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'friendly_shipping/services/ups/parse_xml_response'
|
4
4
|
require 'friendly_shipping/services/ups/parse_money_element'
|
5
|
+
require 'friendly_shipping/services/ups/parse_modifier_element'
|
5
6
|
|
6
7
|
module FriendlyShipping
|
7
8
|
module Services
|
@@ -68,6 +69,7 @@ module FriendlyShipping
|
|
68
69
|
|
69
70
|
def build_packages(rated_shipment)
|
70
71
|
rated_shipment.css('RatedPackage').map do |rated_package|
|
72
|
+
currency_code = rated_package.at('TotalCharges/CurrencyCode').text
|
71
73
|
{
|
72
74
|
transportation_charges: ParseMoneyElement.call(rated_package.at('TransportationCharges'))&.last,
|
73
75
|
base_service_charge: ParseMoneyElement.call(rated_package.at('BaseServiceCharge'))&.last,
|
@@ -75,6 +77,7 @@ module FriendlyShipping
|
|
75
77
|
itemized_charges: extract_charges(rated_package.xpath('ItemizedCharges')),
|
76
78
|
total_charges: ParseMoneyElement.call(rated_package.at('TotalCharges'))&.last,
|
77
79
|
negotiated_charges: extract_charges(rated_package.xpath('NegotiatedCharges/ItemizedCharges')),
|
80
|
+
rate_modifiers: extract_modifiers(rated_package.xpath('RateModifier'), currency_code: currency_code),
|
78
81
|
weight: BigDecimal(rated_package.at('Weight').text),
|
79
82
|
billing_weight: BigDecimal(rated_package.at('BillingWeight/Weight').text)
|
80
83
|
}.compact
|
@@ -86,6 +89,15 @@ module FriendlyShipping
|
|
86
89
|
ParseMoneyElement.call(element)
|
87
90
|
end.compact.to_h
|
88
91
|
end
|
92
|
+
|
93
|
+
# @param [Nokogiri::XML::NodeSet] node The RateModifier node set from the source XML
|
94
|
+
# @param [String] currency_code The currency code for the modifier amounts (i.e. 'USD')
|
95
|
+
# @return [Array<Hash>]
|
96
|
+
def extract_modifiers(node, currency_code:)
|
97
|
+
node.map do |element|
|
98
|
+
ParseModifierElement.call(element, currency_code: currency_code)
|
99
|
+
end.compact.to_h
|
100
|
+
end
|
89
101
|
end
|
90
102
|
end
|
91
103
|
end
|
@@ -17,10 +17,13 @@ module FriendlyShipping
|
|
17
17
|
# @option customer_classification [Symbol] Which kind of rates to request. See UPS docs for more details. Default: `shipper_number`
|
18
18
|
# @option negotiated_rates [Boolean] if truthy negotiated rates will be requested from ups. Only valid if
|
19
19
|
# shipper account has negotiated rates. Default: false
|
20
|
+
# @option pickup_type [String] UPS pickup type. See UPS docs for more details. Default: `daily_pickup`
|
21
|
+
# @option pickup_date [Time] UPS pickup date/time. Default: nil
|
20
22
|
# @option saturday_delivery [Boolean] should we request Saturday delivery?. Default: false
|
21
23
|
# @option saturday_pickup [Boolean] should we request Saturday pickup?. Default: false
|
22
24
|
# @option shipping_method [FriendlyShipping::ShippingMethod] Request rates for a particular shipping method only?
|
23
25
|
# Default is `nil`, which translates to 'All shipping methods' (The "Shop" option in UPS parlance)
|
26
|
+
# @option sub_version [String] The UPS API sub-version to use for requests. Default: 1707
|
24
27
|
# @option with_time_in_transit [Boolean] Whether to request timing information alongside the rates
|
25
28
|
# @option package_options_class [Class] See FriendlyShipping::ShipmentOptions
|
26
29
|
#
|
@@ -45,15 +48,19 @@ module FriendlyShipping
|
|
45
48
|
standard_rates: "53"
|
46
49
|
}.freeze
|
47
50
|
|
51
|
+
SUB_VERSIONS = %w[1601 1607 1701 1707 1801 2108 2201 2205].freeze
|
52
|
+
|
48
53
|
attr_reader :carbon_neutral,
|
49
54
|
:customer_context,
|
50
55
|
:destination_account,
|
51
56
|
:negotiated_rates,
|
57
|
+
:pickup_date,
|
52
58
|
:saturday_delivery,
|
53
59
|
:saturday_pickup,
|
54
60
|
:shipper,
|
55
61
|
:shipper_number,
|
56
62
|
:shipping_method,
|
63
|
+
:sub_version,
|
57
64
|
:with_time_in_transit
|
58
65
|
|
59
66
|
def initialize(
|
@@ -64,14 +71,18 @@ module FriendlyShipping
|
|
64
71
|
destination_account: nil,
|
65
72
|
negotiated_rates: false,
|
66
73
|
pickup_type: :daily_pickup,
|
74
|
+
pickup_date: nil,
|
67
75
|
saturday_delivery: false,
|
68
76
|
saturday_pickup: false,
|
69
77
|
shipper: nil,
|
70
78
|
shipping_method: nil,
|
79
|
+
sub_version: "1707",
|
71
80
|
with_time_in_transit: false,
|
72
81
|
package_options_class: FriendlyShipping::Services::Ups::RateEstimatePackageOptions,
|
73
82
|
**kwargs
|
74
83
|
)
|
84
|
+
raise ArgumentError, "Invalid sub-version: #{sub_version}" unless sub_version.in?(SUB_VERSIONS)
|
85
|
+
|
75
86
|
@carbon_neutral = carbon_neutral
|
76
87
|
@customer_context = customer_context
|
77
88
|
@customer_classification = customer_classification
|
@@ -79,12 +90,14 @@ module FriendlyShipping
|
|
79
90
|
@negotiated_rates = negotiated_rates
|
80
91
|
@shipper_number = shipper_number
|
81
92
|
@pickup_type = pickup_type
|
93
|
+
@pickup_date = pickup_date
|
82
94
|
@saturday_delivery = saturday_delivery
|
83
95
|
@saturday_pickup = saturday_pickup
|
84
96
|
@shipper = shipper
|
85
97
|
@shipping_method = shipping_method
|
98
|
+
@sub_version = sub_version
|
86
99
|
@with_time_in_transit = with_time_in_transit
|
87
|
-
super(**kwargs.
|
100
|
+
super(**kwargs.reverse_merge(package_options_class: package_options_class))
|
88
101
|
end
|
89
102
|
|
90
103
|
def pickup_type_code
|
@@ -18,7 +18,7 @@ module FriendlyShipping
|
|
18
18
|
# If no shipping method is given, request all of them
|
19
19
|
# I one is given, omit the request option. It then becomes "Rate", the default.
|
20
20
|
xml.RequestOption('Shop') unless options.shipping_method
|
21
|
-
xml.SubVersion(
|
21
|
+
xml.SubVersion(options.sub_version)
|
22
22
|
# Optional element to identify transactions between client and server.
|
23
23
|
if options.customer_context
|
24
24
|
xml.TransactionReference do
|
@@ -56,6 +56,15 @@ module FriendlyShipping
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
if options.pickup_date && options.sub_version.to_i >= 2205
|
60
|
+
xml.DeliveryTimeInformation do
|
61
|
+
xml.Pickup do
|
62
|
+
xml.Date options.pickup_date.strftime('%Y%m%d')
|
63
|
+
xml.Time options.pickup_date.strftime('%H%M')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
59
68
|
shipment.packages.each do |package|
|
60
69
|
package_options = options.options_for_package(package)
|
61
70
|
SerializePackageNode.call(
|
@@ -9,7 +9,7 @@ module FriendlyShipping
|
|
9
9
|
xml.ShipmentAcceptRequest do
|
10
10
|
xml.Request do
|
11
11
|
xml.RequestAction('ShipAccept')
|
12
|
-
xml.SubVersion(
|
12
|
+
xml.SubVersion(options.sub_version)
|
13
13
|
if options.customer_context
|
14
14
|
xml.TransactionReference do
|
15
15
|
xml.CustomerContext(options.customer_context)
|
@@ -27,7 +27,7 @@ module FriendlyShipping
|
|
27
27
|
xml.RequestAction('ShipConfirm')
|
28
28
|
# Required element controls level of address validation.
|
29
29
|
xml.RequestOption(options.validate_address ? 'validate' : 'nonvalidate')
|
30
|
-
xml.SubVersion(
|
30
|
+
xml.SubVersion(options.sub_version)
|
31
31
|
# Optional element to identify transactions between client and server.
|
32
32
|
if options.customer_context
|
33
33
|
xml.TransactionReference do
|
@@ -242,6 +242,7 @@ module FriendlyShipping
|
|
242
242
|
xml.InvoiceDate(invoice_date.strftime('%Y%m%d'))
|
243
243
|
xml.ReasonForExport(reason_for_export)
|
244
244
|
xml.CurrencyCode(options.billing_options.currency || 'USD')
|
245
|
+
xml.DeclarationStatement(options.declaration_statement) if options.declaration_statement
|
245
246
|
|
246
247
|
if options.terms_of_shipment_code
|
247
248
|
xml.TermsOfShipment(options.terms_of_shipment_code)
|
@@ -4,7 +4,7 @@ module FriendlyShipping
|
|
4
4
|
module Services
|
5
5
|
class Ups
|
6
6
|
EU_COUNTRIES = %w(
|
7
|
-
AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL
|
7
|
+
AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK
|
8
8
|
).map { |country_code| Carmen::Country.coded(country_code) }
|
9
9
|
|
10
10
|
class << self
|
@@ -8,16 +8,17 @@ module FriendlyShipping
|
|
8
8
|
class ApiError < FriendlyShipping::ApiError
|
9
9
|
# @param [RestClient::Exception] cause
|
10
10
|
def initialize(cause)
|
11
|
-
super
|
11
|
+
super(cause, parse_message(cause))
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
# @param [RestClient::Exception]
|
17
|
-
|
18
|
-
|
16
|
+
# @param [RestClient::Exception] error
|
17
|
+
# @return [String]
|
18
|
+
def parse_message(error)
|
19
|
+
return error.message unless error.response
|
19
20
|
|
20
|
-
parsed_json = JSON.parse(
|
21
|
+
parsed_json = JSON.parse(error.response.body)
|
21
22
|
|
22
23
|
if parsed_json['httpCode'].present?
|
23
24
|
status = [parsed_json['httpCode'], parsed_json['httpMessage']].compact.join(" ")
|
@@ -31,6 +32,8 @@ module FriendlyShipping
|
|
31
32
|
[status, desc].compact.join(": ").presence || "UPS Freight could not process the request."
|
32
33
|
end.join("\n")
|
33
34
|
end
|
35
|
+
rescue JSON::ParserError, KeyError => _e
|
36
|
+
nil
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
@@ -4,26 +4,72 @@ module FriendlyShipping
|
|
4
4
|
module Services
|
5
5
|
class UpsFreight
|
6
6
|
class GenerateCommodityInformation
|
7
|
-
|
8
|
-
shipment
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
class << self
|
8
|
+
# @param shipment [Physical::Shipment]
|
9
|
+
# @param options [#options_for_package, #options_for_structure]
|
10
|
+
# @return [Array<Hash>]
|
11
|
+
def call(shipment:, options:)
|
12
|
+
if shipment.packages.any?
|
13
|
+
warn "[DEPRECATION] `packages` is deprecated. Please use `structures` instead."
|
14
|
+
serialize_packages(shipment.packages, options)
|
15
|
+
else
|
16
|
+
serialize_structures(shipment.structures, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @param packages [Array<Physical::Package>]
|
23
|
+
# @param options [#options_for_package]
|
24
|
+
# @return [Array<Hash>]
|
25
|
+
def serialize_packages(packages, options)
|
26
|
+
packages.flat_map do |package|
|
27
|
+
package_options = options.options_for_package(package)
|
28
|
+
package.items.map do |item|
|
29
|
+
item_options = package_options.options_for_item(item)
|
30
|
+
{
|
31
|
+
# This is a required field
|
32
|
+
Description: item.description || 'Commodities',
|
33
|
+
Weight: {
|
34
|
+
UnitOfMeasurement: {
|
35
|
+
Code: 'LBS' # Only Pounds are supported
|
36
|
+
},
|
37
|
+
Value: item.weight.convert_to(:pounds).value.to_f.round(2).to_s
|
38
|
+
},
|
39
|
+
NumberOfPieces: '1', # We won't support this yet.
|
40
|
+
PackagingType: {
|
41
|
+
Code: item_options.packaging_code
|
42
|
+
},
|
43
|
+
FreightClass: item_options.freight_class
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param structures [Array<Physical::Structure>]
|
50
|
+
# @param options [#options_for_structure]
|
51
|
+
# @return [Array<Hash>]
|
52
|
+
def serialize_structures(structures, options)
|
53
|
+
structures.flat_map do |structure|
|
54
|
+
structure_options = options.options_for_structure(structure)
|
55
|
+
structure.packages.map do |package|
|
56
|
+
package_options = structure_options.options_for_package(package)
|
57
|
+
{
|
58
|
+
# This is a required field
|
59
|
+
Description: package.description || 'Commodities',
|
60
|
+
Weight: {
|
61
|
+
UnitOfMeasurement: {
|
62
|
+
Code: 'LBS' # Only Pounds are supported
|
63
|
+
},
|
64
|
+
Value: package.weight.convert_to(:pounds).value.to_f.round(2).to_s
|
65
|
+
},
|
66
|
+
NumberOfPieces: '1', # We won't support this yet.
|
67
|
+
PackagingType: {
|
68
|
+
Code: package_options.packaging_code
|
18
69
|
},
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
PackagingType: {
|
23
|
-
Code: item_options.packaging_code
|
24
|
-
},
|
25
|
-
FreightClass: item_options.freight_class
|
26
|
-
}
|
70
|
+
FreightClass: package_options.freight_class
|
71
|
+
}
|
72
|
+
end
|
27
73
|
end
|
28
74
|
end
|
29
75
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'friendly_shipping/services/ups_freight/generate_location_hash'
|
4
4
|
require 'friendly_shipping/services/ups_freight/generate_pickup_request_hash'
|
5
|
+
require 'friendly_shipping/services/ups_freight/generate_handling_units_hash'
|
5
6
|
|
6
7
|
module FriendlyShipping
|
7
8
|
module Services
|
@@ -22,31 +23,13 @@ module FriendlyShipping
|
|
22
23
|
Commodity: options.commodity_information_generator.call(shipment: shipment, options: options),
|
23
24
|
TimeInTransitIndicator: 'true',
|
24
25
|
PickupRequest: GeneratePickupRequestHash.call(pickup_request_options: options.pickup_request_options),
|
25
|
-
}.compact.
|
26
|
+
}.compact.
|
27
|
+
merge(GenerateHandlingUnitsHash.call(shipment: shipment, options: options))
|
26
28
|
}
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
30
32
|
|
31
|
-
def handling_units(shipment, options)
|
32
|
-
all_package_options = shipment.packages.map { |package| options.options_for_package(package) }
|
33
|
-
all_package_options.group_by(&:handling_unit_code).map do |_handling_unit_code, options_group|
|
34
|
-
[options_group.first, options_group.length]
|
35
|
-
end.map { |package_options, quantity| handling_unit_hash(package_options, quantity) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def handling_unit_hash(package_options, quantity)
|
39
|
-
{
|
40
|
-
package_options.handling_unit_tag => {
|
41
|
-
Quantity: quantity.to_s,
|
42
|
-
Type: {
|
43
|
-
Code: package_options.handling_unit_code,
|
44
|
-
Description: package_options.handling_unit_description
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
33
|
def request_options(customer_context)
|
51
34
|
return {} unless customer_context
|
52
35
|
|
@@ -6,6 +6,7 @@ require 'friendly_shipping/services/ups_freight/generate_document_options_hash'
|
|
6
6
|
require 'friendly_shipping/services/ups_freight/generate_email_options_hash'
|
7
7
|
require 'friendly_shipping/services/ups_freight/generate_pickup_options_hash'
|
8
8
|
require 'friendly_shipping/services/ups_freight/generate_delivery_options_hash'
|
9
|
+
require 'friendly_shipping/services/ups_freight/generate_handling_units_hash'
|
9
10
|
|
10
11
|
module FriendlyShipping
|
11
12
|
module Services
|
@@ -33,7 +34,7 @@ module FriendlyShipping
|
|
33
34
|
DeliveryInstructions: options.delivery_instructions,
|
34
35
|
PickupRequest: GeneratePickupRequestHash.call(pickup_request_options: options.pickup_request_options),
|
35
36
|
}.compact.
|
36
|
-
merge(
|
37
|
+
merge(GenerateHandlingUnitsHash.call(shipment: shipment, options: options)).
|
37
38
|
merge(GenerateReferenceHash.call(reference_numbers: options.reference_numbers))
|
38
39
|
}
|
39
40
|
}
|
@@ -48,25 +49,6 @@ module FriendlyShipping
|
|
48
49
|
[email_options, pickup_options, delivery_options].compact.presence
|
49
50
|
end
|
50
51
|
|
51
|
-
def handling_units(shipment, options)
|
52
|
-
all_package_options = shipment.packages.map { |package| options.options_for_package(package) }
|
53
|
-
all_package_options.group_by(&:handling_unit_code).map do |_handling_unit_code, options_group|
|
54
|
-
[options_group.first, options_group.length]
|
55
|
-
end.map { |package_options, quantity| handling_unit_hash(package_options, quantity) }
|
56
|
-
end
|
57
|
-
|
58
|
-
def handling_unit_hash(package_options, quantity)
|
59
|
-
{
|
60
|
-
package_options.handling_unit_tag => {
|
61
|
-
Quantity: quantity.to_s,
|
62
|
-
Type: {
|
63
|
-
Code: package_options.handling_unit_code,
|
64
|
-
Description: package_options.handling_unit_description
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
52
|
def payment_information(options)
|
71
53
|
payer_address = GenerateLocationHash.call(location: options.billing_address).
|
72
54
|
merge(ShipperNumber: options.shipper_number)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class UpsFreight
|
6
|
+
# Generates a handling units hash for JSON serialization.
|
7
|
+
class GenerateHandlingUnitsHash
|
8
|
+
class << self
|
9
|
+
# @param shipment [Physical::Shipment]
|
10
|
+
# @param options [ShipmentOptions]
|
11
|
+
# @return [Hash]
|
12
|
+
def call(shipment:, options:)
|
13
|
+
handling_units(shipment, options).reduce(&:merge)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# @param shipment [Physical::Shipment]
|
19
|
+
# @param options [ShipmentOptions]
|
20
|
+
# @return [Array<Hash>]
|
21
|
+
def handling_units(shipment, options)
|
22
|
+
if shipment.packages.any?
|
23
|
+
warn "[DEPRECATION] `packages` is deprecated. Please use `structures` instead."
|
24
|
+
all_package_options = shipment.packages.map { |package| options.options_for_package(package) }
|
25
|
+
all_package_options.group_by(&:handling_unit_code).map do |_handling_unit_code, options_group|
|
26
|
+
[options_group.first, options_group.length]
|
27
|
+
end.map { |package_options, quantity| handling_unit_hash(package_options, quantity) }
|
28
|
+
else
|
29
|
+
all_structure_options = shipment.structures.map { |structure| options.options_for_structure(structure) }
|
30
|
+
all_structure_options.group_by(&:handling_unit_code).map do |_handling_unit_code, options_group|
|
31
|
+
[options_group.first, options_group.length]
|
32
|
+
end.map { |structure_options, quantity| handling_unit_hash(structure_options, quantity) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param options [PackageOptions, StructureOptions]
|
37
|
+
# @param quantity [Integer]
|
38
|
+
# @return [Hash]
|
39
|
+
def handling_unit_hash(options, quantity)
|
40
|
+
{
|
41
|
+
options.handling_unit_tag.to_sym => {
|
42
|
+
Quantity: quantity.to_s,
|
43
|
+
Type: {
|
44
|
+
Code: options.handling_unit_code,
|
45
|
+
Description: options.handling_unit_description
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
module FriendlyShipping
|
4
4
|
module Services
|
5
5
|
class UpsFreight
|
6
|
+
# Options for generating UPS Freight labels for a shipment.
|
6
7
|
class LabelOptions < RatesOptions
|
8
|
+
# Maps friendly names to reference number codes.
|
7
9
|
REFERENCE_NUMBER_CODES = {
|
8
10
|
bill_of_lading_number: "57",
|
9
11
|
purchase_order_number: "28",
|
@@ -18,16 +20,38 @@ module FriendlyShipping
|
|
18
20
|
other: "OTHER"
|
19
21
|
}.freeze
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
:pickup_options,
|
24
|
-
:delivery_options,
|
25
|
-
:pickup_instructions,
|
26
|
-
:delivery_instructions,
|
27
|
-
:handling_instructions,
|
28
|
-
:reference_numbers
|
23
|
+
# @return [Array<LabelDocumentOptions>]
|
24
|
+
attr_reader :document_options
|
29
25
|
|
30
|
-
# @
|
26
|
+
# @return [Array<LabelEmailOptions>]
|
27
|
+
attr_reader :email_options
|
28
|
+
|
29
|
+
# @return [LabelPickupOptions]
|
30
|
+
attr_reader :pickup_options
|
31
|
+
|
32
|
+
# @return [LabelDeliveryOptions]
|
33
|
+
attr_reader :delivery_options
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
attr_reader :pickup_instructions
|
37
|
+
|
38
|
+
# @return [String]
|
39
|
+
attr_reader :delivery_instructions
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
attr_reader :handling_instructions
|
43
|
+
|
44
|
+
# @return [Array<Hash>]
|
45
|
+
attr_reader :reference_numbers
|
46
|
+
|
47
|
+
# @param document_options [Array<LabelDocumentOptions>]
|
48
|
+
# @param email_options [Array<LabelEmailOptions>]
|
49
|
+
# @param pickup_options [LabelPickupOptions]
|
50
|
+
# @param delivery_options [LabelDeliveryOptions]
|
51
|
+
# @param pickup_instructions [String]
|
52
|
+
# @param delivery_instructions [String]
|
53
|
+
# @param handling_instructions [String]
|
54
|
+
# @param reference_numbers [Array<Hash>] reference numbers for the Bill of Lading
|
31
55
|
def initialize(
|
32
56
|
document_options: [],
|
33
57
|
email_options: [],
|
@@ -47,11 +71,13 @@ module FriendlyShipping
|
|
47
71
|
@delivery_instructions = delivery_instructions
|
48
72
|
@handling_instructions = handling_instructions
|
49
73
|
@reference_numbers = fill_codes(reference_numbers)
|
50
|
-
super(**kwargs)
|
74
|
+
super(**kwargs.reverse_merge(package_options_class: LabelPackageOptions))
|
51
75
|
end
|
52
76
|
|
53
77
|
private
|
54
78
|
|
79
|
+
# @param reference_numbers [Array<Hash>] reference numbers for the Bill of Lading
|
80
|
+
# @return [Array<Hash>] reference numbers with codes filled
|
55
81
|
def fill_codes(reference_numbers)
|
56
82
|
reference_numbers.each do |reference_number|
|
57
83
|
reference_number[:code] = REFERENCE_NUMBER_CODES.fetch(reference_number[:code])
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class UpsFreight
|
6
|
+
class LabelStructureOptions < RatesStructureOptions
|
7
|
+
def initialize(**kwargs)
|
8
|
+
super(**kwargs.reverse_merge(package_options_class: LabelPackageOptions))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|