Test whether ValueOfContents works in Domestic rate estimates.
This commit is contained in:
parent
4ee1f56aa3
commit
2b4bfb8eec
2 changed files with 67 additions and 0 deletions
|
|
@ -61,15 +61,19 @@ sub buildXML {
|
||||||
next PACKAGE unless scalar @{ $package };
|
next PACKAGE unless scalar @{ $package };
|
||||||
tie my %packageData, 'Tie::IxHash';
|
tie my %packageData, 'Tie::IxHash';
|
||||||
my $weight = 0;
|
my $weight = 0;
|
||||||
|
my $cost = 0;
|
||||||
foreach my $item (@{ $package }) {
|
foreach my $item (@{ $package }) {
|
||||||
my $sku = $item->getSku;
|
my $sku = $item->getSku;
|
||||||
my $itemWeight = $sku->getWeight();
|
my $itemWeight = $sku->getWeight();
|
||||||
|
my $itemCost = $sku->getPrice();
|
||||||
##Items that ship separately with a quantity > 1 are rate estimated as 1 item and then the
|
##Items that ship separately with a quantity > 1 are rate estimated as 1 item and then the
|
||||||
##shipping cost is multiplied by the quantity.
|
##shipping cost is multiplied by the quantity.
|
||||||
if (! $sku->shipsSeparately ) {
|
if (! $sku->shipsSeparately ) {
|
||||||
$itemWeight *= $item->get('quantity');
|
$itemWeight *= $item->get('quantity');
|
||||||
|
$itemCost *= $item->get('quantity');
|
||||||
}
|
}
|
||||||
$weight += $itemWeight;
|
$weight += $itemWeight;
|
||||||
|
$cost += $itemCost;
|
||||||
}
|
}
|
||||||
my $pounds = int($weight);
|
my $pounds = int($weight);
|
||||||
my $ounces = int(16 * ($weight - $pounds));
|
my $ounces = int(16 * ($weight - $pounds));
|
||||||
|
|
@ -89,6 +93,9 @@ sub buildXML {
|
||||||
}
|
}
|
||||||
$packageData{Size} = [ 'REGULAR' ];
|
$packageData{Size} = [ 'REGULAR' ];
|
||||||
$packageData{Machinable} = [ 'true' ];
|
$packageData{Machinable} = [ 'true' ];
|
||||||
|
if ($self->get('addInsurance')) {
|
||||||
|
$packageData{ValueOfContents} = $cost;
|
||||||
|
}
|
||||||
push @{ $xmlTop->{Package} }, \%packageData;
|
push @{ $xmlTop->{Package} }, \%packageData;
|
||||||
}
|
}
|
||||||
my $xml = XMLout(\%xmlHash,
|
my $xml = XMLout(\%xmlHash,
|
||||||
|
|
|
||||||
|
|
@ -755,6 +755,66 @@ SKIP: {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$properties = $driver->get();
|
||||||
|
$properties->{addInsurance} = 1;
|
||||||
|
$driver->update($properties);
|
||||||
|
|
||||||
|
$xml = $driver->buildXML($cart, @shippableUnits);
|
||||||
|
my $xmlData = XMLin($xml,
|
||||||
|
KeepRoot => 1,
|
||||||
|
ForceArray => ['Package'],
|
||||||
|
);
|
||||||
|
cmp_deeply(
|
||||||
|
$xmlData,
|
||||||
|
{
|
||||||
|
RateV3Request => {
|
||||||
|
USERID => $userId,
|
||||||
|
Package => [
|
||||||
|
{
|
||||||
|
ID => 0,
|
||||||
|
ZipDestination => '53715', ZipOrigination => '97123',
|
||||||
|
Pounds => '1', Ounces => '8',
|
||||||
|
Size => 'REGULAR', Service => 'PRIORITY',
|
||||||
|
Machinable => 'true', ValueOfContents => 7.50,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'buildXML: contains ValueOfContents when insurance is requested'
|
||||||
|
);
|
||||||
|
like($xml, qr/RateV3Request USERID.+?Package ID=.+?Service.+?ZipOrigination.+?ZipDestination.+?Pounds.+?Ounces.+?Size.+?Machinable/, '... and tag order');
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
|
||||||
|
skip 'No userId for testing', 2 unless $hasRealUserId;
|
||||||
|
|
||||||
|
my $response = $driver->_doXmlRequest($xml);
|
||||||
|
ok($response->is_success, '... _doXmlRequest to USPS successful');
|
||||||
|
my $xmlData = XMLin($response->content, ForceArray => [qw/Package/],);
|
||||||
|
diag $response->content;
|
||||||
|
# cmp_deeply(
|
||||||
|
# $xmlData,
|
||||||
|
# {
|
||||||
|
# Package => [
|
||||||
|
# {
|
||||||
|
# ID => 0,
|
||||||
|
# ZipOrigination => ignore(), ZipDestination => ignore(),
|
||||||
|
# Ounces => ignore(), Pounds => ignore(),
|
||||||
|
# Size => ignore(), Zone => ignore(),
|
||||||
|
# Postage => {
|
||||||
|
# CLASSID => ignore(),
|
||||||
|
# MailService => ignore(),
|
||||||
|
# Rate => num(8,8), ##A number around 10...
|
||||||
|
# }
|
||||||
|
# },
|
||||||
|
# ],
|
||||||
|
# },
|
||||||
|
# '... returned data from USPS in correct format. If this test fails, the driver may need to be updated'
|
||||||
|
# );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Cleanup
|
# Cleanup
|
||||||
END {
|
END {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue