AbanteCart Community

Shopping Cart Operations => Support => Extension Support => Topic started by: Heemet on November 19, 2017, 07:46:09 PM

Title: USPS extension on but not showing up
Post by: Heemet on November 19, 2017, 07:46:09 PM
Hello everyone,

New to the forum here. 

I installed the USPS extension and enabled it, but USPS is not showing up as a shipping option at check out.  I'm not including shipping in the price of the items I'm selling.  I've enabled priority mail and media mail, but I don't see these options at checkout.

I tested my user ID using the XML test request that the USPS suggests, and I got a response back.  So, my user ID isn't an issue.

I've tried uninstalling and then reinstalling the extension, but that didn't fix things.

Am I missing something?  Any suggestions are appreciated.

Thanks for your time.

ETA: I tried enabling another shipping extension, e.g., default_free_shipping, and that option appeared at checkout.
Title: Re: USPS extension on but not showing up
Post by: Basara on November 20, 2017, 01:02:48 AM
Hello. Make sure your product have correct weight, also check your USPS API is in live, check that customer address is valid etc.
https://abantecart.atlassian.net/wiki/spaces/AD/pages/17661953/USPS
Title: Re: USPS extension on but not showing up
Post by: Heemet on November 20, 2017, 11:58:28 AM
Thanks.  I've got the weight set.

The API appears to be active.  Per the USPS's suggestion, I inserted the following XML code (edited because I can't post an external link) into my browser's search bar (replacing xxxxxxxxxxxx with my userID), and I got a response, which would seem to indicate that my userID is active:

.....ShippingApi.dll?API=RateV4&XML=<RateV4Request USERID="xxxxxxxxxxxx">
<Package ID="1ST">
<Service>PRIORITY</Service>
<ZipOrigination>44106</ZipOrigination>
<ZipDestination>20770</ZipDestination>
<Pounds>1</Pounds>
<Ounces>8</Ounces>
<Container>NONRECTANGULAR</Container>
<Size>LARGE</Size>
<Width>15</Width>
<Length>30</Length>
<Height>15</Height>
<Girth>55</Girth>
</Package>

</RateV4Request>

How do I see what XML code is being sent to the USPS and the XML I'm receiving in response?
Title: Re: USPS extension on but not showing up
Post by: Basara on November 21, 2017, 01:08:26 AM
Hi.

What is your AbanteCart and USPS extension versions?
Title: Re: USPS extension on but not showing up
Post by: Heemet on November 21, 2017, 02:31:20 PM
Hi,

AbanteCart v. 1.2.11

USPS extension v. 1.0.2

I did a clean install of AbanteCart last night, and installed the USPS extension.  At first, the shipping option didn't show up on the stock site, but after filling in some of the details in System->Settings->Store details, USPS started showing up as a shipping option.  I don't understand that.

I fooled around today with turning on and off various shipping options in the USPS extension, e.g., priority mail, media mail, first class mail.  At first I could see some of these options showing up in the cart estimate (although they didn't match exactly what I had just selected) but now USPS is no longer available as a shipping option.  It's very strange.

Our site uses Cloudflare.  I'm not sure if that's a problem.  I've tried turning on development mode in Cloudflare (to turn off caching there), but it didn't make a difference.

Thanks!
Title: Re: USPS extension on but not showing up
Post by: Basara on November 22, 2017, 12:30:45 AM
Our site uses Cloudflare.  I'm not sure if that's a problem.  I've tried turning on development mode in Cloudflare (to turn off caching there), but it didn't make a difference.

Hello. Try to disable it completely.   ::) Cloudflare knows as bug maker. They have a lot of experimental or not well supported features. If you still want to use it I suggest to enable only images and css caching. This will speed up your site and will not broke anything.
Title: Re: USPS extension on but not showing up
Post by: Heemet on November 22, 2017, 12:27:35 PM
Thanks for your reply and your continued help.  I disabled Cloudflare and changed the nameservers back to my original host's.  USPS shipping is still not showing up as an option.  I've confirmed that the page is being served by my host and no longer Cloudflare.

When I first view the cart, the form data sent with the POST (request URL "Request URL:.../store/index.php?rt=r/checkout/cart/change_zone_get_shipping_methods") sent by the shipping estimator is "country_id=223&zone_id=3663&postcode=", which makes sense, since no zip code was inputted yet.  The response is "{"default_usps":{"title":"United States Postal Service","quote":[],"sort_order":"0","error":"Missing value for ZipDestination."},"selectbox":""}", which also makes sense.

When I input the zip code in the shipping calculator, the URL request is the same, and the form data includes the zip code.  However, the response (in the browser's console) is blank.

How do I check the XML sent to the USPS's API and the response?

ETA: My workaround for this is to set up weight-based shipping, which I can easily do because all of my items will ship USPS media mail, which is solely a weight-based shipping method.  At this point, I'm trying to get to the bottom of this for the sake of others who might be facing a similar problem.  Thank you!
Title: Re: USPS extension on but not showing up
Post by: abolabo on November 23, 2017, 03:57:02 AM
How do I check the XML sent to the USPS's API and the response?

hi.
You can open file public_html/extensions/default_usps/storefront/model/extension/default_usps.php and put inside something like that
Code: [Select]
$this->log->write(var_export($xml,true));
before curl-request, in line 231
Then see xml in your error-log on admin side
Title: Re: USPS extension on but not showing up
Post by: Heemet on November 24, 2017, 12:06:13 AM
Thanks you, abolabo! 

The XML code passed to the USPS's API and visible in the error-log is correct.

I added the following to line 238 of default_usps.php and I logged a response back from the USPS:
$this->log->write(var_export($result,true));

The response is well formed, and the prices are correct, but I'm seeing no estimates for USPS shipping options in the cart estimator.  I have only first class, priority mail, and media mail enabled.

I guess the data back from the USPS isn't getting into the drop-down box?
Title: Re: USPS extension on but not showing up
Post by: Basara on November 24, 2017, 12:41:14 AM
Hi. Estimate require to enter ZIP code. Without zip it will not work
Title: Re: USPS extension on but not showing up
Post by: Heemet on November 24, 2017, 11:31:50 AM
Hi Basara,

I inputted the zip code.  Here's the log for the outgoing XML (USERID and PASSWORD redacted):

2017-11-23 22:53:54 - '<RateV4Request USERID="XXXXX" PASSWORD="XXXXX">   <Package ID="1">   <Service>ALL</Service>   <ZipOrigination>19610</ZipOrigination> <ZipDestination>19610</ZipDestination>   <Pounds>1</Pounds>   <Ounces>9.12</Ounces>   <Container>VARIABLE</Container>   <Size>REGULAR</Size>   <Width>11.875</Width>   <Length>13.625</Length> <Height>3.375</Height>   <Girth>44.1</Girth>   <Machinable>true</Machinable>   </Package></RateV4Request>'

Here's the of the XML response from the USPS:

2017-11-23 22:53:55 - '<?xml version="1.0" encoding="UTF-8"?>
<RateV4Response><Package ID="1"><ZipOrigination>19610</ZipOrigination><ZipDestination>19610</ZipDestination><Pounds>1</Pounds><Ounces>9.12</Ounces><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>1</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</MailService><Rate>23.75</Rate></Postage><Postage CLASSID="2"><MailService>Priority Mail Express 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Hold For Pickup</MailService><Rate>23.75</Rate></Postage><Postage CLASSID="1"><MailService>Priority Mail 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</MailService><Rate>7.20</Rate></Postage><Postage CLASSID="17"><MailService>Priority Mail 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Medium Flat Rate Box</MailService><Rate>13.60</Rate></Postage><Postage CLASSID="6"><MailService>Media Mail Parcel</MailService><Rate>3.12</Rate></Postage><Postage CLASSID="7"><MailService>Library Mail Parcel</MailService><Rate>2.97</Rate></Postage></Package></RateV4Response>'

The response is correct.  The item costs USD 3.12 to ship via media mail.  However, none of the prices are showing up in the drop down box in the shipping estimator.

Thanks!
Title: Re: USPS extension on but not showing up
Post by: Basara on December 12, 2017, 08:44:57 AM
Hello.

FYI one issue were fixed in 1.2.12 you can apply fix to 1.2.11 manually see commit in https://github.com/abantecart/abantecart-src/issues/1034
Title: Re: USPS extension on but not showing up
Post by: Heemet on December 13, 2017, 11:42:30 PM
Thank you, gentlemen, for your assistance with this.  I successfully applied the fix manually, and it works perfectly now.

 :)
Title: Re: USPS extension on but not showing up
Post by: Heemet on September 07, 2018, 11:50:28 PM
It appears that the problem has reappeared.  I have upgraded to AbanteCart v 1.2.13, and the USPS option has disappeared as a shipping option.  I do not see it when estimating shipping in my shopping cart.

I modified the usps extension to log the xml request and response (lines 231-238 of public_html/extensions/default_usps/storefront/model/extension/default_usps.php):
Code: [Select]
$this->log->write(var_export($xml,true));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://secure.shippingapis.com/ShippingAPI.dll?' . $request);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$this->log->write(var_export($result,true));

I checked the log file.  The request is well formed, but the result is blank.

Any idea what happened?
Title: Re: USPS extension on but not showing up
Post by: Heemet on September 08, 2018, 12:01:53 AM
The top of default_usps.php installed in my store still says © 2011-2017 Belavier Commerce LLC.  Is that right, or does that indicate that it is not the right version of default_usps.php for v 1.2.13?
Title: Re: USPS extension on but not showing up
Post by: Basara on September 10, 2018, 01:18:13 AM
The top of default_usps.php installed in my store still says © 2011-2017 Belavier Commerce LLC.  Is that right, or does that indicate that it is not the right version of default_usps.php for v 1.2.13?

Upgrade package usually do not contain small changes like year in comments. But you can always get latest code from https://github.com/abantecart/abantecart-src/tree/master/public_html/extensions
Title: Re: USPS extension on but not showing up
Post by: Heemet on September 11, 2018, 10:28:01 PM
I guess what I'm saying is that it does not appear that the USPS extension upgraded when I upgraded from AbanteCart 1.2.12 to 1.2.13.  I suspect that is the reason it is no longer working. 

How do I download the entire default_usps folder from GitHub so that I can copy it into CPanel?  Or can I delete the extension from within the store admin site and reinstall it?

Thanks!
Title: Re: USPS extension on but not showing up
Post by: natdroid on September 12, 2018, 01:11:34 AM
http://www.abantecart.com/download-abantecart
Title: Re: USPS extension on but not showing up
Post by: Heemet on September 12, 2018, 11:01:29 PM
Thanks for the link. 

It appears that the USPS extension did not update when I updated to AbanteCart 1.2.13.  I updated the extension manually, uninstalled it, and then reinstalled it and tried it out in a test shopping cart.  It is still not working.

I added the following to public_html/store/extensions/default_usps/storefront/model/extension/default_usps.php (lines 234-241):

Code: [Select]
$this->log->write(var_export($xml,true));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://secure.shippingapis.com/ShippingAPI.dll?'.$request);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$this->log->write(var_export($result,true));

I'm not getting a response back from the USPS after clicking "Estimate" in the shopping cart.

This is what the log file shows:
2018-09-13 2:47:06 - '<RateV4Request USERID="XXX" PASSWORD="XXX">   <Package ID="1"> <Service>ALL</Service> <ZipOrigination>02138</ZipOrigination> <ZipDestination>02138</ZipDestination> <Pounds>0</Pounds> <Ounces>2.08</Ounces> <Container>VARIABLE</Container> <Size>REGULAR</Size> <Width>11.875</Width> <Length>13.625</Length> <Height>3.375</Height> <Girth>44.1</Girth> <Machinable>true</Machinable>   </Package></RateV4Request>'

2018-09-13 2:47:06 - ''

The default USPS extension worked prior to the upgrade.  Any advice is appreciated.

Thanks!
Title: Re: USPS extension on but not showing up
Post by: abolabo on September 13, 2018, 02:54:01 AM
Here's the of the XML response from the USPS:

2017-11-23 22:53:55 - '<?xml version="1.0" encoding="UTF-8"?>
<RateV4Response><Package ID="1"><ZipOrigination>19610</ZipOrigination><ZipDestination>19610</ZipDestination><Pounds>1</Pounds><Ounces>9.12</Ounces><Size>REGULAR</Size><Machinable>TRUE</Machinable><Zone>1</Zone><Postage CLASSID="3"><MailService>Priority Mail Express 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</MailService><Rate>23.75</Rate></Postage><Postage CLASSID="2"><MailService>Priority Mail Express 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Hold For Pickup</MailService><Rate>23.75</Rate></Postage><Postage CLASSID="1"><MailService>Priority Mail 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</MailService><Rate>7.20</Rate></Postage><Postage CLASSID="17"><MailService>Priority Mail 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Medium Flat Rate Box</MailService><Rate>13.60</Rate></Postage><Postage CLASSID="6"><MailService>Media Mail Parcel</MailService><Rate>3.12</Rate></Postage><Postage CLASSID="7"><MailService>Library Mail Parcel</MailService><Rate>2.97</Rate></Postage></Package></RateV4Response>'

The response is correct.  The item costs USD 3.12 to ship via media mail.  However, none of the prices are showing up in the drop down box in the shipping estimator.

Thanks!

You should to check customer address , usps settings (location) and store address.
Filtering of shipping methods list based on it
Title: Re: USPS extension on but not showing up
Post by: Heemet on September 13, 2018, 09:13:39 PM
Thanks.  The request sent to the USPS API is well formatted.  If I paste it into the address bar on my browser, I get a response with the correct information fro the USPS API.  However, the response being logged in AbanteCart's log is empty.  The problem isn't with customer address, usps settings (location), or store address, I don't believe.  I've verified those.

I think something is going wrong with cURL session, but I'm not terribly familiar with php.
Title: Re: USPS extension on but not showing up
Post by: Basara on September 18, 2018, 03:03:26 AM
Hello.

USPS is work in 1.2.13
I think you need to ask your hosting support about recent changes on server.
Take a note that anything additional like cloudflare "optimizations" (  :'( ) or server mod_security module may block some requests
Title: Re: USPS extension on but not showing up
Post by: Heemet on October 03, 2018, 10:40:21 PM
Thanks, Basara.  I modified the default_usps.php file to find out what exactly was happening with the cURL request.  It was properly formatted.  The response I was getting was a 400 bad gateway.

Per your suggestion, I followed up with the hosting provider.  They had recently moved my site to a new server.  I told them that I thought the problem was with the PHP cURL package.  They decided to move my site to another server, and sure enough, the problem went away.

So, the problem turned out to be in the host's cURL package.  It was a tough bug to track down.
Title: Re: USPS extension on but not showing up
Post by: Basara on October 04, 2018, 01:00:51 AM
Thanks, Heemet for the update  :)