Zen Cart Logo
Forums / Upgrading to 1.5.x / Square Payment Processing: myDEBUG file generated

Square Payment Processing: myDEBUG file generated

Views: 13,464

Results 1 to 9 of 9
11 Jan 2019, 12:23 AM
#1
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

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

[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.
11 Jan 2019, 1:27 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

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:

        $body         = new \SquareConnect\Model\ZenCartChargeRequest($request_body);
[B]        $errors_object = array();
[/B]
        try {
            $result        = $api_instance->charge($location->id, $body);
            $errors_object = $result->getErrors();
10 Sep 2019, 4:51 PM
#3
edadk avatar

edadk

Zen Follower

Join Date:
Nov 2008
Posts:
191
Plugin Contributions:
0

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

11 Sep 2019, 10:16 AM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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:

if (count($errors_object)) {

To:

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:

if (!empty($errors_object) && is_array($errors_object)) {

The response null is not countable which would cause the response received.

11 Sep 2019, 10:25 AM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Square Payment Processing: myDEBUG file generated

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:

    $body         = new \SquareConnect\Model\ZenCartChargeRequest($request_body);

[B] $errors_object = array();
[/B]

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.
12 Sep 2019, 4:28 AM
#6
edadk avatar

edadk

Zen Follower

Join Date:
Nov 2008
Posts:
191
Plugin Contributions:
0

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.

12 Sep 2019, 8:15 PM
#7
edadk avatar

edadk

Zen Follower

Join Date:
Nov 2008
Posts:
191
Plugin Contributions:
0

Re: Square Payment Processing: myDEBUG file generated

Received an order today with no warnings, so that change works.

Thanks very much.

12 Sep 2019, 8:22 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Square Payment Processing: myDEBUG file generated

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.

7 Jan 2020, 1:49 PM
#9
welshop_com avatar

welshop_com

Zen Follower

Join Date:
Aug 2004
Location:
Newport, Wales
Posts:
262
Plugin Contributions:
0

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 ```
if (!empty($errors_object)) {


Cheers
Brinley