diff --git a/src/USPS/Rate.php b/src/USPS/Rate.php index 33b43fe..e9dbc35 100644 --- a/src/USPS/Rate.php +++ b/src/USPS/Rate.php @@ -78,10 +78,6 @@ class Rate extends RateAdapter $this->password = $options['password']; } - if (isset($options['username'])) { - $this->username = $options['username']; - } - if (isset($options['approved_codes'])) { $this->approved_codes = $options['approved_codes']; } @@ -107,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 = ' @@ -117,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') . '