Jump to content
fulluvscents

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

Recommended Posts

NEW and Improved!

 

Please let me know if you find a way to break this one.

 

Regards

Jim

 

Domestic -> :thumbsup:

 

Canada yields a bunch of warnings but at the very bottom the rates show

 

First-Class Package International Service $8.24 Priority Mail International® $27.40

 

The warnings above are bunch of lines repeating:

 

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

 

Spain yields same as Canada


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

That's disappointing but not too bad. The error is in the Extra services section, so one of those is getting corrupted. That's only bad if it's one that you want to use.

 

To help with this, turn off the Show International Regulations option. The regulations are sent first, and push the quotes down where there seem to be more errors.

 

There's only so much I can do to fix this. USPS really needs to get their act together.

 

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

Light bulb after reading post #901 and reviewing where all that weird code was coming from.

Here's a possible workaround -- disable the Revision=“2” tag and all other tags that involve Revision=“2”.

 

This workaround was tested ONLY on the following USPS add-on (kymation @ Aug 29, 2013): http://addons.oscommerce.com/info/8702

ThIS workaround INCLUDED the code fix provided in this link: http://forums.oscommerce.com/topic/383307-usps-rate-v4-intl-rate-v2-official-support-thread/page__st__880#entry1684822

WARNING: Extra services that rely on the Revision="2" tag may no longer work. Trade-off is functional rates with USPS.

 

Then, perform the following steps (or if you know how to comment out PHP lines, then do so for the first 4 modifications):

 

BACKUP includes/modules/shipping/usps.php

 

#1 FIND:

$request = '<RateV4Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Revision>2</Revision>';

 

#1 REPLACE WITH:

$request = '<RateV4Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '';
//$request = '<RateV4Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Revision>2</Revision>';

 

#2 FIND:

$request = '<IntlRateV2Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
'<Revision>2</Revision>' .

 

#2 REPLACE WITH:

$request = '<IntlRateV2Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
//'<Revision>2</Revision>' .

 

#3 FIND:

'<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' .

 

#3 REPLACE WITH:

// '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' .

 

#4 FIND:

'<ExtraServices>' .
'<ExtraService>0</ExtraService>' .
'<ExtraService>1</ExtraService>' .
'<ExtraService>2</ExtraService>' .
'<ExtraService>3</ExtraService>' .
'<ExtraService>5</ExtraService>' .
'<ExtraService>6</ExtraService>' .
'</ExtraServices>' .

 

#4 REPLACE WITH:

/*
'<ExtraServices>' .
'<ExtraService>0</ExtraService>' .
'<ExtraService>1</ExtraService>' .
'<ExtraService>2</ExtraService>' .
'<ExtraService>3</ExtraService>' .
'<ExtraService>5</ExtraService>' .
'<ExtraService>6</ExtraService>' .
'</ExtraServices>' .
*/

 

