diff --git a/src/USPS/Rate.php b/src/USPS/Rate.php old mode 100755 new mode 100644 index a664d5a..e9dbc35 --- a/src/USPS/Rate.php +++ b/src/USPS/Rate.php @@ -103,6 +103,22 @@ class Rate extends RateAdapter throw new Exception('Weight missing'); } + $size = Arr::get($this->shipment, 'size'); + + // If user has not specified size, determine it automatically + // https://www.usps.com/business/web-tools-apis/rate-calculator-api.htm#_Toc378922331 + if ($size === null) { + // Size is considered large if any dimension is larger than 12 inches + foreach ($dimensions as $dimension) { + if ($dimension > 12) { + $size = 'LARGE'; + break; + } + } + if (!isset($size)) { + $size = 'REGULAR'; + } + } $this->data = ' @@ -113,7 +129,7 @@ class Rate extends RateAdapter ' . $pounds . ' ' . $ounces . ' ' . Arr::get($this->shipment, 'container') . ' - ' . Arr::get($this->shipment, 'size') . ' + ' . $size . ' ' . Arr::get($dimensions, 'width') . ' ' . Arr::get($dimensions, 'length') . ' ' . Arr::get($dimensions, 'height') . '