diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index cc2964da2..4c5c2ad85 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.8.7 - fixed #11278: Wrong test for Template::Toolkit in testEnvironment.pl + - fixed #11282: USPS Shipping Driver does not accept ZIP+4 7.8.6 - fixed #11250: i18n Asset_EMSSubmissionForm::delete created items label help diff --git a/lib/WebGUI/Shop/ShipDriver/USPS.pm b/lib/WebGUI/Shop/ShipDriver/USPS.pm index d4c32b91f..a1c0fc34a 100644 --- a/lib/WebGUI/Shop/ShipDriver/USPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/USPS.pm @@ -54,9 +54,12 @@ sub buildXML { $xmlTop->{Package} = []; ##Do a request for each package. my $packageIndex; - my $shipType = $self->get('shipType'); - my $service = $shipType eq 'PRIORITY VARIABLE' ? 'PRIORITY' - : $shipType; + my $shipType = $self->get('shipType'); + my $service = $shipType eq 'PRIORITY VARIABLE' + ? 'PRIORITY' + : $shipType; + my $sourceZip = $self->get('sourceZip'); + $sourceZip =~ s/^(\d{5}).*$/$1/; PACKAGE: for(my $packageIndex = 0; $packageIndex < scalar @packages; $packageIndex++) { my $package = $packages[$packageIndex]; next PACKAGE unless scalar @{ $package }; @@ -79,6 +82,7 @@ sub buildXML { } my $destination = $package->[0]->getShippingAddress; my $destZipCode = $destination->get('code'); + $destZipCode =~ s/^(\d{5}).*$/$1/; $packageData{ID} = $packageIndex; $packageData{Service} = [ $service ]; $packageData{ZipOrigination} = [ $self->get('sourceZip') ]; diff --git a/t/Shop/ShipDriver/USPS.t b/t/Shop/ShipDriver/USPS.t index 43c1bcfd5..049c75b2b 100644 --- a/t/Shop/ShipDriver/USPS.t +++ b/t/Shop/ShipDriver/USPS.t @@ -25,7 +25,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; use WebGUI::Shop::ShipDriver::USPS; -plan tests => 66; +plan tests => 69; #---------------------------------------------------------------------------- # Init @@ -232,6 +232,13 @@ my $wucAddress = $addressBook->addAddress({ city => 'Madison', state => 'WI', code => '53703', country => 'United States', }); +my $zip4Address = $addressBook->addAddress({ + label => 'work-zip4', + organization => 'Plain Black Corporation', + address1 => '1360 Regent St. #145', + city => 'Madison', state => 'WI', code => '53715-1255', + country => 'United States', +}); $cart->update({shippingAddressId => $workAddress->getId}); cmp_deeply( @@ -826,6 +833,48 @@ SKIP: { } +####################################################################### +# +# Test ZIP+4 format domestic code +# +####################################################################### +$cart->update({shippingAddressId => $zip4Address->getId}); + +my $xmlData = XMLin($driver->buildXML($cart, @shippableUnits), + KeepRoot => 1, + ForceArray => ['Package'], +); +cmp_deeply( + $xmlData, + { + RateV3Request => { + USERID => $userId, + Package => [ + { + ID => 0, + ZipDestination => '53715', ZipOrigination => '97123', + Pounds => '1', Ounces => '8.0', + Size => 'REGULAR', Service => 'PRIORITY', + Machinable => 'true',# Container => 'VARIABLE', + }, + ], + } + }, + 'buildXML: removed plus4 part of zipcode' +); + +SKIP: { + + skip 'No userId for testing', 2 unless $hasRealUserId; + + my $cost = eval { $driver->calculate($cart); }; + my $e = Exception::Class->caught(); + ok( ! ref $e, 'no exception thrown for zip+4 address'); + cmp_deeply($cost, num(10,9.99), 'zip+4 address returns a valid cost'); + +} + +$cart->update({shippingAddressId => $workAddress->getId}); ####################################################################### # # Check for throwing an exception