OPTIONAL (if you've modified your add-on to support First-Class Mail International Letter):

 

#5 FIND:

'<Width>2</Width>' .

 

#5 CHANGE TO

'<Width>0.2</Width>' .

 

 

If I can get some updates from others that this is working, I'll upload these fixes along with some upgrades I've made to add-on contribution 8702.

 

This worked for me to get back International Rates but I get the following warning. There are several of them. Looks like one for each rate. I just posted 3.

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

Share this post


Link to post
Share on other sites

This worked for me to get back International Rates but I get the following warning. There are several of them. Looks like one for each rate. I just posted 3.

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

 

Warning: Invalid argument supplied for foreach() in/home/XXXXX/public_html/includes/modules/shipping/usps.php on line 110

Curious if you've also disabled the Extra Services from the module's admin section. They should all be checkmarked to N instead of Y for both domestic and international.

 

I also recommend setting Show International Regulations to False.

Share this post


Link to post
Share on other sites

Gotta love the mess USPS makes without thinking it will affect anyone. We have sent multiple emails to USPS as requested to see if they will feel some pressure to get this fixed.

 

@@kymation, could I beg you pretty please to update http://addons.oscommerce.com/info/8702 when all this mess is worked out?


-Rebecca

 

If at first you don't succeed, try, try again.

Share this post


Link to post
Share on other sites

I will update the addon page if we ever find a fix to this problem. Of course that won't be necessary if the USPS fixes their bug.

 

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

I guess I am seeing the same craps from USPS. I narrow down my problem has to do with the xml_5.php isn't able to parse the response from USPS.

 

Yeah, $doc = XML_unserialize($dombody); , $dombody goes in full and $doc returns empty.

 

I had submitted the query string to the usps production server and I got a complaint: "This XML file does not appear to have any style information associated with it. The document tree is shown below." Looking at the source of this I don't see any error. However, if I would dump out $dombody live from the store that are weired characters in front and after...will keep working on it and hope someone find a fix soon...I am sure USPS is the problem in this case...

Share this post


Link to post
Share on other sites

The filter I posted above will help. Insert it before the line you posted to clean up $dombody before the XML parser gets 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

kymation: thx for the info! tried it but no go...the error is probably from the http client class...i got in the source from the output...

 

27

<?xml version="1.0" encoding="UTF-8"?>

 

55d

<RateV4Response><Package ID="0"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>1</Zone><Postage CLASSID="4"><MailService>Standard Post&lt;sup&gt;&#174;&lt;/sup&gt;</MailService><Rate>9.75</Rate></Postage></Package><Package ID="1"><Error><Number>-2147219428</Number><Source>DomesticRatesV4;clsRateV4.ValidateFirstClassMailType;RateEngineV4.ProcessRequest</Source><Description>Invalid First Class Mail Type.</Description><HelpFile/><HelpContext>1000440</HelpContext></Error></Package><Package ID="2"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>1</Zone><Postage CLASSID="1"><MailService>Priority Mail 1-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService><Rate>9.75</Rate></Postage></Package><Package ID="3"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>1</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 1-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService><Rate>26.40</Rate></Postage></Package></RateV4Response>

0

You can't just strip away the 27, 55d, and the end 0 and it would work...there are some hidden special characters...but if i go

 

$dombody = '

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

<RateV4Response><Package ID="0"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>1</Zone><Postage CLASSID="4"><MailService>Standard Post&lt;sup&gt;&#174;&lt;/sup&gt;</MailService><Rate>9.75</Rate></Postage></Package><Package ID="1"><Error><Number>-2147219428</Number><Source>DomesticRatesV4;clsRateV4.ValidateFirstClassMailType;RateEngineV4.ProcessRequest</Source><Description>Invalid First Class Mail Type.</Description><HelpFile/><HelpContext>1000440</HelpContext></Error></Package><Package ID="2"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>1</Zone><Postage CLASSID="1"><MailService>Priority Mail 1-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService><Rate>9.75</Rate></Postage></Package><Package ID="3"><ZipOrigination>90501</ZipOrigination><ZipDestination>90501</ZipDestination><Pounds>6</Pounds><Ounces>0</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>1</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 1-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService><Rate>26.40</Rate></Postage></Package></RateV4Response>

'

Then no problem...USPS is just lovely...thx! Tim

Share this post


Link to post
Share on other sites

@@clustersolutions First, you have an invalid First Class error in there. Turn off that First Class option (temporarily) to fix that.

 

Second, the invisible characters are Windows line endings. My filter takes all of those out. Apparently there are some other characters as well that I haven't been able to characterize. If I could do that, I could filter out everything.

 

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, thanks for your help!

 

First thing first, I am still on OSC 2.2 MS2 from way back...

 

Yes, the First Class error is not an issue for us as our package offers only valid services. We supply weight and dimensions so base on that sometime First Class is a go and sometime not...

 

Yes, I also see your filters, which in the past we had been applying as USPS API had decided to screwed with us. So the issue to us wasn't these "filters."

 

So, I suspect the http client wasn't able to handle the get response and is scrambling characters; hence, the http client get response had the strage characters and not the output from Firefox. Now, we are testing OSC 2.3.3 (and migrating a Magento store to it in the process. Yeah, who would have guessed?!) and perhap the http client is okay and that I don't know until further testing...

 

Lastly, the CURL gives a clean response so for now until further testing this is what we did...

 

// temp fix 11-13-13 clustersolutions.net

 

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

 

$url = 'http://' . $usps_server . '/' . $api_dll . '?' . $request;

$options = array (CURLOPT_RETURNTRANSFER => true, // return web page

CURLOPT_HEADER => false, // don't return headers

CURLOPT_FOLLOWLOCATION => true, // follow redirects

CURLOPT_ENCODING => "", // handle compressed

CURLOPT_USERAGENT => "OsCommerce", // who am i

CURLOPT_AUTOREFERER => true, // set referer on redirect

CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect

CURLOPT_TIMEOUT => 120, // timeout on response

CURLOPT_MAXREDIRS => 5 ); // stop after 10 redirects

 

$ch = curl_init ( $url );

curl_setopt_array ( $ch, $options );

$content = curl_exec ( $ch );

$err = curl_errno ( $ch );

$errmsg = curl_error ( $ch );

$header = curl_getinfo ( $ch );

$httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );

 

