Change how the shipping driver throws errors. Fixes bug #11202.
This commit is contained in:
parent
0e703788b2
commit
fc6acc7be3
3 changed files with 81 additions and 50 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
7.8.4
|
7.8.4
|
||||||
- Fixed a compatibility problem between WRE and new Spectre code.
|
- Fixed a compatibility problem between WRE and new Spectre code.
|
||||||
- fixed #11198: Typo in i18n
|
- fixed #11198: Typo in i18n
|
||||||
|
- fixed #11202: USPS driver does not log authentication errors
|
||||||
|
|
||||||
7.8.3
|
7.8.3
|
||||||
- Rewrote Spectre's workflow queues to prevent it from "forgetting" about some workflows.
|
- Rewrote Spectre's workflow queues to prevent it from "forgetting" about some workflows.
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use WebGUI::Exception;
|
||||||
use XML::Simple;
|
use XML::Simple;
|
||||||
use LWP;
|
use LWP;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -142,12 +143,12 @@ sub calculate {
|
||||||
my $response = $self->_doXmlRequest($xml);
|
my $response = $self->_doXmlRequest($xml);
|
||||||
##Error handling
|
##Error handling
|
||||||
if (! $response->is_success) {
|
if (! $response->is_success) {
|
||||||
WebGUI::Error::RemoteShippingRate->throw(error => 'Problem connecting to USPS Web Tools: '. $response->status_line);
|
WebGUI::Error::Shop::RemoteShippingRate->throw(error => 'Problem connecting to USPS Web Tools: '. $response->status_line);
|
||||||
}
|
}
|
||||||
my $returnedXML = $response->content;
|
my $returnedXML = $response->content;
|
||||||
my $xmlData = XMLin($returnedXML, ForceArray => [qw/Package/]);
|
my $xmlData = XMLin($returnedXML, KeepRoot => 1, ForceArray => [qw/Package/]);
|
||||||
if (exists $xmlData->{Error}) {
|
if (exists $xmlData->{Error}) {
|
||||||
WebGUI::Error::RemoteShippingRate->throw(error => 'Problem with USPS Web Tools XML: '. $xmlData->{Description});
|
WebGUI::Error::Shop::RemoteShippingRate->throw(error => 'Problem with USPS Web Tools XML: '. $xmlData->{Error}->{Description});
|
||||||
}
|
}
|
||||||
##Summarize costs from returned data
|
##Summarize costs from returned data
|
||||||
$cost = $self->_calculateFromXML($xmlData, @shippableUnits);
|
$cost = $self->_calculateFromXML($xmlData, @shippableUnits);
|
||||||
|
|
@ -167,14 +168,16 @@ Processed XML data from an XML rate request, processed in perl data structure.
|
||||||
have this structure:
|
have this structure:
|
||||||
|
|
||||||
{
|
{
|
||||||
Package => [
|
RateV3Response => {
|
||||||
{
|
Package => [
|
||||||
ID => 0,
|
{
|
||||||
Postage => {
|
ID => 0,
|
||||||
Rate => some_number
|
Postage => {
|
||||||
}
|
Rate => some_number
|
||||||
},
|
}
|
||||||
]
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 @shippableUnits
|
=head3 @shippableUnits
|
||||||
|
|
@ -186,12 +189,12 @@ The set of shippable units, which are required to do quantity lookups.
|
||||||
sub _calculateFromXML {
|
sub _calculateFromXML {
|
||||||
my ($self, $xmlData, @shippableUnits) = @_;
|
my ($self, $xmlData, @shippableUnits) = @_;
|
||||||
my $cost = 0;
|
my $cost = 0;
|
||||||
foreach my $package (@{ $xmlData->{Package} }) {
|
foreach my $package (@{ $xmlData->{RateV3Response}->{Package} }) {
|
||||||
my $id = $package->{ID};
|
my $id = $package->{ID};
|
||||||
my $rate = $package->{Postage}->{Rate};
|
my $rate = $package->{Postage}->{Rate};
|
||||||
##Error check for invalid index
|
##Error check for invalid index
|
||||||
if ($id < 0 || $id > $#shippableUnits) {
|
if ($id < 0 || $id > $#shippableUnits) {
|
||||||
WebGUI::Error::RemoteShippingRate->throw(error => "Illegal package index returned by USPS: $id");
|
WebGUI::Error::Shop::RemoteShippingRate->throw(error => "Illegal package index returned by USPS: $id");
|
||||||
}
|
}
|
||||||
my $unit = $shippableUnits[$id];
|
my $unit = $shippableUnits[$id];
|
||||||
if ($unit->[0]->getSku->shipsSeparately) {
|
if ($unit->[0]->getSku->shipsSeparately) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ use Data::Dumper;
|
||||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
|
||||||
plan tests => 64;
|
plan tests => 65;
|
||||||
use_ok('WebGUI::Shop::ShipDriver::USPS')
|
use_ok('WebGUI::Shop::ShipDriver::USPS')
|
||||||
or die 'Unable to load module WebGUI::Shop::ShipDriver::USPS';
|
or die 'Unable to load module WebGUI::Shop::ShipDriver::USPS';
|
||||||
|
|
||||||
|
|
@ -377,15 +377,18 @@ SKIP: {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $cost = $driver->_calculateFromXML({
|
my $cost = $driver->_calculateFromXML(
|
||||||
Package => [
|
{
|
||||||
{
|
RateV3Response => {
|
||||||
ID => 0,
|
Package => [
|
||||||
Postage => {
|
{
|
||||||
Rate => 5.25,
|
ID => 0,
|
||||||
},
|
Postage => {
|
||||||
|
Rate => 5.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
},
|
||||||
@shippableUnits
|
@shippableUnits
|
||||||
);
|
);
|
||||||
|
|
@ -471,21 +474,24 @@ SKIP: {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cost = $driver->_calculateFromXML({
|
$cost = $driver->_calculateFromXML(
|
||||||
Package => [
|
{
|
||||||
{
|
RateV3Response => {
|
||||||
ID => 0,
|
Package => [
|
||||||
Postage => {
|
{
|
||||||
Rate => 7.00,
|
ID => 0,
|
||||||
},
|
Postage => {
|
||||||
|
Rate => 7.00,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID => 1,
|
||||||
|
Postage => {
|
||||||
|
Rate => 5.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ID => 1,
|
|
||||||
Postage => {
|
|
||||||
Rate => 5.25,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
@shippableUnits
|
@shippableUnits
|
||||||
);
|
);
|
||||||
|
|
@ -497,21 +503,24 @@ $bibleItem->setQuantity(2);
|
||||||
|
|
||||||
is(calculateInsurance($driver), 8, '_calculateInsurance: two items in cart with quantity=2, calculates insurance');
|
is(calculateInsurance($driver), 8, '_calculateInsurance: two items in cart with quantity=2, calculates insurance');
|
||||||
|
|
||||||
$cost = $driver->_calculateFromXML({
|
$cost = $driver->_calculateFromXML(
|
||||||
Package => [
|
{
|
||||||
{
|
RateV3Response => {
|
||||||
ID => 0,
|
Package => [
|
||||||
Postage => {
|
{
|
||||||
Rate => 7.00,
|
ID => 0,
|
||||||
},
|
Postage => {
|
||||||
|
Rate => 7.00,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID => 1,
|
||||||
|
Postage => {
|
||||||
|
Rate => 5.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ID => 1,
|
|
||||||
Postage => {
|
|
||||||
Rate => 5.25,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
@shippableUnits
|
@shippableUnits
|
||||||
);
|
);
|
||||||
|
|
@ -811,6 +820,24 @@ SKIP: {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# Check for throwing an exception
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
my $userId = $driver->get('userId');
|
||||||
|
$properties = $driver->get();
|
||||||
|
$properties->{userId} = '__NEVER_GOING_TO_HAPPEN__';
|
||||||
|
$driver->update($properties);
|
||||||
|
|
||||||
|
$cost = eval { $driver->calculate($cart); };
|
||||||
|
$e = Exception::Class->caught();
|
||||||
|
isa_ok($e, 'WebGUI::Error::Shop::RemoteShippingRate', 'calculate throws an exception when a bad userId is used');
|
||||||
|
|
||||||
|
$properties->{userId} = $userId;
|
||||||
|
$driver->update($properties);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# _calculateInsurance edge case
|
# _calculateInsurance edge case
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue