Class: Shipping::PackageAuditor
- Inherits:
-
BaseService
- Object
- BaseService
- Shipping::PackageAuditor
- Includes:
- ActiveModel::API, ActiveModel::Attributes
- Defined in:
- app/services/shipping/package_auditor.rb
Overview
Feed me a container and i'll tell you what pricing rules will trigger
Constant Summary collapse
- UPS_LENGTH_HANDLING =
48- UPS_WIDTH_HANDLING =
Additional handling if length > 48"
30- UPS_WEIGHT_HANDLING_DOMESTIC =
Additional handling if 2nd longest side > 30"
50- UPS_WEIGHT_HANDLING_INTERNATIONAL =
Additional handling if weight > 50 lbs (domestic)
70- UPS_DIM_WEIGHT_DIVISOR =
Additional handling if weight > 70 lbs (international)
139- UPS_LARGE_PACKAGE_THRESHOLD =
Large package if L+G > 130"
130- UPS_LARGE_PACKAGE_MIN_WEIGHT =
90- UPS_MAX_WEIGHT =
150- FEDEX_LENGTH_HANDLING =
FedEx thresholds (https://www.fedex.com/en-us/shipping/current-rates/surcharges-and-fees.html)
48- FEDEX_WIDTH_HANDLING =
Additional handling if length > 48"
30- FEDEX_WEIGHT_HANDLING_DOMESTIC =
Additional handling if 2nd longest side > 30"
50- FEDEX_WEIGHT_HANDLING_INTERNATIONAL =
Additional handling if weight > 50 lbs (domestic)
55- FEDEX_DIM_WEIGHT_DIVISOR =
Additional handling if weight > 55 lbs (international, as of July 2025)
139- FEDEX_LARGE_PACKAGE_THRESHOLD =
Large package if L+G > 130"
130- FEDEX_OVERSIZE_LENGTH =
Oversize if length > 96"
96- FEDEX_OVERSIZE_CUBIC =
Oversize if cubic volume > 17,280 cu in
17280- FEDEX_OVERSIZE_WEIGHT =
Oversize if weight > 110 lbs
110- FEDEX_MAX_WEIGHT =
150- PUROLATOR_WEIGHT_HANDLING =
Purolator thresholds (https://www.purolator.com/en/special-handling-and-dangerous-goods)
50- PUROLATOR_LARGE_PACKAGE_THRESHOLD =
Oversized surcharge if weight > 50 lbs
130- PUROLATOR_MAX_LG =
Large package if L+G > 130"
165- PUROLATOR_OVERSIZE_MIN =
Oversized if length > 48"
48- PUROLATOR_OVERSIZE_MAX =
Over maximum if length > 108"
108- PUROLATOR_MAX_WEIGHT =
150- PUROLATOR_EXPRESS_DIM_WEIGHT_DIVISOR =
(12*12*12/15)
- PUROLATOR_GROUND_DIM_WEIGHT_DIVISOR =
(12*12*12/12.4)
- CANPAR_LENGTH_HANDLING =
Canpar thresholds (https://www.canpar.com - similar to Purolator)
48- CANPAR_WEIGHT_HANDLING =
Over Length if any dimension > 48"
70- CANPAR_LARGE_PACKAGE_THRESHOLD =
Overweight if weight > 70 lbs
130- CANPAR_OVERSIZE_LENGTH =
Oversize if L+G > 130"
96- CANPAR_MAX_LENGTH =
Oversize if length > 96"
108- CANPAR_MAX_LG =
OverMax if any dimension > 108"
165- CANPAR_MAX_WEIGHT =
OverMax if L+G > 165"
150- CANADAPOST_MAX_LENGTH =
Canada Post thresholds (https://www.canadapost.ca/tools/pg/manual/PGpscanada-e.asp)
78.7402- CANADAPOST_MAX_GIRTH =
2m in inches
118.11- CANADAPOST_MAX_WEIGHT =
3m in inches
66.1387- USPS_MAX_LENGTH_PLUS_GIRTH =
USPS thresholds (https://www.usps.com/ship/prepare-packages.htm)
130- USPS_MAX_WEIGHT =
Ground Advantage limit (standard is 108")
70- PENALTY_OVERSIZED_DIMENSION =
Internal penalty thresholds
108- PENALTY_OVERSIZED_LENGTH_PLUS_GIRTH =
165- PENALTY_OVERSIZED_WEIGHT =
150
Delegated Instance Attributes collapse
-
#height ⇒ Object
Alias for Container#height.
-
#length ⇒ Object
Alias for Container#length.
-
#length_plus_girth ⇒ Object
Alias for Container#length_plus_girth.
-
#rounded_cubic_size ⇒ Object
Alias for Container#rounded_cubic_size.
-
#weight ⇒ Object
Alias for Container#weight.
-
#width ⇒ Object
Alias for Container#width.
Instance Method Summary collapse
- #check_canadapost_max_girth ⇒ Object
- #check_canadapost_maximum_length ⇒ Object
- #check_canadapost_maximum_weight ⇒ Object
-
#check_canpar_handling_length ⇒ Object
Canpar checks.
- #check_canpar_handling_weight ⇒ Object
-
#check_canpar_over_maximum ⇒ Object
Canpar OverMax: any dimension > 108", weight > 150 lbs, or L+G > 165".
-
#check_canpar_oversize ⇒ Object
Canpar Oversize: L+G > 130" or length > 96".
- #check_fedex_billable_weight ⇒ Object
-
#check_fedex_handling_length ⇒ Object
FedEx Additional Handling checks.
-
#check_fedex_handling_weight ⇒ Object
FedEx domestic threshold is 50 lbs, international is 55 lbs (as of July 2025).
- #check_fedex_handling_width ⇒ Object
- #check_fedex_maximum_weight ⇒ Object
-
#check_fedex_oversize ⇒ Object
FedEx Oversize: L+G > 130", length > 96", cubic > 17,280, or weight > 110 lbs.
- #check_package_penalty_oversized ⇒ Object
- #check_purolator_express_billable_weight ⇒ Object
- #check_purolator_ground_billable_weight ⇒ Object
-
#check_purolator_large_package ⇒ Object
Purolator Large Package: L+G > 130" up to 165".
-
#check_purolator_over_maximum_limit ⇒ Object
Purolator Over Maximum: weight > 150 lbs, L+G > 165", or length > 108".
-
#check_purolator_oversize ⇒ Object
Purolator Oversized: longest side > 48" up to 108".
-
#check_purolator_overweight ⇒ Object
Purolator Oversized: weight > 50 lbs up to 150 lbs.
- #check_shipping_insurance ⇒ Object
- #check_ups_billable_weight ⇒ Object
- #check_ups_handling_length ⇒ Object
-
#check_ups_handling_weight ⇒ Object
UPS domestic threshold is 50 lbs, international is 70 lbs We use domestic threshold as default since most shipments are domestic.
- #check_ups_handling_width ⇒ Object
- #check_ups_large_package_surcharge ⇒ Object
- #check_ups_maximum_weight ⇒ Object
- #check_usps_max_girth ⇒ Object
- #check_usps_max_weight ⇒ Object
- #fedex_billable_weight ⇒ Object
- #fedex_dimensional_weight ⇒ Object
- #oversize_conditions? ⇒ Boolean
-
#process(container, carriers: nil, services: nil, shipment: nil) ⇒ Object
Feed me an instance of Shipping::Container and i'll tell you what's wrong with it.
- #purolator_express_billable_weight ⇒ Object
- #purolator_express_dimensional_weight ⇒ Object
- #purolator_ground_billable_weight ⇒ Object
- #purolator_ground_dimensional_weight ⇒ Object
- #ups_billable_weight ⇒ Object
- #ups_dimensional_weight ⇒ Object
- #ups_large_package_surcharge? ⇒ Boolean
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#check_canadapost_max_girth ⇒ Object
323 324 325 326 |
# File 'app/services/shipping/package_auditor.rb', line 323 def check_canadapost_max_girth return unless length_plus_girth > CANADAPOST_MAX_GIRTH errors[:canadapost_girth_limit] ||= "CanadaPost package length + girth (#{length_plus_girth}) exceeds girth limit of #{CANADAPOST_MAX_GIRTH}" end |
#check_canadapost_maximum_length ⇒ Object
313 314 315 316 |
# File 'app/services/shipping/package_auditor.rb', line 313 def check_canadapost_maximum_length return unless length > CANADAPOST_MAX_LENGTH errors[:canadapost_length_limit] ||= "Canadapost package exceeds length limit of #{CANADAPOST_MAX_LENGTH} in" end |
#check_canadapost_maximum_weight ⇒ Object
318 319 320 321 |
# File 'app/services/shipping/package_auditor.rb', line 318 def check_canadapost_maximum_weight return unless weight > CANADAPOST_MAX_WEIGHT errors[:canadapost_weight_limit] ||= "Canadapost package exceeds weight limit of #{CANADAPOST_MAX_WEIGHT} lbs" end |
#check_canpar_handling_length ⇒ Object
Canpar checks
279 280 281 282 |
# File 'app/services/shipping/package_auditor.rb', line 279 def check_canpar_handling_length return unless length && length.ceil > CANPAR_LENGTH_HANDLING errors[:canpar_length_handling] ||= "Canpar over length fee if any dimension > #{CANPAR_LENGTH_HANDLING} in" end |
#check_canpar_handling_weight ⇒ Object
284 285 286 287 |
# File 'app/services/shipping/package_auditor.rb', line 284 def check_canpar_handling_weight return unless weight && weight.ceil > CANPAR_WEIGHT_HANDLING && weight <= CANPAR_MAX_WEIGHT errors[:canpar_weight_handling] ||= "Canpar overweight fee if weight > #{CANPAR_WEIGHT_HANDLING} lbs" end |
#check_canpar_over_maximum ⇒ Object
Canpar OverMax: any dimension > 108", weight > 150 lbs, or L+G > 165"
299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'app/services/shipping/package_auditor.rb', line 299 def check_canpar_over_maximum if length && length > CANPAR_MAX_LENGTH errors[:canpar_over_maximum] ||= "Canpar OverMax: dimension (#{length}) > #{CANPAR_MAX_LENGTH} in" elsif width && width > CANPAR_MAX_LENGTH errors[:canpar_over_maximum] ||= "Canpar OverMax: dimension (#{width}) > #{CANPAR_MAX_LENGTH} in" elsif height && height > CANPAR_MAX_LENGTH errors[:canpar_over_maximum] ||= "Canpar OverMax: dimension (#{height}) > #{CANPAR_MAX_LENGTH} in" elsif weight && weight > CANPAR_MAX_WEIGHT errors[:canpar_over_maximum] ||= "Canpar OverMax: weight (#{weight}) > #{CANPAR_MAX_WEIGHT} lbs" elsif length_plus_girth > CANPAR_MAX_LG errors[:canpar_over_maximum] ||= "Canpar OverMax: length + girth (#{length_plus_girth}) > #{CANPAR_MAX_LG} in" end end |
#check_canpar_oversize ⇒ Object
Canpar Oversize: L+G > 130" or length > 96"
290 291 292 293 294 295 296 |
# File 'app/services/shipping/package_auditor.rb', line 290 def check_canpar_oversize if length_plus_girth > CANPAR_LARGE_PACKAGE_THRESHOLD && length_plus_girth <= CANPAR_MAX_LG errors[:canpar_oversize] ||= "Canpar oversize fee: length + girth (#{length_plus_girth}) > #{CANPAR_LARGE_PACKAGE_THRESHOLD} in" elsif length && length > CANPAR_OVERSIZE_LENGTH && length <= CANPAR_MAX_LENGTH errors[:canpar_oversize] ||= "Canpar oversize fee: length (#{length}) > #{CANPAR_OVERSIZE_LENGTH} in" end end |
#check_fedex_billable_weight ⇒ Object
265 266 267 268 |
# File 'app/services/shipping/package_auditor.rb', line 265 def check_fedex_billable_weight return unless weight && fedex_billable_weight > weight.ceil errors[:fedex_billable_weight] ||= "FedEx Billable weight is #{fedex_billable_weight} lbs instead of package weight of #{weight.ceil} lbs" end |
#check_fedex_handling_length ⇒ Object
FedEx Additional Handling checks
231 232 233 234 |
# File 'app/services/shipping/package_auditor.rb', line 231 def check_fedex_handling_length return unless length && length.ceil > FEDEX_LENGTH_HANDLING errors[:fedex_length_handling] ||= "FedEx adds additional handling fee if length > #{FEDEX_LENGTH_HANDLING} in" end |
#check_fedex_handling_weight ⇒ Object
FedEx domestic threshold is 50 lbs, international is 55 lbs (as of July 2025)
242 243 244 245 |
# File 'app/services/shipping/package_auditor.rb', line 242 def check_fedex_handling_weight return unless weight && weight.ceil > FEDEX_WEIGHT_HANDLING_DOMESTIC errors[:fedex_weight_handling] ||= "FedEx adds additional handling fee if weight > #{FEDEX_WEIGHT_HANDLING_DOMESTIC} lbs" end |
#check_fedex_handling_width ⇒ Object
236 237 238 239 |
# File 'app/services/shipping/package_auditor.rb', line 236 def check_fedex_handling_width return unless width && width.ceil > FEDEX_WIDTH_HANDLING errors[:fedex_width_handling] ||= "FedEx adds additional handling fee if width > #{FEDEX_WIDTH_HANDLING} in" end |
#check_fedex_maximum_weight ⇒ Object
260 261 262 263 |
# File 'app/services/shipping/package_auditor.rb', line 260 def check_fedex_maximum_weight return unless weight && weight > FEDEX_MAX_WEIGHT errors[:fedex_weight_limit] ||= "FedEx package exceeds weight limit of #{FEDEX_MAX_WEIGHT} lbs" end |
#check_fedex_oversize ⇒ Object
FedEx Oversize: L+G > 130", length > 96", cubic > 17,280, or weight > 110 lbs
248 249 250 251 252 253 254 255 256 257 258 |
# File 'app/services/shipping/package_auditor.rb', line 248 def check_fedex_oversize if length_plus_girth > FEDEX_LARGE_PACKAGE_THRESHOLD errors[:fedex_oversize] ||= "FedEx oversize surcharge: length + girth (#{length_plus_girth}) > #{FEDEX_LARGE_PACKAGE_THRESHOLD} in" elsif length && length > FEDEX_OVERSIZE_LENGTH errors[:fedex_oversize] ||= "FedEx oversize surcharge: length (#{length}) > #{FEDEX_OVERSIZE_LENGTH} in" elsif rounded_cubic_size && rounded_cubic_size > FEDEX_OVERSIZE_CUBIC errors[:fedex_oversize] ||= "FedEx oversize surcharge: cubic volume (#{rounded_cubic_size}) > #{FEDEX_OVERSIZE_CUBIC} cu in" elsif weight && weight > FEDEX_OVERSIZE_WEIGHT errors[:fedex_oversize] ||= "FedEx oversize surcharge: weight (#{weight}) > #{FEDEX_OVERSIZE_WEIGHT} lbs" end end |
#check_package_penalty_oversized ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'app/services/shipping/package_auditor.rb', line 338 def check_package_penalty_oversized if length > PENALTY_OVERSIZED_DIMENSION errors[:penalty_dimension_limit] ||= "Package length (#{length}) exceeds penalty limit of #{PENALTY_OVERSIZED_DIMENSION}" elsif width > PENALTY_OVERSIZED_DIMENSION errors[:penalty_dimension_limit] ||= "Package width (#{width}) exceeds penalty limit of #{PENALTY_OVERSIZED_DIMENSION}" elsif height > PENALTY_OVERSIZED_DIMENSION errors[:penalty_dimension_limit] ||= "Package height (#{height}) exceeds penalty limit of #{PENALTY_OVERSIZED_DIMENSION}" end if length_plus_girth > PENALTY_OVERSIZED_LENGTH_PLUS_GIRTH errors[:penalty_girth_limit] ||= "Package length + girth (#{length_plus_girth}) exceeds penalty girth limit of #{PENALTY_OVERSIZED_LENGTH_PLUS_GIRTH}" end if weight > PENALTY_OVERSIZED_WEIGHT errors[:penalty_weight_limit] ||= "Package weight (#{weight}) exceeds penalty limit of #{PENALTY_OVERSIZED_WEIGHT}" end end |
#check_purolator_express_billable_weight ⇒ Object
127 128 129 130 |
# File 'app/services/shipping/package_auditor.rb', line 127 def check_purolator_express_billable_weight return unless weight && purolator_express_billable_weight > weight.ceil errors[:purolator_billable_weight] ||= "Purolator Express Billable weight is #{purolator_express_billable_weight} lbs instead of package weight of #{weight.ceil} lbs" end |
#check_purolator_ground_billable_weight ⇒ Object
132 133 134 135 |
# File 'app/services/shipping/package_auditor.rb', line 132 def check_purolator_ground_billable_weight return unless weight && purolator_ground_billable_weight > weight.ceil errors[:purolator_billable_weight] ||= "Purolator Ground Billable weight is #{purolator_ground_billable_weight} lbs instead of package weight of #{weight.ceil} lbs" end |
#check_purolator_large_package ⇒ Object
Purolator Large Package: L+G > 130" up to 165"
152 153 154 155 156 |
# File 'app/services/shipping/package_auditor.rb', line 152 def check_purolator_large_package if length_plus_girth > PUROLATOR_LARGE_PACKAGE_THRESHOLD && length_plus_girth < PUROLATOR_MAX_LG errors[:purolator_large_package] ||= "Purolator considers this large package (L+2(W+H)) >#{PUROLATOR_LARGE_PACKAGE_THRESHOLD} in up to #{PUROLATOR_MAX_LG} in, $65 extra per piece" end end |
#check_purolator_over_maximum_limit ⇒ Object
Purolator Over Maximum: weight > 150 lbs, L+G > 165", or length > 108"
159 160 161 162 163 |
# File 'app/services/shipping/package_auditor.rb', line 159 def check_purolator_over_maximum_limit if weight > PUROLATOR_MAX_WEIGHT || length_plus_girth > PUROLATOR_MAX_LG || length > PUROLATOR_OVERSIZE_MAX errors[:purolator_over_maximum_limit] ||= "Purolator considers this package over maximum limits, $350 extra per piece" end end |
#check_purolator_oversize ⇒ Object
Purolator Oversized: longest side > 48" up to 108"
138 139 140 141 142 |
# File 'app/services/shipping/package_auditor.rb', line 138 def check_purolator_oversize if length > PUROLATOR_OVERSIZE_MIN && length <= PUROLATOR_OVERSIZE_MAX errors[:purolator_oversize] ||= "Purolator considers this package oversize (>#{PUROLATOR_OVERSIZE_MIN} in and <= #{PUROLATOR_OVERSIZE_MAX} in), $14 extra per piece" end end |
#check_purolator_overweight ⇒ Object
Purolator Oversized: weight > 50 lbs up to 150 lbs
145 146 147 148 149 |
# File 'app/services/shipping/package_auditor.rb', line 145 def check_purolator_overweight if weight > PUROLATOR_WEIGHT_HANDLING && weight < PUROLATOR_MAX_WEIGHT errors[:purolator_overweight] ||= "Purolator considers this overweight (>#{PUROLATOR_WEIGHT_HANDLING}lbs up to #{PUROLATOR_MAX_WEIGHT}lbs) and will add $14 per piece or $50 in residential delivery areas" end end |
#check_shipping_insurance ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'app/services/shipping/package_auditor.rb', line 354 def check_shipping_insurance return unless shipment.present? and shipment.delivery.present? and Shipping::ShippingInsurance.new.(shipment.delivery) alert_msg = nil alert_sig_msg = nil calculated_value = shipment.compute_shipment_declared_value.round limited_insured_value = Shipping::ShippingInsurance.new.get_shipping_insurance_insured_value_for_shipment(shipment).round if calculated_value > limited_insured_value # flag this per shipment alert_msg = "Calculated insured value of $#{calculated_value} exceeds shipping insurance coverage of $#{limited_insured_value}, insurance will be limited." if calculated_value > Shipping::ShippingInsurance::SIGNATURE_CONFIRMATION_REQUIRED_COVERAGE_LIMIT and !shipment.delivery.signature_confirmation.to_b # flag this unless we already have signature_confirmation set alert_sig_msg = "*ADDING SIGNATURE CONFIRMATION WILL INCREASE THE SHIPPING INSURANCE COVERAGE*." end end errors[:shipping_insurance] ||= "#{alert_msg} #{alert_sig_msg}" if alert_msg.present? end |
#check_ups_billable_weight ⇒ Object
210 211 212 213 |
# File 'app/services/shipping/package_auditor.rb', line 210 def check_ups_billable_weight return unless weight && ups_billable_weight > weight.ceil errors[:ups_billable_weight] ||= "UPS Billable weight is #{ups_billable_weight} lbs instead of package weight of #{weight.ceil} lbs" end |
#check_ups_handling_length ⇒ Object
183 184 185 186 |
# File 'app/services/shipping/package_auditor.rb', line 183 def check_ups_handling_length return unless length && length.ceil > UPS_LENGTH_HANDLING errors[:ups_length_handling] ||= "UPS adds additional handling fee if length > #{UPS_LENGTH_HANDLING} in" end |
#check_ups_handling_weight ⇒ Object
UPS domestic threshold is 50 lbs, international is 70 lbs
We use domestic threshold as default since most shipments are domestic
195 196 197 198 |
# File 'app/services/shipping/package_auditor.rb', line 195 def check_ups_handling_weight return unless weight && weight.ceil > UPS_WEIGHT_HANDLING_DOMESTIC errors[:ups_weight_handling] ||= "UPS adds additional handling fee if weight > #{UPS_WEIGHT_HANDLING_DOMESTIC} lbs" end |
#check_ups_handling_width ⇒ Object
188 189 190 191 |
# File 'app/services/shipping/package_auditor.rb', line 188 def check_ups_handling_width return unless width && width.ceil > UPS_WIDTH_HANDLING errors[:ups_width_handling] ||= "UPS adds additional handling fee if width > #{UPS_WIDTH_HANDLING} in" end |
#check_ups_large_package_surcharge ⇒ Object
200 201 202 203 |
# File 'app/services/shipping/package_auditor.rb', line 200 def check_ups_large_package_surcharge return unless ups_large_package_surcharge? errors[:ups_large_package_surcharge] ||= "UPS adds large package surcharge due to dimensions, length + girth (#{length_plus_girth}) > #{UPS_LARGE_PACKAGE_THRESHOLD}" end |
#check_ups_maximum_weight ⇒ Object
205 206 207 208 |
# File 'app/services/shipping/package_auditor.rb', line 205 def check_ups_maximum_weight return unless weight > UPS_MAX_WEIGHT errors[:ups_weight_limit] ||= "UPS package exceeds weight limit of #{UPS_MAX_WEIGHT} lbs" end |
#check_usps_max_girth ⇒ Object
328 329 330 331 |
# File 'app/services/shipping/package_auditor.rb', line 328 def check_usps_max_girth return unless length_plus_girth > USPS_MAX_LENGTH_PLUS_GIRTH errors[:usps_girth_limit] ||= "USPS package length + girth (#{length_plus_girth}) exceeds limit of #{USPS_MAX_LENGTH_PLUS_GIRTH} inches" end |
#check_usps_max_weight ⇒ Object
333 334 335 336 |
# File 'app/services/shipping/package_auditor.rb', line 333 def check_usps_max_weight return unless weight && weight > USPS_MAX_WEIGHT errors[:usps_weight_limit] ||= "USPS package weight (#{weight} lbs) exceeds limit of #{USPS_MAX_WEIGHT} lbs" end |
#fedex_billable_weight ⇒ Object
274 275 276 |
# File 'app/services/shipping/package_auditor.rb', line 274 def fedex_billable_weight [fedex_dimensional_weight, weight].max.ceil end |
#fedex_dimensional_weight ⇒ Object
270 271 272 |
# File 'app/services/shipping/package_auditor.rb', line 270 def fedex_dimensional_weight (rounded_cubic_size / FEDEX_DIM_WEIGHT_DIVISOR).ceil end |
#height ⇒ Object
Alias for Container#height
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#length ⇒ Object
Alias for Container#length
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#length_plus_girth ⇒ Object
Alias for Container#length_plus_girth
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#oversize_conditions? ⇒ Boolean
117 118 119 120 121 122 123 124 125 |
# File 'app/services/shipping/package_auditor.rb', line 117 def oversize_conditions? oversize_keys = %i[ ups_large_package_surcharge ups_length_handling ups_weight_limit ups_width_handling fedex_oversize fedex_length_handling fedex_width_handling purolator_oversize purolator_overweight canpar_oversize canpar_over_maximum ] (errors.keys & oversize_keys).present? end |
#process(container, carriers: nil, services: nil, shipment: nil) ⇒ Object
Feed me an instance of Shipping::Container and i'll tell you what's wrong with it
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/services/shipping/package_auditor.rb', line 67 def process(container, carriers: nil, services: nil, shipment: nil) raise 'Invalid container parameter, must be Shipping::Container' unless container.is_a?(Shipping::Container) self.errors = {} self.container = container self.shipment = shipment if carriers.blank? || carriers.include?('UPS') check_ups_handling_length check_ups_handling_width check_ups_handling_weight check_ups_large_package_surcharge check_ups_maximum_weight check_ups_billable_weight end if carriers.blank? || carriers.include?('FedEx') check_fedex_handling_length check_fedex_handling_width check_fedex_handling_weight check_fedex_oversize check_fedex_maximum_weight check_fedex_billable_weight end if carriers.blank? || carriers.include?('Purolator') check_purolator_overweight check_purolator_oversize check_purolator_large_package # We will only record one issue when it comes to billable weight and we will give preference to express being the most restrictive check_purolator_express_billable_weight if services.blank? || services.any?{|s| s =~ /^purolator_express/} check_purolator_ground_billable_weight if services.blank? || services.any?{|s| s =~ /^purolator_ground/} end if carriers.blank? || carriers.include?('Canpar') check_canpar_handling_length check_canpar_handling_weight check_canpar_oversize check_canpar_over_maximum end if carriers.blank? || carriers.include?('Canadapost') #https://www.canadapost.ca/tools/pg/manual/PGpscanada-e.asp check_canadapost_maximum_length check_canadapost_maximum_weight check_canadapost_max_girth end if carriers.blank? || carriers.include?('Usps') || carriers.include?('USPS') check_usps_max_girth check_usps_max_weight end check_package_penalty_oversized if shipment&.carton? check_shipping_insurance if shipment.present? errors end |
#purolator_express_billable_weight ⇒ Object
169 170 171 172 |
# File 'app/services/shipping/package_auditor.rb', line 169 def purolator_express_billable_weight weights = [purolator_express_dimensional_weight, weight] weights.max.ceil end |
#purolator_express_dimensional_weight ⇒ Object
165 166 167 |
# File 'app/services/shipping/package_auditor.rb', line 165 def purolator_express_dimensional_weight ( rounded_cubic_size / PUROLATOR_EXPRESS_DIM_WEIGHT_DIVISOR ).ceil #round up end |
#purolator_ground_billable_weight ⇒ Object
178 179 180 181 |
# File 'app/services/shipping/package_auditor.rb', line 178 def purolator_ground_billable_weight weights = [purolator_ground_dimensional_weight, weight] weights.max.ceil end |
#purolator_ground_dimensional_weight ⇒ Object
174 175 176 |
# File 'app/services/shipping/package_auditor.rb', line 174 def purolator_ground_dimensional_weight ( rounded_cubic_size / PUROLATOR_GROUND_DIM_WEIGHT_DIVISOR ).ceil #round up end |
#rounded_cubic_size ⇒ Object
Alias for Container#rounded_cubic_size
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#ups_billable_weight ⇒ Object
224 225 226 227 228 |
# File 'app/services/shipping/package_auditor.rb', line 224 def ups_billable_weight weights = [ups_dimensional_weight, weight] weights << UPS_LARGE_PACKAGE_MIN_WEIGHT if ups_large_package_surcharge? # https://www.ups.com/us/en/help-center/sri/glo-lpks.page weights.max.ceil end |
#ups_dimensional_weight ⇒ Object
216 217 218 |
# File 'app/services/shipping/package_auditor.rb', line 216 def ups_dimensional_weight ( rounded_cubic_size / UPS_DIM_WEIGHT_DIVISOR ).ceil #round up end |
#ups_large_package_surcharge? ⇒ Boolean
220 221 222 |
# File 'app/services/shipping/package_auditor.rb', line 220 def ups_large_package_surcharge? length_plus_girth > UPS_LARGE_PACKAGE_THRESHOLD end |
#weight ⇒ Object
Alias for Container#weight
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#width ⇒ Object
Alias for Container#width
64 |
# File 'app/services/shipping/package_auditor.rb', line 64 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |