Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

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


Guest

Recommended Posts

That is getting you a valid response. Well, valid except for the invalid characters that USPS is throwing in. Now go into the line of code just above the one you uncommented and change $body to $response. That will return an email with the filtered results. Comparing that to the response above will show if the filter is working and what it's doing.

 

Regards

Jim

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

Link to comment
Share on other sites

Response from USPS:

There was a migration to a new environment over the weekend. We have found the XML processor in the new environment to be more strict in its validation of XML, though all validations still align with the published technical specs. There are a few instances where improperly formatted XML would have been processed successfully before the migration but would fail now. However, your request below seems to process just fine.

 

NOTE: My request works fine. It is the response that isn't.

Link to comment
Share on other sites

I hope you replied to their email with that line. They don't seem to understand that their response is broken.

 

xml_unserialize() is the fastest way to do this. We could use an external library, as some of the older modules do, but this is faster. No matter what you use, invalid XML will always break it.

 

Regards

Jim

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

Link to comment
Share on other sites

Here is my 2 cents on what I've been able to get to work and how.

 

For what it is worth - using 6.3 from http://addons.oscommerce.com/info/487

 

I used code that was recommended earlier in this forum but only really seemed to need the first part (thus all the commenting).

   $body = preg_replace( array(
			  '/\v*[0-9a-f]+\v+/',
//				  '{<sup>®</sup>}',  /* Registered Trademark symbol - July 2013 update */
//				  '{<sup>™</sup>}',  /* Trademark symbol - July 2013 update */
//				  '/\",/',
//				  '/\"<br>/',
//				  '/<br>/'
		    ), array (
			  '',
//				  'RM',
//				  'TM',
//				  '",',
//				  '"<br>',
//				  'BREAK'
		    ), htmlspecialchars_decode($body));

 

NOTE: This alone did not fix it.

 

I also needed to change:

Automatically charge Delivery Confirmation when available? Note: Signature Confirmation will override this if it is selected.

 

from False to True. (which makes the displayed rates more than I want to pay).

(Discovered by staring at the USPS response)

 

-- Hope that helps someone else out.

 

I still am having issues figuring out how to get any international rates to display (specifically Canada)

Link to comment
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://www.oscommerce.com/forums/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.

Link to comment
Share on other sites

For anyone having the simplexml errors, please try this solution, it worked for me).

 

FIRST BACKUP YOUR includes/modules/shipping/usps.php file.

 

Before this line:

 

return json_decode(json_encode(simplexml_load_string($body)),TRUE);

 

Add the following code:

 

 

//BOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

preg_match('/\<.*\>.?\<.*\>/', $body, $matches);

 

$body = '<?xml version="1.0" encoding="UTF-8"?>';

$body .= implode($matches);

$body .= '</Package></RateV4Response>';

//EOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

 

 

Most likely this is not the best solution but it cleans up the extra garbage that USPS supplies in the quotes and allows you to get your rates if you were having the same simplexml errors that many of our clients are having.

 

-David

Link to comment
Share on other sites

Update to the code above. I don't believe I'll be able to get international working. USPS has to fix all the garbage in their response. This is just a hack to fix domestic which should work even after USPS takes the garbage out.

 

FIRST BACKUP YOUR includes/modules/shipping/usps.php file.

 

Before this line:

 

return json_decode(json_encode(simplexml_load_string($body)),TRUE);

 

Add the following code:

 

 

//BOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

preg_match('/\<.*\>.?\<.*\>/', $body, $matches);

 

$body = implode($matches);

if (strpos($body, '<?xml version="1.0" encoding="UTF-8"?>') === false)

$body = '<?xml version="1.0" encoding="UTF-8"?>' . $body;

if (strpos($body, '</Package>') === false)

$body .= '</Package>';

if (strpos($body, '</RateV4Response>') === false)

$body .= '</RateV4Response>';

//EOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

 

Hopefully this will at least fix domestic for you until USPS gets the situation resolved.

 

-David

Link to comment
Share on other sites

Does this make sense to anyone?

 

 

This looks like they are having an issue with how the data is being passed back. The user is not handling the chunked response from us.

 

Below are the headers from connecting to the external VIP.

 

0030 00 2e 7f 4b 00 00 48 54 54 50 2f 31 2e 31 20 32 ...K..HT TP/1.1 2

0040 30 30 20 4f 4b 0d 0a 58 2d 42 61 63 6b 73 69 64 00 OK..X -Backsid

0050 65 2d 54 72 61 6e 73 70 6f 72 74 3a 20 4f 4b 20 e-Transp ort: OK

0060 4f 4b 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 OK..Conn ection:

0070 4b 65 65 70 2d 41 6c 69 76 65 0d 0a 54 72 61 6e Keep-Ali ve..Tran

0080 73 66 65 72 2d 45 6e 63 6f 64 69 6e 67 3a 20 63 sfer-Enc oding: c

0090 68 75 6e 6b 65 64 0d 0a 44 61 74 65 3a 20 54 75 hunked.. Date: Tu

00a0 65 2c 20 31 32 20 4e 6f 76 20 32 30 31 33 20 31 e, 12 No v 2013 1

00b0 33 3a 34 30 3a 33 38 20 47 4d 54 0d 0a 53 65 72 3:40:38 GMT..Ser

00c0 76 65 72 3a 20 4d 69 63 72 6f 73 6f 66 74 2d 49 ver: Mic rosoft-I

00d0 49 53 2f 36 2e 30 0d 0a 58 2d 50 6f 77 65 72 65 IS/6.0.. X-Powere

00e0 64 2d 42 79 3a 20 41 53 50 2e 4e 45 54 0d 0a 58 d-By: AS P.NET..X

00f0 2d 43 6c 69 65 6e 74 2d 49 50 3a 20 35 36 2e 30 -Client- IP: 56.0

0100 2e 33 33 2e 39 0d 0a 43 6f 6e 74 65 6e 74 2d 54 .33.9..C ontent-T

0110 79 70 65 3a 20 74 65 78 74 2f 78 6d 6c 0d 0a 0d ype: tex t/xml..

 

Below is the response directly from the eagnmntwe1616 application server. It is not chunk encoding the response.

 

0030 00 2e a6 1a 00 00 48 54 54 50 2f 31 2e 31 20 32 ......HT TP/1.1 2

0040 30 30 20 4f 4b 0d 0a 43 6f 6e 6e 65 63 74 69 6f 00 OK..C onnectio

0050 6e 3a 20 63 6c 6f 73 65 0d 0a 44 61 74 65 3a 20 n: close ..Date:

0060 54 75 65 2c 20 31 32 20 4e 6f 76 20 32 30 31 33 Tue, 12 Nov 2013

0070 20 31 33 3a 35 37 3a 32 33 20 47 4d 54 0d 0a 53 13:57:2 3 GMT..S

0080 65 72 76 65 72 3a 20 4d 69 63 72 6f 73 6f 66 74 erver: M icrosoft

0090 2d 49 49 53 2f 36 2e 30 0d 0a 58 2d 50 6f 77 65 -IIS/6.0 ..X-Powe

00a0 72 65 64 2d 42 79 3a 20 41 53 50 2e 4e 45 54 0d red-By: ASP.NET.

 

From the customer’s response, it looks like they are only reading part of the message being sent back.

 

 

27 f9e 372114809106.16REGULAR4First-Class<sup>™</sup> Package Service0.002.391Insurancefalsetrue01.95truefalse13USPS Tracking<sup>™</sup>truetrue0.900.0015Signature Confirmation<sup>™</sup>truetrue2.702.20372114809106.16VARIABLEREGULAR4Priority Mail 2-Day<sup>™</sup>5.855.359Certificate of Mailingtruefalse1.2001Insurancetruetrue1.951.95truefalse5Registered Mail<sup>™</sup>truefalse11.200truefalse4Registered without Insurancetruefalse11.2000Certified Mail<sup>®</sup>truefalse3.10013USPS Tracking<sup>™</sup>truetrue0.000.007Return Receipt for Merchandisetruefalse4.10015Signature Confirmation<sup>™</sup>truetrue2.702.2019Adult Signature Requiredfalsetrue04.95 a2d 20Adult Signature Restricted Deliveryfalsetrue05.156Collect on Deliverytruefalse6.450truetrue372114809106.16VARIABLEREGULARTRUE4Standard Post<sup>®</sup>5.859Certificate of Mailingtruefalse1.2001Insurancetruefalse1.950truefalse13USPS Tracking<sup>™</sup>truetrue0.000.007Return Receipt for Merchandisetruefalse4.10015Signature Confirmation<sup>™</sup>truetrue2.702.206Collect on Deliverytruefalse6.450truetrue 0

Edited by betterwebsite
Link to comment
Share on other sites

Ok, yet another update that should work a bit more universally. As we are applying the temporary fix to many of our client's shops that all have different USPS modules, the code needed to be a bit more variable for closing the tags up at the end after weeding out the garbage in the USPS response XML.

 

 

FIRST BACKUP YOUR includes/modules/shipping/usps.php file.

 

Before this line:

 

return json_decode(json_encode(simplexml_load_string($body)),TRUE);

 

Add the following code:

 

 

//BOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

preg_match('/\<.*\>.?\<.*\>/', $body, $matches);

 

$body = implode($matches);

if (strpos($body, '<?xml version="1.0" encoding="UTF-8"?>') === false)

$body = '<?xml version="1.0" encoding="UTF-8"?>' . $body;

 

$tagsArray = array('MailService', 'Postage', 'Package', 'RateV4Response');

 

for ($i=0; $i<sizeof($tagsArray); $i++) {

if (strrpos($body, '<' . $tagsArray[$i]) > strrpos($body, '</' . $tagsArray[$i] . '>')) {

$body .= '</' . $tagsArray[$i] . '>';

}

}

//EOF Code fix for USPS problems starting on 11/9/2013 by batchtech.com

 

Hopefully this will at least fix domestic for you until USPS gets the situation resolved.

 

-David

Link to comment
Share on other sites

@@kymation - I noticed that my response started with the following.

 

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

 

So by simply commenting out the following lines, the preg_replace function stopped replacing these occurrences. My rates appeared immediately.

 

$body = preg_replace( array(
	 '/\v*[0-9a-f]+\v+/', // November XML problem - 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 (
	 '',
	 'RM',
	 'TM',
	 'RM',
	 'TM',
	 //'" ', These 3 lines commented out for November XML Problem - CHRISYTSMA
	 //'",',
	 //'"<br>',
	 'BREAK'
	 ), htmlspecialchars_decode($http->getBody()));

 

Chris

Link to comment
Share on other sites

That will probably work -- some of the time. It may also cause some quotes that would otherwise work to stop working. I tried that on my test store and it broke every quote I tried.

 

It all depends on where the invalid characters end up, which partly depends on what quotes you are getting. Changing the weight can be enough to trigger errors. Changing the allowed services/special services can also do it. It's just too random to fix easily.

 

It could still be possible to fix in the general case, so keep trying if you want to. I'll do the same if I get any inspiration.

 

Regards

Jim

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

Link to comment
Share on other sites

@@kymation - I noticed that my response started with the following.

 

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

 

So by simply commenting out the following lines, the preg_replace function stopped replacing these occurrences. My rates appeared immediately.

 

$body = preg_replace( array(
	 '/\v*[0-9a-f]+\v+/', // November XML problem - 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 (
	 '',
	 'RM',
	 'TM',
	 'RM',
	 'TM',
	 //'" ', These 3 lines commented out for November XML Problem - CHRISYTSMA
	 //'",',
	 //'"<br>',
	 'BREAK'
	 ), htmlspecialchars_decode($http->getBody()));

 

Chris

 

well, it didnt break anything. but, still with certain weight combinations i am having no rates offered. but with some i am.

Link to comment
Share on other sites

That will probably work -- some of the time. It may also cause some quotes that would otherwise work to stop working. I tried that on my test store and it broke every quote I tried.

 

It all depends on where the invalid characters end up, which partly depends on what quotes you are getting. Changing the weight can be enough to trigger errors. Changing the allowed services/special services can also do it. It's just too random to fix easily.

 

It could still be possible to fix in the general case, so keep trying if you want to. I'll do the same if I get any inspiration.

 

Regards

Jim

 

yeah, that is what does it for me. i can be good with x qty of a product, add one more and i only get my local pickup option (thats always there). :(

Link to comment
Share on other sites

It does break when I try a quote to Russia over 10 pounds. But it works for other countries I've tested no matter the weight.

 

The most important thing is that US Domestic shipping calculates and it seems to be working good.

 

do you mind sharing what your weight thresholds are for products then? maybe mine are too strict?

Link to comment
Share on other sites

do you mind sharing what your weight thresholds are for products then? maybe mine are too strict?

 

ok, well here is what i did and i seem to be getting decent results. before i had 1st class parcel enabled for my smaller items up to 13oz of course. this is so locals dont get hosed on small stuff.

 

then i unchecked all the flat rate items and just left "priority" up to 70lbs. so only thing enabled is first class parcel 0,.8125 and priority (not priority express, priority flat rate, just "priority") 0,40. seems to be working and i can live with not having flat rate i guess.

Link to comment
Share on other sites

NEW and Improved!

 

Yes, I have a better filter. This one has been tested for a wide range of weights and services and hasn't failed. Yet. I'm not saying it is perfect, but it's one step further towards fixing this mess.

 

Find that same block of code and replace it with this:

 

    $body = preg_replace( array(
	  '/^[0-9a-f]+\v+/',
	  '/\v+[0-9a-f]+\v+/',
	  '{<sup>®</sup>}',  /* Registered Trademark symbol - July 2013 update */
	  '{<sup>™</sup>}',  /* Trademark symbol - July 2013 update */
	  '/<br>/'
    ), array (
	  '',
	  '',
	  'RM',
	  'TM',
	  'BREAK'
    ), htmlspecialchars_decode($response));

 

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

 

Regards

Jim

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

Link to comment
Share on other sites

NEW and Improved!

 

Yes, I have a better filter. This one has been tested for a wide range of weights and services and hasn't failed. Yet. I'm not saying it is perfect, but it's one step further towards fixing this mess.

 

Find that same block of code and replace it with this:

 

 $body = preg_replace( array(
	 '/^[0-9a-f]+\v+/',
	 '/\v+[0-9a-f]+\v+/',
	 '{<sup>®</sup>}', /* Registered Trademark symbol - July 2013 update */
	 '{<sup>™</sup>}', /* Trademark symbol - July 2013 update */
	 '/<br>/'
 ), array (
	 '',
	 '',
	 'RM',
	 'TM',
	 'BREAK'
 ), htmlspecialchars_decode($response));

 

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

 

Regards

Jim

 

i will test this. i tested tons of combo's with me just enabling first class parcel and priority. but if this enables the others i will check it out!

Link to comment
Share on other sites

Hey guys, appreciate the work you have been doing here. It looks like the vanilla USPS Methods add-on is also hosed for a similar issue.

 

I know you guys have your hands full already, but has anyone came across an issue with this module not showing up on the admin page? I tried installing ( and of course, subsequently re-installing) this module, but it appears to be crashing out. The admin/module/shipping page doesn't show it, nor my installed and running UPS module (this is 2.2RC BTW).

 

I assume this has something to do with the admin/modules.php file not being right? I diff'ed my version (copyright 2003, with an extra header comment about modifications for USPS Methods) with the one included and they are vastly different. Using the modules.php that's included, I get a 500 eror on the admin page that I can't seem to trace down.

 

Anyone came across anything like this?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...