Zen Follower
- Join Date:
- Jul 2011
- Posts:
- 167
- Plugin Contributions:
- 0
USPS Shipping (RESTful) (USPSr)
I know us stragglers are a real pain but than you nonetheless. I'll give this a try soon, and will report back with any results.
Views: 54,963
Zen Follower
I know us stragglers are a real pain but than you nonetheless. I'll give this a try soon, and will report back with any results.
Totally Zenned
Has anyone integrated this module with Shipping Boxes Manager?
marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14
Totally Zenned
marcopolo:
Has anyone integrated this module with Shipping Boxes Manager?
Has not occured to me to merge the two but I will look into it.
Totally Zenned
We have the latest non-encapsulated version installed on a 1.5.8a site.
PHP 7.4.33
OPC 2.4.6 allowing Guest Checkout
Clone of Bootstrap 3.6.0
We've done the changes to includes/modules/shipping/uspsr.php mentioned in p;ost #179.
Turned on Generate Logs and Show Errors.
No USPS options are showing on either the shopping cart's shipping estimator or after a shipping address is entered in Guest Checkout.
After basic information, the log states:
2025-08-29 16:14:22: No token detected, requesting session token from USPS
Token Request
{
"grant_type": "client_credentials",
"client_id": "***********",
"scope": "domestic-prices addresses international-prices service-standards shipments"
}
2025-08-29 16:14:22:
==================================
TOKEN RESPONSE FROM USPS:
{
"access_token": "eyJraWQiOiJIdWpzX2F6UnFJUzBpSE5YNEZIRk96eUwwdjE4RXJMdjNyZDB--DELETED--i-YqJm6xY529kEa0WZ0YOLiCVPz6eUeJpigtSeCwSd4wdwFb6KT9eeUuaOEud_WxVaEYc5CDDlc3IxbReOfbNsUuWKfsQ3_f1lMATerBYOuRWxP70UttzUJEEj52xY7_f6lAYlV7ge47RlyNldNTlqymSOiRx6chW9BwADYBjerVGQl3bGAkJZi4EAh0UFc3H_sxftaMOE7KK2WJRx8CRI2tQZ7wERzjnt6AhCLrKk1uDOmFUYegPwZLUhWL9ia2g-eI406x5UbLXgyQe4BVLZZ-Hv8Kz6SI74x8j8XnLvd7vWOaaw9PUmGrPoBx4OWCvsBbairyo1HJsWvO6OAag",
"token_type": "Bearer",
"issued_at": 1756484062962,
"expires_in": 28799,
"status": "approved",
"scope": "domestic-prices addresses international-prices service-standards shipments",
"issuer": "https://keyc.usps.com/realms/USPS",
"client_id": "***********************",
"application_name": "*********",
"api_products": "[Public Access I]",
"public_key": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF1UjQzS0hRdm44UlYybWplMEczSAptKzI3dnA4Z-- DELETED --Q0xwYVcwTG1GVGoyYUpTOUt3TnhHb2pIakV5TjhIVG5zd1lOKzdQNVlLVmxobHUKL1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t"
}
---------------------------------
CommErr (should be 0): 0 -
==================================
Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com
Totally Zenned
dbltoe:
We have the latest non-encapsulated version installed on a 1.5.8a site.
PHP 7.4.33
OPC 2.4.6 allowing Guest Checkout
Clone of Bootstrap 3.6.0We've done the changes to includes/modules/shipping/uspsr.php mentioned in p;ost #179.
Turned on Generate Logs and Show Errors.
No USPS options are showing on either the shopping cart's shipping estimator or after a shipping address is entered in Guest Checkout.
After basic information, the log states:
```
2025-08-29 16:14:22: No token detected, requesting session token from USPS
Token Request
{
"grant_type": "client_credentials",
"client_id": "***********",
"scope": "domestic-prices addresses international-prices service-standards shipments"
}
TOKEN RESPONSE FROM USPS:
{
"access_token": "eyJraWQiOiJIdWpzX2F6UnFJUzBpSE5YNEZIRk96eUwwdjE4RXJMdjNyZDB--DELETED--i-YqJm6xY529kEa0WZ0YOLiCVPz6eUeJpigtSeCwSd4wdwFb6KT9eeUuaOEud_WxVaEYc5CDDlc3IxbReOfbNsUuWKfsQ3_f1lMATerBYOuRWxP70UttzUJEEj52xY7_f6lAYlV7ge47RlyNldNTlqymSOiRx6chW9BwADYBjerVGQl3bGAkJZi4EAh0UFc3H_sxftaMOE7KK2WJRx8CRI2tQZ7wERzjnt6AhCLrKk1uDOmFUYegPwZLUhWL9ia2g-eI406x5UbLXgyQe4BVLZZ-Hv8Kz6SI74x8j8XnLvd7vWOaaw9PUmGrPoBx4OWCvsBbairyo1HJsWvO6OAag",
"token_type": "Bearer",
"issued_at": 1756484062962,
"expires_in": 28799,
"status": "approved",
"scope": "domestic-prices addresses international-prices service-standards shipments",
"issuer": "https://keyc.usps.com/realms/USPS",
"client_id": "**************",
"application_name": "",
"api_products": "[Public Access I]",
"public_key": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF1UjQzS0hRdm44UlYybWplMEczSAptKzI3dnA4Z-- DELETED --Q0xwYVcwTG1GVGoyYUpTOUt3TnhHb2pIakV5TjhIVG5zd1lOKzdQNVlLVmxobHUKL1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t"
}
CommErr (should be 0): 0 -
==================================
">>
Was there a ZenCart error generated?
Totally Zenned
retched:
Was there a ZenCart error generated?
I'm running the same exact identical build, 1.3 2 USPSr with the same PHP 7 and I get options fine. Is there an error message generated or displayed anywhere?
Totally Zenned
I tried bumping it to PHP 8.1, which threw a 500 for another item in that store.
Dropped back to 8.0 with no display logs but did find this in the logs folder:
[29-Aug-2025 16:53:58 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: *************, Language id 1#1 uspsr->update_status() called at [/home/soycnanc/public_html/includes/modules/shipping/uspsr.php:182]
#2 uspsr->__construct() called at [/home/soycnanc/public_html/includes/classes/shipping.php:91]
#3 shipping->__construct() called at [/home/soycnanc/public_html/includes/modules/shipping_estimator.php:161]
#4 require(/home/soycnanc/public_html/includes/modules/shipping_estimator.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/modalboxes/tpl_shipping_estimator.php:19]
#5 require(/home/soycnanc/public_html/includes/templates/boot_soyc/modalboxes/tpl_shipping_estimator.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/templates/tpl_shopping_cart_default.php:204]
#6 require(/home/soycnanc/public_html/includes/templates/boot_soyc/templates/tpl_shopping_cart_default.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/common/tpl_main_page.php:216]
#7 require(/home/soycnanc/public_html/includes/templates/boot_soyc/common/tpl_main_page.php) called at [/home/soycnanc/public_html/index.php:94]
--> PHP Warning: foreach() argument must be of type array|object, string given in /home/soycnanc/public_html/includes/modules/shipping/uspsr.php on line 1731.
Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com
Totally Zenned
dbltoe:
I tried bumping it to PHP 8.1, which threw a 500 for another item in that store.
Dropped back to 8.0 with no display logs but did find this in the logs folder:
[29-Aug-2025 16:53:58 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: *************, Language id 1#1 uspsr->update_status() called at [/home/soycnanc/public_html/includes/modules/shipping/uspsr.php:182]
#2 uspsr->__construct() called at [/home/soycnanc/public_html/includes/classes/shipping.php:91]
#3 shipping->__construct() called at [/home/soycnanc/public_html/includes/modules/shipping_estimator.php:161]
#4 require(/home/soycnanc/public_html/includes/modules/shipping_estimator.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/modalboxes/tpl_shipping_estimator.php:19]
#5 require(/home/soycnanc/public_html/includes/templates/boot_soyc/modalboxes/tpl_shipping_estimator.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/templates/tpl_shopping_cart_default.php:204]
#6 require(/home/soycnanc/public_html/includes/templates/boot_soyc/templates/tpl_shopping_cart_default.php) called at [/home/soycnanc/public_html/includes/templates/boot_soyc/common/tpl_main_page.php:216]
#7 require(/home/soycnanc/public_html/includes/templates/boot_soyc/common/tpl_main_page.php) called at [/home/soycnanc/public_html/index.php:94]
--> PHP Warning: foreach() argument must be of type array|object, string given in /home/soycnanc/public_html/includes/modules/shipping/uspsr.php on line 1731.
In your configuration, are you limiting who can use the shipping module by zone with one item in it?
Totally Zenned
Yes, the product only ships in the continental US.
Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com
Totally Zenned
dbltoe:
Yes, the product only ships in the continental US.
Yup that's what it is. Thought I got that one a while ago. This is going to happen regarding of PHP version.
Need a bit for this.
Totally Zenned
So... I'm having a bit of a conundrum...Is it normal that the Shipping Estimator isn't setting the zone_id variable of the $order-> object? If that's normal behavior, I can proceed.
Administrator
retched:
So... I'm having a bit of a conundrum...Is it normal that the Shipping Estimator isn't setting the zone_id variable of the $order-> object? If that's normal behavior, I can proceed.
On initial entry to the shipping-estimator, only the country (which is set to the store's default country) is guaranteed to be set.
Totally Zenned
lat9:
On initial entry to the shipping-estimator, only the country (which is set to the store's default country) is guaranteed to be set.
Well, I meant that if it was normal for the shipping estimator not to change or set any details of the $order object as a whole when making selections. But I managed to get around this, though.
There is a solution ready that I would like some testing with to make sure it's doing what its supposed to be doing. It's currently on the "restriction-bug" branch of the repo:
https://github.com/retched/ZC-USPSRestful/tree/restriction-bug
I've done light testing on ZC 1.5.8 and 2.1.0 at the "minimum" PHP versions. But would rather get more people to validate it before I go through the process of stamping and publishing. DMs are open if anything.
Totally Zenned
For those that are not familiar with navigating a repository on GitHub, you can just navigate to this page:
https://github.com/retched/ZC-USPSRestful/blob/restriction-bug/zc_plugins/USPSRestful/v0.0.0/catalog/includes/modules/shipping/uspsr.php
Or download the uspsr.php file attached:
Once downloaded, directly upload in place of the uspsr.php file where necessary (if encapsulated, modify the /zc_plugins/ZC-USPSRestful/vXXX/catalog/includes/modules/shipping/uspsr.php . If not, /includes/modules/shipping/uspsr.php . This will render your installation as 0.0.0 as I did not assign a version number yet.)
Zen Follower
retched:
For those that are not familiar with navigating a repository on GitHub, you can just navigate to this page:
https://github.com/retched/ZC-USPSRestful/blob/restriction-bug/zc_plugins/USPSRestful/v0.0.0/catalog/includes/modules/shipping/uspsr.phpOr download the uspsr.php file attached:
Once downloaded, directly upload in place of the uspsr.php file where necessary (if encapsulated, modify the /zc_plugins/ZC-USPSRestful/vXXX/catalog/includes/modules/shipping/uspsr.php . If not, /includes/modules/shipping/uspsr.php . This will render your installation as 0.0.0 as I did not assign a version number yet.)
I'll see what I can do, hopefully tonight. my 1.5.5f php 7.1 is probably your lowest common denominator, but I am still trying to figure out what is suppressing most of the log messages. Must have been something I've done years ago.
Totally Zenned
chibipaw:
I'll see what I can do, hopefully tonight. my 1.5.5f php 7.1 is probably your lowest common denominator, but I am still trying to figure out what is suppressing most of the log messages. Must have been something I've done years ago.
Looking at what I changed, nothing was suppressed but rather a bad logical comparison acted the wrong way and was filtering everything out. It still processed but because nothing stopped the module from proceeding it never found a condition to enable it again. And thus, it turned itself off.
Totally Zenned
retched:
Looking at what I changed, nothing was suppressed but rather a bad logical comparison acted the wrong way and was filtering everything out. It still processed but because nothing stopped the module from proceeding it never found a condition to enable it again. And thus, it turned itself off.
I’m not sure if this is directly related to what you’re working on, but I ran into something similar when converting this module for an older site running Zen Cart 1.5.5 with PHP 5.6. I had to rework how it generates the admin settings, since that was causing an issue where quotes weren’t being returned. That conversion was for version 1.2.0. I haven’t converted 1.3.2 yet, because when I compared it against 1.2.0 there were a lot of differences—mostly styling rather than functional changes—so it ends up being more time-consuming than it should be to sort through.
If you think it might help, I can upload the copy I put together. I fixed a typo from an earlier attempt I uploaded, though honestly I doubt many are still running PHP 5.6 these days.
marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14
Totally Zenned
marcopolo:
I’m not sure if this is directly related to what you’re working on, but I ran into something similar when converting this module for an older site running Zen Cart 1.5.5 with PHP 5.6. I had to rework how it generates the admin settings, since that was causing an issue where quotes weren’t being returned. That conversion was for version 1.2.0. I haven’t converted 1.3.2 yet, because when I compared it against 1.2.0 there were a lot of differences—mostly styling rather than functional changes—so it ends up being more time-consuming than it should be to sort through.
If you think it might help, I can upload the copy I put together. I fixed a typo from an earlier attempt I uploaded, though honestly I doubt many are still running PHP 5.6 these days.
Depending on the version used, I think that might have been before I realized that the $method variable had to be specifically called as a part of the quotation method. Also, a lot of what I do in the admin area is a bit hacky, so I can understand a lot of work being needed on it. I might go ahead and try to set up a 5.6 environment and test there.
chibipaw:
I'll see what I can do, hopefully tonight. my 1.5.5f php 7.1 is probably your lowest common denominator, but I am still trying to figure out what is suppressing most of the log messages. Must have been something I've done years ago.
7.3 tends to be the PHP7 version I test on, but I'm getting the same results on the earlier ZC/PHP combos too. This is more or less me trying to spot check for faults as I keep making these changes for the new versions.
Totally Zenned
retched:
Depending on the version used, I think that might have been before I realized that the $method variable had to be specifically called as a part of the quotation method. Also, a lot of what I do in the admin area is a bit hacky, so I can understand a lot of work being needed on it. I might go ahead and try to set up a 5.6 environment and test there.
7.3 tends to be the PHP7 version I test on, but I'm getting the same results on the earlier ZC/PHP combos too. This is more or less me trying to spot check for faults as I keep making these changes for the new versions.
Here is the the converted version of USPSRestful-1.2.0 I did works fine on Zencart 1.5.5f - using PHP 5.6
marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14
Totally Zenned
So far, it seems to be working on the site using the single zone and non-encapsulated version.
Let me know when you have something without a warning.
Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com
Tell staff why this post should be reviewed.