PAYONE-GmbH / magento-1

PAYONE Payment Extension for Magento 1
22 stars 41 forks source link

Problem with jsonDecode on empty customerData (PHP7) #37

Closed template-provider closed 7 years ago

template-provider commented 7 years ago

Hi, we are using the Payone Extension 3.7.0 with Magento 1.9.3.1. We are having a problem with the onepage checkout. After the 3rd step(shipping), the ajax call for the payment infos throws an error. The payone extension want to json_decode an empty string and the Zend_Json throws the error. Class: Payone_Core_Model_Domain_Customer

    /**
     * @param string $key
     * @return array
     */
    public function getCustomerData($key = null)
    {
        $plain_customer_data = Mage::helper('core')->decrypt($this->customer_data);
//        $plain_customer_data = $this->customer_data;
        $result = Mage::helper('core')->jsonDecode($plain_customer_data);
        if(!is_null($key) && is_array($result) && isset($result[$key])) {
            return $result[$key];
        }

        return $result;
    }

The "$this->customer_data" is empty in our case. I think there should be an "if" around the jsonDecode. The problem is with php7 compat: https://3v4l.org/9Bgcc The json_last_error() reports for an empty string a 4 .... php 5.6 and hhvm a 0.

Zend Json Class

            // php >= 5.3
            **} elseif (($jsonLastErr = json_last_error()) != JSON_ERROR_NONE) {**
                #require_once 'Zend/Json/Exception.php';
                switch ($jsonLastErr) {
                    case JSON_ERROR_DEPTH:
                        throw new Zend_Json_Exception('Decoding failed: Maximum stack depth exceeded');
                    case JSON_ERROR_CTRL_CHAR:
                        throw new Zend_Json_Exception('Decoding failed: Unexpected control character found');
                    case JSON_ERROR_SYNTAX:
                        throw new Zend_Json_Exception('Decoding failed: Syntax error');
                    default:
                        throw new Zend_Json_Exception('Decoding failed');
                }
            }

Greetings Jan

fjbender commented 7 years ago

Hi Jan,

while I understand the point, I simply cannot reproduce it on my machine (although I'm pretty sure it can't work... :D).

Which of the AJAX calls is failing exactly, so I can debug it?

Thanks Florian

template-provider commented 7 years ago

Hi, it is the saveShipping ajax call in the onepage checkout: example: checkout/onepage/saveShippingMethod/

Did u try to reproduce it with php7? But like u said: The code speaks for itself ;-)

Greetings Jan

fjbender commented 7 years ago

Now I was able to reproduce:

a:5:{i:0;s:29:"Decoding failed: Syntax error";i:1;s:3694:"#0 /var/www/html/magento1/current/app/code/core/Mage/Core/Helper/Data.php(659): Zend_Json::decode('', 1)
#1 /var/www/html/magento1/current/app/code/community/Payone/Core/Model/Domain/Customer.php(99): Mage_Core_Helper_Data->jsonDecode('')
#2 /var/www/html/magento1/current/app/code/community/Payone/Core/Block/Payment/Method/Form/Abstract.php(294): Payone_Core_Model_Domain_Customer->getCustomerData('cc_owner')
#3 /var/www/html/magento1/current/app/code/community/Payone/Core/Block/Payment/Method/Form/Creditcard.php(53): Payone_Core_Block_Payment_Method_Form_Abstract->getSavedCustomerData('cc_owner')
#4 /var/www/html/magento1/current/app/design/frontend/base/default/template/payone/core/payment/method/form/creditcard.phtml(39): Payone_Core_Block_Payment_Method_Form_Creditcard->getBillingName()
#5 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#6 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/base/d...')
#7 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#8 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template->_toHtml()
#9 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Abstract.php(641): Mage_Core_Block_Abstract->toHtml()
#10 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Abstract.php(585): Mage_Core_Block_Abstract->_getChildHtml('payment.method....', true)
#11 /var/www/html/magento1/current/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php(72): Mage_Core_Block_Abstract->getChildHtml('payment.method....')
#12 /var/www/html/magento1/current/app/design/frontend/base/default/template/checkout/onepage/payment/methods.phtml(56): Mage_Checkout_Block_Onepage_Payment_Methods->getPaymentMethodFormHtml(Object(Payone_Core_Model_Payment_Method_Creditcard))
#13 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#14 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/base/d...')
#15 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#16 /var/www/html/magento1/current/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template->_toHtml()
#17 /var/www/html/magento1/current/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#18 /var/www/html/magento1/current/app/code/core/Mage/Checkout/controllers/OnepageController.php(143): Mage_Core_Model_Layout->getOutput()
#19 /var/www/html/magento1/current/app/code/core/Mage/Checkout/controllers/OnepageController.php(449): Mage_Checkout_OnepageController->_getPaymentMethodsHtml()
#20 /var/www/html/magento1/current/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_OnepageController->saveShippingMethodAction()
#21 /var/www/html/magento1/current/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('saveShippingMet...')
#22 /var/www/html/magento1/current/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#23 /var/www/html/magento1/current/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#24 /var/www/html/magento1/current/app/Mage.php(691): Mage_Core_Model_App->run(Array)
#25 /var/www/html/magento1/current/index.php(83): Mage::run('', 'store')
#26 {main}";s:3:"url";s:54:"/magento1/current/checkout/onepage/saveShippingMethod/";s:11:"script_name";s:27:"/magento1/current/index.php";s:4:"skin";s:7:"default";}

Key was to make sure that actually there was no data for this customer in the payone_cusomer table...

I think it would be the easiest and fastest solution if you just propose a pull request :)

Best Florian