I have created a very basic module to display EasyPost Tracking information for our customers. The module works in J3, but in J4 I get an error.
This is the code I have:
use Joomla\CMS\Factory;
$input = Factory::getApplication()->input;
$tracking_number = $input->get("tracking_number", "", "ALNUM");
$carrier = $input->get("carrier", "", "ALNUM");
$api_key = $params->get('api_key');
// add EasyPost NameSpace library
JLoader::registerNamespace('EasyPost', JPATH_LIBRARIES. '/lib');
// get EasyPost library
require_once(JPATH_LIBRARIES . '/lib/EasyPost/EasyPost.php');
// set api key
\EasyPost\EasyPost::setApiKey($api_key);
if(!empty($tracking_number)) {
try {
$EZtracker = \EasyPost\Tracker::create(array(
"tracking_code" => $tracking_number,
"carrier" => $carrier
));
When I call the class to set the api key it seems to work.
\EasyPost\EasyPost::setApiKey($api_key);
But when I call the static create method from tracker class with:
$EZtracker = \EasyPost\Tracker::create(array(...));
I get the error:
Message: Class "EasyPost\Tracker" not found.
How do I update this code to work in Joomla 4?
<namespace>
attribute of the manifest as part of the install process of a library extension. Is the EasyPost Library installed as an extension or have you just added it to your Library directory? If you comment the out the 'require_once' statement does the setApiKey() statement also report class not found?