Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2009
    Location
    North Idaho, USA
    Posts
    2,008
    Plugin Contributions
    1

    Default 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.
    Rick
    RixStix (dot) com
    aka: ChainWeavers (dot) com

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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();
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Nov 2008
    Posts
    192
    Plugin Contributions
    0

    Default 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

  4. #4
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default 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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Square Payment Processing: myDEBUG file generated

    Quote Originally Posted by DrByte View Post
    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Nov 2008
    Posts
    192
    Plugin Contributions
    0

    Default 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.

  7. #7
    Join Date
    Nov 2008
    Posts
    192
    Plugin Contributions
    0

    Default Re: Square Payment Processing: myDEBUG file generated

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

    Thanks very much.

  8. #8
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Square Payment Processing: myDEBUG file generated

    Quote Originally Posted by edadk View Post
    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Aug 2004
    Location
    Newport, Wales
    Posts
    283
    Plugin Contributions
    0

    Default 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

 

 

Similar Threads

  1. Square Payment Module for Zen Cart [Support Thread]
    By DrByte in forum Addon Payment Modules
    Replies: 749
    Last Post: 5 Sep 2023, 01:16 AM
  2. Replies: 5
    Last Post: 4 Sep 2019, 05:10 PM
  3. Is there a Square / SquareUp payment module?
    By thatsamore in forum Addon Payment Modules
    Replies: 48
    Last Post: 25 Jul 2017, 12:09 AM
  4. Replies: 4
    Last Post: 19 Jan 2013, 05:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR