Square Payment Processing: myDEBUG file generated
156a vanilla install w/demo data
drop tables
import backup from live db
run db cleanup from myPHPadmin.
run zc_install
Upload USPS modules, remove, delete, reinstall and setup
Upload Fedex modules, remove, delete, reinstall and setup
Remove, delete, reinstall A.net SIM
Remove, delete, reinstall A.net AIM
Install, setup Square
Upload zca_bootstrap template
switch to zca_bootstrap template
run zca_bootstrap mySQL
Complete test order using Square as payment form
Order completed as expected.
Found myDEBUG file associated with the checkout
myDEBUG
Code:
[10-Jan-2019 15:07:28 America/Los_Angeles] Request URI: /156/index.php?main_page=checkout_process, IP address: 98.146.xxx.yyy
#1 square->before_process() called at [/home/cPanelID/public_html/156/includes/classes/payment.php:245]
#2 payment->before_process() called at [/home/cPanelID/public_html/156/includes/modules/checkout_process.php:85]
#3 require(/home/cPanelID/public_html/156/includes/modules/checkout_process.php) called at [/home/cPanelID/public_html/156/includes/modules/pages/checkout_process/header_php.php:14]
#4 require(/home/cPanelID/public_html/156/includes/modules/pages/checkout_process/header_php.php) called at [/home/cPanelID/public_html/156/index.php:36]
--> PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/cPanelID/public_html/156/includes/modules/payment/square.php on line 354.
Re: Square Payment Processing: myDEBUG file generated
NOTE: This is ONLY reporting a warning, which only occurs because of PHP 7.2's new strict mode.
The irony is that it's triggered when checking if any errors exist, and since nothing has been recorded as errors, but the variable where errors are stored hasn't been declared, this warning is triggered.
You can fix this minor issue by adding a new line as shown here, around line 325 in /includes/modules/payment/square.php:
Code:
$body = new \SquareConnect\Model\ZenCartChargeRequest($request_body);
$errors_object = array();
try {
$result = $api_instance->charge($location->id, $body);
$errors_object = $result->getErrors();
Re: Square Payment Processing: myDEBUG file generated
Not sure if this belongs here or if it should be in the Square support thread -
I've added the define for $errors_object per your suggestion, but am still getting warnings for orders and refunds. Here's the latest one I received from a refund today:
--> PHP Warning: count(): Parameter must be an array or an object that implements Countable in /usr/www/users/xxx/includes/modules/payment/square.php on line 954.
Also getting a similar warning when orders are placed.
Any suggestions?
php7.2
v1.56c
mysql 5.7x
Re: Square Payment Processing: myDEBUG file generated
As includes/modules/payment/square.php is Zen Cart code (not part of the Square "API"), line 954 should be changed from:
Code:
if (count($errors_object)) {
To:
Code:
if (!empty($errors_object)) {
This way if the result is null, then the internal code will be ignored, but it seems that otherwise it will be an array. If that still causes issue within the if statement, then it would be:
Code:
if (!empty($errors_object) && is_array($errors_object)) {
The response null is not countable which would cause the response received.
Re: Square Payment Processing: myDEBUG file generated
Quote:
Originally Posted by
DrByte
NOTE: This is ONLY reporting a warning, which only occurs because of PHP 7.2's new strict mode.
The irony is that it's triggered when checking if any errors exist, and since nothing has been recorded as errors, but the variable where errors are stored hasn't been declared, this warning is triggered.
You can fix this minor issue by adding a new line as shown here, around line 325 in /includes/modules/payment/square.php:
Code:
$body = new \SquareConnect\Model\ZenCartChargeRequest($request_body);
$errors_object = array();
try {
$result = $api_instance->charge($location->id, $body);
$errors_object = $result->getErrors();
DrByte; however, when looking at current ZC 1.5.6 code, both the try and catch parts contain an assignment of $errors_object so that it is defined in both cases. Looking at the response results code, it appears that if there is no error, then $errors_object will have a value of null. The value null is not countable leading to the warning(s) reported. This review was performed on the v156 branch of github instead of v1.5.6c, but regardless would apply.
I did not though exhautively search to validate that all error results would be an array which is why I suggested to edadk that a check of is_array may also be necessary. The thought though is that all error responses are either null or an array containing the associated error response data and therefore such a check should not be necessary for properly written code.
Re: Square Payment Processing: myDEBUG file generated
Thank you for the reply.
I will try the first code block and report any change.
The line 954 error came up during a refund. Previously, a similar error that referenced line 354 came after a sale. I will try making the change there also.
I note that the same code also appears on lines 1017 and 1079 approx. I have not encountered errors relating to those lines so I will leave them alone for now.
Re: Square Payment Processing: myDEBUG file generated
Received an order today with no warnings, so that change works.
Thanks very much.
Re: Square Payment Processing: myDEBUG file generated
Quote:
Originally Posted by
edadk
Received an order today with no warnings, so that change works.
Thanks very much.
Welcome. Looking over the code it would appear that the same change would be appropriate in the other locations where count($errors_object) is used.
Re: Square Payment Processing: myDEBUG file generated
I got the same error (but on line 355) running 1.5.6c and PHP 7.2
I made the amendment Doc suggested - adding $errors_object = array(); as Edadk said it resolved the issue - but has anyone feedback on the effect of changing the instances of count to
Code:
if (!empty($errors_object)) {
in square.php??
Cheers
Brinley