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 =
Ups large package min weight.
90- UPS_MAX_WEIGHT =
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
17_280- FEDEX_OVERSIZE_WEIGHT =
Oversize if weight > 110 lbs
110- FEDEX_MAX_WEIGHT =
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 =
Purolator max weight.
150- PUROLATOR_EXPRESS_DIM_WEIGHT_DIVISOR =
Purolator express dim weight divisor.
(12 * 12 * 12 / 15)
- PUROLATOR_GROUND_DIM_WEIGHT_DIVISOR =
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 =
Penalty oversized length plus girth.
165- PENALTY_OVERSIZED_WEIGHT =
Penalty oversized weight.
150
Instance Attribute Summary
Attributes inherited from BaseService
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, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#check_canadapost_max_girth ⇒ Object
346 347 348 349 350 |
# File 'app/services/shipping/package_auditor.rb', line 346 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
334 335 336 337 338 |
# File 'app/services/shipping/package_auditor.rb', line 334 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
340 341 342 343 344 |
# File 'app/services/shipping/package_auditor.rb', line 340 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
298 299 300 301 302 |
# File 'app/services/shipping/package_auditor.rb', line 298 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
304 305 306 307 308 |
# File 'app/services/shipping/package_auditor.rb', line 304 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"
320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/services/shipping/package_auditor.rb', line 320 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"
311 312 313 314 315 316 317 |
# File 'app/services/shipping/package_auditor.rb', line 311 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
283 284 285 286 287 |
# File 'app/services/shipping/package_auditor.rb', line 283 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
245 246 247 248 249 |
# File 'app/services/shipping/package_auditor.rb', line 245 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)
258 259 260 261 262 |
# File 'app/services/shipping/package_auditor.rb', line 258 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
251 252 253 254 255 |
# File 'app/services/shipping/package_auditor.rb', line 251 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
277 278 279 280 281 |
# File 'app/services/shipping/package_auditor.rb', line 277 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
265 266 267 268 269 270 271 272 273 274 275 |
# File 'app/services/shipping/package_auditor.rb', line 265 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
364 365 366 367 368 369 370 371 372 373 374 |
# File 'app/services/shipping/package_auditor.rb', line 364 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 errors[:penalty_girth_limit] ||= "Package length + girth (#{length_plus_girth}) exceeds penalty girth limit of #{PENALTY_OVERSIZED_LENGTH_PLUS_GIRTH}" if length_plus_girth > PENALTY_OVERSIZED_LENGTH_PLUS_GIRTH errors[:penalty_weight_limit] ||= "Package weight (#{weight}) exceeds penalty limit of #{PENALTY_OVERSIZED_WEIGHT}" if weight > PENALTY_OVERSIZED_WEIGHT end |
#check_purolator_express_billable_weight ⇒ Object
137 138 139 140 141 |
# File 'app/services/shipping/package_auditor.rb', line 137 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
143 144 145 146 147 |
# File 'app/services/shipping/package_auditor.rb', line 143 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"
162 163 164 165 166 |
# File 'app/services/shipping/package_auditor.rb', line 162 def check_purolator_large_package return unless 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 |
#check_purolator_over_maximum_limit ⇒ Object
Purolator Over Maximum: weight > 150 lbs, L+G > 165", or length > 108"
169 170 171 |
# File 'app/services/shipping/package_auditor.rb', line 169 def check_purolator_over_maximum_limit errors[:purolator_over_maximum_limit] ||= "Purolator considers this package over maximum limits, $350 extra per piece" if weight > PUROLATOR_MAX_WEIGHT || length_plus_girth > PUROLATOR_MAX_LG || length > PUROLATOR_OVERSIZE_MAX end |
#check_purolator_oversize ⇒ Object
Purolator Oversized: longest side > 48" up to 108"
150 151 152 |
# File 'app/services/shipping/package_auditor.rb', line 150 def check_purolator_oversize errors[:purolator_oversize] ||= "Purolator considers this package oversize (>#{PUROLATOR_OVERSIZE_MIN} in and <= #{PUROLATOR_OVERSIZE_MAX} in), $14 extra per piece" if length > PUROLATOR_OVERSIZE_MIN && length <= PUROLATOR_OVERSIZE_MAX end |
#check_purolator_overweight ⇒ Object
Purolator Oversized: weight > 50 lbs up to 150 lbs
155 156 157 158 159 |
# File 'app/services/shipping/package_auditor.rb', line 155 def check_purolator_overweight return unless 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 |
#check_shipping_insurance ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'app/services/shipping/package_auditor.rb', line 376 def check_shipping_insurance return unless shipment.present? && shipment.delivery.present? && 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) && !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
223 224 225 226 227 |
# File 'app/services/shipping/package_auditor.rb', line 223 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
191 192 193 194 195 |
# File 'app/services/shipping/package_auditor.rb', line 191 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
205 206 207 208 209 |
# File 'app/services/shipping/package_auditor.rb', line 205 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
197 198 199 200 201 |
# File 'app/services/shipping/package_auditor.rb', line 197 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
211 212 213 214 215 |
# File 'app/services/shipping/package_auditor.rb', line 211 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
217 218 219 220 221 |
# File 'app/services/shipping/package_auditor.rb', line 217 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
352 353 354 355 356 |
# File 'app/services/shipping/package_auditor.rb', line 352 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
358 359 360 361 362 |
# File 'app/services/shipping/package_auditor.rb', line 358 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
293 294 295 |
# File 'app/services/shipping/package_auditor.rb', line 293 def fedex_billable_weight [fedex_dimensional_weight, weight].max.ceil end |
#fedex_dimensional_weight ⇒ Object
289 290 291 |
# File 'app/services/shipping/package_auditor.rb', line 289 def fedex_dimensional_weight (rounded_cubic_size / FEDEX_DIM_WEIGHT_DIVISOR).ceil end |
#height ⇒ Object
Alias for Container#height
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#length ⇒ Object
Alias for Container#length
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#length_plus_girth ⇒ Object
Alias for Container#length_plus_girth
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#oversize_conditions? ⇒ Boolean
127 128 129 130 131 132 133 134 135 |
# File 'app/services/shipping/package_auditor.rb', line 127 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.intersect?(oversize_keys) 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
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 116 117 118 119 120 121 122 123 124 125 |
# File 'app/services/shipping/package_auditor.rb', line 76 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
177 178 179 180 |
# File 'app/services/shipping/package_auditor.rb', line 177 def purolator_express_billable_weight weights = [purolator_express_dimensional_weight, weight] weights.max.ceil end |
#purolator_express_dimensional_weight ⇒ Object
173 174 175 |
# File 'app/services/shipping/package_auditor.rb', line 173 def purolator_express_dimensional_weight (rounded_cubic_size / PUROLATOR_EXPRESS_DIM_WEIGHT_DIVISOR).ceil # round up end |
#purolator_ground_billable_weight ⇒ Object
186 187 188 189 |
# File 'app/services/shipping/package_auditor.rb', line 186 def purolator_ground_billable_weight weights = [purolator_ground_dimensional_weight, weight] weights.max.ceil end |
#purolator_ground_dimensional_weight ⇒ Object
182 183 184 |
# File 'app/services/shipping/package_auditor.rb', line 182 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
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#ups_billable_weight ⇒ Object
238 239 240 241 242 |
# File 'app/services/shipping/package_auditor.rb', line 238 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
230 231 232 |
# File 'app/services/shipping/package_auditor.rb', line 230 def ups_dimensional_weight (rounded_cubic_size / UPS_DIM_WEIGHT_DIVISOR).ceil # round up end |
#ups_large_package_surcharge? ⇒ Boolean
234 235 236 |
# File 'app/services/shipping/package_auditor.rb', line 234 def ups_large_package_surcharge? length_plus_girth > UPS_LARGE_PACKAGE_THRESHOLD end |
#weight ⇒ Object
Alias for Container#weight
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |
#width ⇒ Object
Alias for Container#width
73 |
# File 'app/services/shipping/package_auditor.rb', line 73 delegate :length, :width, :height, :weight, :rounded_cubic_size, :length_plus_girth, to: :container |