Steps to reproduce:
1. Set up USPS as a shipping option
2. Create an order with a shipping address in Puerto Rico or Guam
3. Calculate shipping rates

AJAX request fails with 500 internal server error

shipping results show up

checking out the code, this seems to be hitting an unhandled code path:
ubercart/shipping/uc_usps/uc_usps.module, lines 374 - 381:
if (strpos($method['id'], 'intl') && ($destination->country != 840)) {
// Build XML for international rate request
$request = uc_usps_intl_rate_request($ship_packages, $orig, $destination);
elseif ($destination->country == 840) {
// Build XML for domestic rate request
$request = uc_usps_rate_request($ship_packages, $orig, $destination);

note that 840 = country ID of USA
so in our scenario, the shipping $method['id'] is usps, and the country ID is (E.g.) 630 (Puerto Rico), so neither the first nor second branches match, the $request variable is never assigned and the HTTP request for shipping quotes fails.

#3 1901296-usps-territories.patch786 byteslongwave
PASSED: [[SimpleTest]]: [MySQL] 2,144 pass(es).
[ View ]
#1 1901296-ubercart-usps-shipping-to-us_territories.patch700 bytesbenjaminbradley
FAILED: [[SimpleTest]]: [MySQL] 1,966 pass(es), 60 fail(s), and 194 exception(s).
[ View ]


Status:Active» Needs review
new700 bytes
FAILED: [[SimpleTest]]: [MySQL] 1,966 pass(es), 60 fail(s), and 194 exception(s).
[ View ]

Here is one possible solution - in an additional else branch, if the $method['id'] is not 'intl', we default to using the "domestic" rate request.

Status:Needs review» Needs work

The last submitted patch, 1901296-ubercart-usps-shipping-to-us_territories.patch, failed testing.

Version:6.x-2.11» 6.x-2.x-dev
Status:Needs work» Needs review
new786 bytes
PASSED: [[SimpleTest]]: [MySQL] 2,144 pass(es).
[ View ]

Whether to use US or International quotes is already decided by Rules, so I think we can remove the country test here.

I won't be able to check on this for a while, but I'm pretty sure that for USPS you should be using country = US and selecting Puerto Rico as the *zone*, not the country.

Double post ...

Oh, and the patch in #3 reverts the code to how it used to be two years ago. The check for country was put in there deliberately as part of commit 5aa9d168. I don't remember right now exactly why it was added, but it was certainly done to address a bug/problem.

Edit: I previously referred to the wrong patch #. Fixed now.

Maybe the solution is to remove Puerto Rico and Guam from the Country list on the Shipping Address form, thereby forcing selection of Country = US and Puerto Rico or Guam as the State/Province ?

Yes, that's what I've done in the past.