curl_close ( $ch );

 

$header ['errno'] = $err;

$header ['errmsg'] = $errmsg;

$header ['content'] = $content;

$body = ($header ['content']);

 

$dombody = $body;

 

Yeah, just comment out the http client get (it's a waste of resources for now) and assign the response to the $body prior to XML parsing...it worked for both the domestic and internation shippings...I gotta checkout how we had obtained the responde from Fedex and UPS...

 

Thanks for all your help...much appreciated!!!

 

Yes, the same people doing these stuffs are working on ocare.gov...

 

Tim

Share this post


Link to post
Share on other sites

I've been trying to avoid using cURL as it's not always available, but we may have to to fix this bug, as there's no sign that USPS has any intention of fixing it. It also bothers me that I can see no reason why cURL works and httpClient does not.

 

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

Extremely frustrated here..

 

running osCmax 2.0.35 with USPS Rate V4 Intl Rate V2 - v.1.7

$Mod: Changed from Parcel Post to Standard Post 20130129 Kymation $

$Mod: USPS API changes 20130729 Kymation v 1.3 $

 

 

I tried every suggestion in the last 3-4 pages here.. some worse than others.. but generally I get this warning at the top of the page:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in/home/USER/public_html/catalog/includes/modules/shipping/usps.php on line 391

 

Warning: simplexml_load_string() [function.simplexml-load-string]: 27 in /home/USER/public_html/catalog/includes/modules/shipping/usps.php on line 391

 

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/USER/public_html/catalog/includes/modules/shipping/usps.php on line 391

 

I have searched the response emails for invalid pr error and there is nothing.. on the contrary it seriously looks like a very valid response..

][/b]Request:

API=RateV4&XML=<RateV4Request USERID="220WWWEB5787"><Revision>2</Revision><Package ID="0"><Service>PARCEL</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>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="2"><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:

27

<?xml version="1.0",encoding="UTF-8"?>

 

f89

<RateV4Response><Package ID="0"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>4</Zone><Postage CLASSID="4"><MailService>Standard PostRM</MailService><Rate>5.85</Rate><SpecialServices><SpecialService><ServiceID>9</ServiceID><ServiceName>Certificate of Mailing</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.20</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>1</ServiceID><ServiceName>Insurance</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.95</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>13</ServiceID><ServiceName>USPS TrackingTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>0.00</Price><PriceOnline>0.00</PriceOnline></SpecialService><SpecialService><ServiceID>7</ServiceID><ServiceName>Return Receipt for Merchandise</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>4.10</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>15</ServiceID><ServiceName>Signature ConfirmationTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>2.70</Price><PriceOnline>2.20</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package><Package ID="1"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>4</Zone><Postage CLASSID="1"><MailService>Priority Mail 2-DayTM</MailService><Rate>5.85</Rate><CommercialRate>5.35</CommercialRate><SpecialServices><SpecialService><ServiceID>9</ServiceID><ServiceName>Certificate of Mailing</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.20</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>1</ServiceID><ServiceName>Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>1.95</Price><PriceOnline>1.95</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>5</ServiceID><ServiceName>Registered MailTM</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>11.20</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceIDc30

.00</Price><PriceOnline>0.00</PriceOnline></SpecialService><SpecialService><ServiceID>7</ServiceID><ServiceName>Return Receipt for Merchandise</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>4.10</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>15</ServiceID><ServiceName>Signature ConfirmationTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>2.70</Price><PriceOnline>2.20</PriceOnline></SpecialService><SpecialService><ServiceID>19</ServiceID><ServiceName>Adult Signature Required</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>4.95</PriceOnline></SpecialService><SpecialService><ServiceID>20</ServiceID><ServiceName>Adult Signature Restricted Delivery</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>5.15</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package><Package ID="2"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>4</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 2-DayTM</MailService><Rate>28.30</Rate><CommercialRate>20.42</CommercialRate><SpecialServices><SpecialService><ServiceID>11</ServiceID><ServiceName>Priority Mail Express Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>0.90</Price><PriceOnline>0.90</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>8</ServiceID><ServiceName>Return Receipt</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>2.55</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>19</ServiceID><ServiceName>Adult Signature Required</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>4.95</PriceOnline></SpecialService><SpecialService><ServiceID>20</ServiceID><ServiceName>Adult Signature Restricted Delivery</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>5.15</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package></RateV4Response>

0

 

adding the code from

