
Originally Posted by
swguy
This is the standard mechanism that modules use to avoid logs from undefined variables in recent versions of PHP. Compare any other payment module and you'll see this pattern.
i have no idea what standard mechanism means. and just because it was done that way does not make it right.
i would suggest spending more time testing prior to posting code. your early return completely changes how square is presented to the store owner prior to install. and either we want our code to conform to PSR or we do not. i prefer my code to conform to said standards as i am a fan of the PHP Standards Recommendation (PSR).
back to the problem at hand; here is the fix for said code. changes start at line 105.
PHP Code:
// from:
$environment = Environment::PRODUCTION;
if (MODULE_PAYMENT_SQ_WEBPAY_TESTING_MODE === 'Sandbox') {
$environment = Environment::SANDBOX;
}
$this->client = new SquareClient([
'accessToken' => MODULE_PAYMENT_SQ_WEBPAY_ACCESS_TOKEN,
'environment' => $environment,
]);
// to:
$environment = Environment::PRODUCTION;
if (defined('MODULE_PAYMENT_SQ_WEBPAY_TESTING_MODE') && MODULE_PAYMENT_SQ_WEBPAY_TESTING_MODE === 'Sandbox') {
$environment = Environment::SANDBOX;
}
$this->token= '';
if (defined('MODULE_PAYMENT_SQ_WEBPAY_ACCESS_TOKEN')) {
$this->token = MODULE_PAYMENT_SQ_WEBPAY_ACCESS_TOKEN;
}
$this->client = new SquareClient([
'accessToken' => $this->token,
'environment' => $environment,
]);
@WayneStephens please let me know if that works for you.
also, noting that these errors exist and are logged in php 7.4; in php 8.0, they are now fatal errors.
best.
Bookmarks