Jump to content
Latest News: (loading..)
fulluvscents

USPS Rate V4, Intl Rate V2 (official support thread)

Recommended Posts

Didnt work for me either I did the same except I didnt REMOVE that whole second code chunk (preg replace), just replaced that one line.

no quotes, no error message on the site either..

and this is the response report:

Request:

API=RateV4&XML=<RateV4Request USERID="220WWWEB5787"><Revision>2</Revision><Package ID="0"><Service>PRIORITY COMMERCIAL</Service><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable></Package><Package ID="1"><Service>EXPRESS COMMERCIAL</Service><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable></Package></RateV4Request>

 

Response:

 

I fooled with some different settings.. (turning off the Int'l rules option for instance) with no change


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

The comment is correct that XML response is being returned in CHUNKED format. Here is a workaround that I've put in. Hopefully it helps you:

 

I run USPS Methods 7.1 and am having no issues after making the following changes:

 

First you will need to define a function for HTTP_CHUNKED_DECODE somewhere within the code:

 

/**
* dechunk an http 'transfer-encoding: chunked' message
*
* @[member='param'] string $chunk the encoded message
* @[member='Return'] string the decoded message. If $chunk wasn't encoded properly it will be returned unmodified.
*/
function http_chunked_decode($chunk) {
$pos = 0;
$len = strlen($chunk);
$dechunk = null;

while(($pos < $len)
&& ($chunkLenHex = substr($chunk,$pos, ($newlineAt = strpos($chunk,"\n",$pos+1))-$pos)))
{
if (!$this->is_hex($chunkLenHex)) {
trigger_error('Value is not properly chunk encoded', E_USER_WARNING);
return $chunk;
}

$pos = $newlineAt + 1;
$chunkLen = hexdec(rtrim($chunkLenHex,"\r\n"));
$dechunk .= substr($chunk, $pos, $chunkLen);
$pos = strpos($chunk, "\n", $pos + $chunkLen) + 1;
}
return $dechunk;
}

/**
* determine if a string can represent a number in hexadecimal
*
* @[member='param'] string $hex
* @[member='Return'] boolean true if the string is a hex, otherwise false
*/
function is_hex($hex) {
// regex is for weenies
$hex = strtolower(trim(ltrim($hex,"0")));
if (empty($hex)) { $hex = 0; };
$dec = hexdec($hex);
return ($hex == dechex($dec));
}

 

Find the occurrences of

if ($http->Get('/shippingAPI.dll?' . $request)) $body = $http->getBody();

and change to

if ($http->Get('/shippingAPI.dll?' . $request)) {
 $body = preg_replace( array(
 '{<sup>®</sup>}', /* Registered Trademark symbol - July 2013 update */
 '{<sup>™</sup>}', /* Trademark symbol - July 2013 update */
 '/<br>/'
 ), array (
 '',
 '',
 ''
 ), htmlspecialchars_decode($this->http_chunked_decode($http->getBody())));
}

 

All of my quotes come up for both domestic and international without issue.

 

If someone can update this post with the correct locations within the module that would be great.

 

This make sense and we konw who's the XML expert here and I knew someone would know a thing or two about these hex codes...will try this fix as soon as done fighting other fires!!! Thx!

Share this post


Link to post
Share on other sites

I've posted an update on the USPS Methods Rates V4 Intl Rates V2 addon. This contains the code posted by @@badlhby on the USPS Methods support thread. I simply modified the module to work with that code.

 

I have tested both the stock and MVS modules and they seem to work. Please let me know if you find a case where this does not work.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

woooohooo that worked.. I see just a few itty bitty differences from what I was trying.. specifically..

if ($http->Get('/shippingapi.dll?' . $request)) {

$response = http_chunked_decode( $http->getBody() );

the chuncked part of that I was totally missing..

 

thanks all!!!!


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

Jim...you are the man! Thank you again, I am back and running with all my domestic and international services!

 

I've posted an update on the USPS Methods Rates V4 Intl Rates V2 addon. This contains the code posted by @@badlhby on the USPS Methods support thread. I simply modified the module to work with that code.

 

I have tested both the stock and MVS modules and they seem to work. Please let me know if you find a case where this does not work.

 

Regards

Jim

Share this post


Link to post
Share on other sites

Not my code this time, I just cleaned it up a bit and put it up. I'm just glad somebody figured out what that encoding was. I thought it looked familiar and it was driving me crazy.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

@@badlhby aww.. so sorry didnt mean to forget you! thank you for finding that and helping make it work!


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

hate to be the bearer.. but.. SOMETIMES I am getting a warning about cant chunk.. more on the international the domestic.. and now that I want to copy the error message it won;t come up.. grrrrr


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

Do you get the correct quotes when that happens? It's possible that USPS is sending some quotes that are not chunked. I think that happened sometimes on some of my tests, but I also can't prove anything.

 

If you are getting quotes, just comment out the error message and forget about it.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Jim, I'm embarrassed to say I dont know.. I was so freaked out by it.. my thought process was cached so I just hit refresh I saw it twice in moving from US to AU shipping several times

 

I'll check again and be sure to stop and examine next time


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

here ya go.. I just went back in and clicked checkout again (had left it on the catalog main page)

Warning: Value is not properly chunk encoded in /home/[user]/public_html/catalog/includes/modules/shipping/usps.php on line 651

that was using an AU address for shipping..yes I got a quote and yes it looks proper:

United States Postal Service

 

 

>>Click here to view shipping regulations for your country<<

 

First-Class Mail® International Large Envelope $15.40

Priority Mail International® $45.95

Priority Mail Express International™ $62.35

 

 

leaving that as is I changed to a US shipping address and now got the same warning, also did get very correct rate quotes.. it allows me to proceed and get to the payment screen and all looks fine there.. no warnings.. shipping is being added at this point properly

Edited by wkdwich

Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

After updating to the latest add on via Jim -> USPS Rate V4 Intl Rate V2_r3

 

domestic US shipping is working fine

 

international shipping gives something like this:

Warning: Value is not properly chunk encoded in /home/myusername/public_html/includes/modules/shipping/usps.php on line 649

 

Warning: Illegal string offset 'ServiceName' in /home/myusername/public_html/includes/modules/shipping/usps.php on line 111

 

With the second warning repeating numerous times.


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

@@altoid Same question: Are you getting quotes when you get the error message? If you are, comment out the error message.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

@@altoid Same question: Are you getting quotes when you get the error message? If you are, comment out the error message.

 

Regards

Jim

 

Where do you comment out the error message? Thanks


Production:
osCommerce V. 2.3.4BS
VPS Box

Share this post


Link to post
Share on other sites

I'm having the same issue as @@altoid but luckily I am only seeing the one warning (Warning: Value is not properly chunk encoded in /.../includes/modules/shipping/usps.php on line 649) for both domestic and international. It seems the quotes are coming back just fine now. MANY THANKS!!! to @@kymation and @@badlhby.

 

However, I still can not figure out how to get rid of the warning: (Warning: Value is not properly chunk encoded in /.../includes/modules/shipping/usps.php on line 649) :x . I would have assumed the inclusion of the new function would have resolved this warning.

 

Surely I am missing something???????


Anthony David

AllThingsTrendy.com

Share this post


Link to post
Share on other sites

Last night USPS released an update to revert back to the original response format (no chunk encoding) temporarily to fix the issue for users until a more permanent solution can be reached. Does going back to the no-chunk format break anyone who has implemented this patch?

Share this post


Link to post
Share on other sites

Not certain if everyone has realized it or not - USPS has "fixed" their garbage transmission.

 

I was working on updating and installing when a customer called about his order.... I looked at his order and discovered that he had gotten a CORRECT response... further investigation showed it is now working without any changes on my part.

Share this post


Link to post
Share on other sites

Not certain if everyone has realized it or not - USPS has "fixed" their garbage transmission.

 

I was working on updating and installing when a customer called about his order.... I looked at his order and discovered that he had gotten a CORRECT response... further investigation showed it is now working without any changes on my part.

Which USPS module are you using USPS Methods or USPS Rate V4, Intl Rate V2. These are not the same modules. The thread you are posting in is USPS Rate V4, Intl Rate V2.

Edited by spiritalan

Production:
osCommerce V. 2.3.4BS
VPS Box

Share this post


Link to post
Share on other sites

You can comment out this line to get rid of the error message:

 

    trigger_error('Value is not properly chunk encoded', E_USER_WARNING);

 

I would like to warn everyone that you should have error reporting turned off in any live store. No customer should ever see a PHP or MySQL error message.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Where do you comment out the error message? Thanks

 

I commented the following line out as follows:

BEFORE-

trigger_error('Value is not properly chunk encoded', E_USER_WARNING);

 

AFTER-

//trigger_error('Value is not properly chunk encoded', E_USER_WARNING);

 

My file is located at /home/includes/modules/shipping/usps.php, and was the only file I modified from the latest upload from Kymation (USPS Methods Rates V4 Intl Rates V2 11/2013 Update).

 

I don't believe that USPS backed out of their HUGE mistake as was stated by someone today. Since my fix was really simple.. once it was identified. I backed out of the fix from all of you, and I was not able to obtain any pricing from USPS (OSC v2.3.3). So I am sticking with this fix posted by Kymation on the official site... and mod it with the error line commented out.

 

Thanks everyone!!!!

Edited by videod

Share this post


Link to post
Share on other sites

Last night USPS released an update to revert back to the original response format (no chunk encoding) temporarily to fix the issue for users until a more permanent solution can be reached. Does going back to the no-chunk format break anyone who has implemented this patch?

Hi Ben - what proof do you have they've done this? If I restore the original code the module breaks, so not sure they've done this.

Simon

Share this post


Link to post
Share on other sites

@@videod In theory I agree and hadn't jumped in the jumping backwards hoop @@kymation thanks for pointing out the line to be commented out.. done.. I have quotes and no errors.. now to head off to fix my clients as I think we have a real solution now - permanent?? probably not.. but its put us all back in business,, thanks everyone!


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

Oh.. thinking.. it might be helpful to have that error message at some point.. can you do a quick have it write to an error log but leave it commented out for the time being???


Debbie D
Franklin County, VA "Moonshine Capitol of the World"
osCmax Mobile Template oscmaxtemplates.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×