batchtech post #907 made a huge error message mess...

otherwise the changes involved anything Jim suggested (#882 then #923) I have display Int'l regulations set to false..

 

where to now my friends???


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

Very much not a correct response. This is in fact a very typical invalid response. The characters in red are invalid and break the XML:

 

27

<?xml version="1.0",encoding="UTF-8"?>

 

f89

<RateV4Response><Package ID="0"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>4</Zone><Postage CLASSID="4"><MailService>Standard PostRM</MailService><Rate>5.85</Rate><SpecialServices><SpecialService><ServiceID>9</ServiceID><ServiceName>Certificate of Mailing</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.20</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>1</ServiceID><ServiceName>Insurance</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.95</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>13</ServiceID><ServiceName>USPS TrackingTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>0.00</Price><PriceOnline>0.00</PriceOnline></SpecialService><SpecialService><ServiceID>7</ServiceID><ServiceName>Return Receipt for Merchandise</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>4.10</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>15</ServiceID><ServiceName>Signature ConfirmationTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>2.70</Price><PriceOnline>2.20</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package><Package ID="1"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>4</Zone><Postage CLASSID="1"><MailService>Priority Mail 2-DayTM</MailService><Rate>5.85</Rate><CommercialRate>5.35</CommercialRate><SpecialServices><SpecialService><ServiceID>9</ServiceID><ServiceName>Certificate of Mailing</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>1.20</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>1</ServiceID><ServiceName>Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>1.95</Price><PriceOnline>1.95</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>5</ServiceID><ServiceName>Registered MailTM</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>11.20</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceIDc30

.00</Price><PriceOnline>0.00</PriceOnline></SpecialService><SpecialService><ServiceID>7</ServiceID><ServiceName>Return Receipt for Merchandise</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>4.10</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>15</ServiceID><ServiceName>Signature ConfirmationTM</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>2.70</Price><PriceOnline>2.20</PriceOnline></SpecialService><SpecialService><ServiceID>19</ServiceID><ServiceName>Adult Signature Required</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>4.95</PriceOnline></SpecialService><SpecialService><ServiceID>20</ServiceID><ServiceName>Adult Signature Restricted Delivery</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>5.15</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package><Package ID="2"><ZipOrigination>11779</ZipOrigination><ZipDestination>24151</ZipDestination><Pounds>0</Pounds><Ounces>16</Ounces><Container>VARIABLE</Container><Size>REGULAR</Size><Zone>4</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 2-DayTM</MailService><Rate>28.30</Rate><CommercialRate>20.42</CommercialRate><SpecialServices><SpecialService><ServiceID>11</ServiceID><ServiceName>Priority Mail Express Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>0.90</Price><PriceOnline>0.90</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>false</DueSenderRequired></SpecialService><SpecialService><ServiceID>8</ServiceID><ServiceName>Return Receipt</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>2.55</Price><PriceOnline>0</PriceOnline></SpecialService><SpecialService><ServiceID>19</ServiceID><ServiceName>Adult Signature Required</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>4.95</PriceOnline></SpecialService><SpecialService><ServiceID>20</ServiceID><ServiceName>Adult Signature Restricted Delivery</ServiceName><Available>false</Available><AvailableOnline>true</AvailableOnline><Price>0</Price><PriceOnline>5.15</PriceOnline></SpecialService><SpecialService><ServiceID>6</ServiceID><ServiceName>Collect on Delivery</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>6.45</Price><PriceOnline>0</PriceOnline><DeclaredValueRequired>true</DeclaredValueRequired><DueSenderRequired>true</DueSenderRequired></SpecialService></SpecialServices></Postage></Package></RateV4Response>

0

 

There may be more; I only did a quick scan for the most common errors. The filter code in this post will remove most of it. The cURL code that @@clustersolutions posted above is also supposed to work. If those are not working for you, you've done something wrong in your edits. Check carefully and try again.

 

Regards

Jim

Edited by kymation

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

Share this post


Link to post
Share on other sites

wkdwich, your response had the same junks in it as our was...don't know what OSCMax was but it had probably the same http class client...if you can go to CURL incorporate the codes and all should be swell...good luck...

 

most apache should have curl compiled in and if your don't you can always ask your hosting company to get it for you...I like tools...tools are good...but still need to find the issue with the http client when there is time...then again...that's before USPS decided to go break something else...this XML upgrade was unannounced I believer...love the way they just go make changes to data languages...wed thur fri...

Share this post


Link to post
Share on other sites

It looks like the issue is a change in the response transfer-encoding to 'chunked' .. the numbers / hexdecimals you're trying to filter out are the chunked line counts, with 0 at the end to indicate the end of the 'chunk.' However using curl or even the pecl http_chunked_decode function, it still doesn't parse correctly even though it looks as though it does.

 

Simon

Share this post


Link to post
Share on other sites

oscMax is a version of OSC with lots of MODs already built in.. no huge mystery there :)

 

