From c871c0372d9511bb1a4c3448e77a0c2d6fada466 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 5 Nov 2009 08:18:10 -0800 Subject: [PATCH] The current USPS driver only works on domestic shipments. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/ShipDriver/USPS.pm | 8 +++++++- t/Shop/ShipDriver/USPS.t | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7acf173ed..225a2e31e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #11202: USPS driver does not log authentication errors - fixed #10985: Survey: can't add multiple choice answer - fixed #11197: Survey Edit Console is not i18n'ed + - fixed USPS driver only works on domestic addresses. 7.8.3 - Rewrote Spectre's workflow queues to prevent it from "forgetting" about some workflows. diff --git a/lib/WebGUI/Shop/ShipDriver/USPS.pm b/lib/WebGUI/Shop/ShipDriver/USPS.pm index 850ca844a..18828d1ff 100644 --- a/lib/WebGUI/Shop/ShipDriver/USPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/USPS.pm @@ -14,7 +14,7 @@ Package WebGUI::Shop::ShipDriver::USPS =head1 DESCRIPTION -Shipping driver for the United States Postal Service. +Shipping driver for the United States Postal Service, domestic shipping services. =head1 SYNOPSIS @@ -127,6 +127,9 @@ sub calculate { if (! $self->get('userId')) { WebGUI::Error::InvalidParam->throw(error => q{Driver configured without a USPS userId.}); } + if ($cart->getShippingAddress->get('country') ne 'United States') { + WebGUI::Error::InvalidParam->throw(error => q{Driver only handles domestic shipping}); + } my $cost = 0; ##Sort the items into shippable bundles. my @shippableUnits = $self->_getShippableUnits($cart); @@ -428,6 +431,9 @@ sub _getShippableUnits { } else { my $zip = $item->getShippingAddress->get('code'); + if ($item->getShippingAddress->get('country') ne 'United States') { + WebGUI::Error::InvalidParam->throw(error => q{Driver only handles domestic shipping}); + } push @{ $looseUnits{$zip} }, $item; } } diff --git a/t/Shop/ShipDriver/USPS.t b/t/Shop/ShipDriver/USPS.t index 4a66f2bca..a6029f825 100644 --- a/t/Shop/ShipDriver/USPS.t +++ b/t/Shop/ShipDriver/USPS.t @@ -23,10 +23,9 @@ use Data::Dumper; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; +use WebGUI::Shop::ShipDriver::USPS; plan tests => 65; -use_ok('WebGUI::Shop::ShipDriver::USPS') - or die 'Unable to load module WebGUI::Shop::ShipDriver::USPS'; #---------------------------------------------------------------------------- # Init @@ -224,14 +223,14 @@ my $workAddress = $addressBook->addAddress({ organization => 'Plain Black Corporation', address1 => '1360 Regent St. #145', city => 'Madison', state => 'WI', code => '53715', - country => 'USA', + country => 'United States', }); my $wucAddress = $addressBook->addAddress({ label => 'wuc', organization => 'Madison Concourse Hotel', address1 => '1 W Dayton St', city => 'Madison', state => 'WI', code => '53703', - country => 'USA', + country => 'United States', }); $cart->update({shippingAddressId => $workAddress->getId}); @@ -838,6 +837,19 @@ isa_ok($e, 'WebGUI::Error::Shop::RemoteShippingRate', 'calculate throws an excep $properties->{userId} = $userId; $driver->update($properties); +my $dutchAddress = $addressBook->addAddress({ + label => 'dutch', + address1 => 'Rotterdamseweg 183C', + city => 'Delft', code => '2629HD', + country => 'Netherlands', +}); + +$cart->update({shippingAddressId => $dutchAddress->getId}); +$cost = eval { $driver->calculate($cart); }; +$e = Exception::Class->caught(); +isa_ok($e, 'WebGUI::Error::InvalidParam', "calculate won't calculate for foreign countries"); + +$cart->update({shippingAddressId => $workAddress->getId}); ####################################################################### # # _calculateInsurance edge case