thanks gentlemen for the replies.. I should have realized there was something wrong because my email program just chops the responses off at those pints.. it wont even read them!

 

so this AM I went back to what was working last week, added back in both the new and improved "strip out the junk" post #923 and the curl post #936 and I have no errors, but no quotes either..

 

this was all I got back this last try:

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've asked Tim to send me his copy so I can do a compare.. I've got one reallllllyy panicked client I need to get this right for!


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, still messing with this.. was looking back for someone posted their zone rates they use for an interim fix and found your post #785 with a link for clean code for the module file.. I did a compare and I am spot on except for the post #923 strip and post #976 curl codes.. so I guess I maybe just need your copy or Tim's copy to fool with here..

 

meanwhile... does anyone know what post # that lady posted her zone file info??? or am I losing it did she post it??


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.

Share this post


Link to post
Share on other sites

I tried this in 2 places and no luck so far.. the first place I placed the chunk was a horror wrong oopps..

added the "chunk" right above

function quote($method = '') {

global $order, $shipping_num_boxes, $currencies, $shipping, $shipping_weight;

 

I did the decode thing too.. I didnt get any errors, but I didnt get a quote either

 

the entire response I got back from USPS was:

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:


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, my thanks to you and everyone else who's been trying to fix this cluster by the USPS.

 

I'm not a coder, just a low-line web designer with pretensions of adequacy (and XML is anathema) -- but even I was able to make your last patch work. We're running 2.3.1, and after trying too many things I got confused and went back for a clean install of the Aug. 28 package. It was a very bad four days getting to that point, but from there on it was clear sailing for us.

 

In Admin I disabled Int'l Regulations and all extra services, both Int'l and Domestic -- luckily we don't need them -- and all works transparently well as it should.

 

I saw a comment above about extra services and Int'l regs being pushed early in the response process, and it makes sense to me if that's where the garbage characters are coming from. If you don't absolutely need the extra services, disabling them may help the problem. (Apologies if this sounds simple-minded.) Again, thanks to all for working together.


webmaster@mysongs.com

Ignorance is curable ... but there's no vaccine against stupid.

Share this post


Link to post
Share on other sites

badlhby is almost right-on. for those that use other odd versions of USPS and USPS methods here's the fix that worked for my sites...

 

Add this to your includes>functions>general.php

or to the bottom of your usps.php module after the last ending bracket }

 

/**
* 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 (!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));
}

 

then find this small code chunck:

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

change to

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

 

should do it. works for me in several versions of this module.

Share this post


Link to post
Share on other sites

badlhby is almost right-on. for those that use other odd versions of USPS and USPS methods here's the fix that worked for my sites...

 

Add this to your includes>functions>general.php

or to the bottom of your usps.php module after the last ending bracket }

 

/**
* 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 (!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));
}

 

then find this small code chunck:

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

change to

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

 

should do it. works for me in several versions of this module.

 

This did not work for me. Maybe I did something wrong. Here is what I did:

 

I added the function to the end of usps.php module, before the closing ?> and after the last }

 

I then removed the following code:

if ($http->Get('/shippingapi.dll?' . $request)) {
$body = preg_replace( array(
	 '/\v*[0-9a-f]+\v+/', // November XML problem - CHRISYTSMA kymation
	 '/\<sup\>\&reg;\<\/sup\>/',
	 '/\<sup\>\&trade;\<\/sup\>/',
	 '{<sup>®</sup>}', // Registered Trademark symbol - July 2013 update
	 '{<sup>™</sup>}', // Trademark symbol - July 2013 update
	 //'/\" /', These 3 lines commented out for November XML Problem - CHRISYTSMA
	 //'/\",/',
	 //'/\"<br>/',
	 '/<br>/'
	 ), array (
	 '', // November XML problem - CHRISYTSMA kymation
	 'RM',
	 'TM',
	 'RM',
	 'TM',
	 //'" ', These 3 lines commented out for November XML Problem - CHRISYTSMA
	 //'",',
	 //'"<br>',
	 'BREAK'
	 ), htmlspecialchars_decode($http->getBody()));

 

And replaced it with:

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

 

Did I do something wrong?

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

×