Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful payment but order was not saved in Magento 2 due to Timeout communicating with Laybuy. #31

Open
LiamKarlMitchell opened this issue Sep 21, 2021 · 0 comments

Comments

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Sep 21, 2021

No order created in Magento 2 but payment made on Laybuys end.
You have no try catches or handling of errors!

So when there is a REST API timeout during a checkout such as in method laybuyConfirm used in execute method the inside code of your condition is not executed as everything bombs out, yet the payment was successfully captured on Laybuys end.

The default timeout for Zend Http Client is 10 seconds.
https://framework.zend.com/manual/1.12/en/zend.http.client.html

Maybe this could also be set higher as a work-around?
I'm not sure what caused it to not complete in that time but it happened.

Possible work-around, but really should have error handling.
Laybuy\Gateway\Http|\RestClient.php set a timeout.

    /**
     * Gets the HTTP client object.
     *
     * @return \Zend_Http_Client
     */
    final public static function getHttpClient()
    {
        if (!self::$_httpClient instanceof \Zend_Http_Client) {
            self::$_httpClient = new \Zend_Http_Client();
            self::$_httpClient->setConfig([
                'timeout' => 60
            ]);
        }

        return self::$_httpClient;
    }

Log lines.

[2021-09-17 23:30:08] Laybuy Logger.DEBUG: array (
  'Laybuy\\Laybuy\\Controller\\Payment\\Response::execute' => 'start',
)
[2021-09-17 23:30:18] Laybuy Logger.DEBUG: array (
  'process error ' => '#0 /var/www/html/vendor/magento/zendframework1/library/Zend/Http/Client/Adapter/Socket.php(329): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /var/www/html/vendor/magento/zendframework1/library/Zend/Http/Client.php(1089): Zend_Http_Client_Adapter_Socket->read()
#2 /var/www/html/app/code/Laybuy/Laybuy/Gateway/Http/RestClient.php(162): Zend_Http_Client->request(\'POST\')
#3 /var/www/html/app/code/Laybuy/Laybuy/Gateway/Http/RestClient.php(176): Laybuy\\Laybuy\\Gateway\\Http\\RestClient->_performPost(\'POST\', \'{"token":"REDACTED...\')
#4 /var/www/html/app/code/Laybuy/Laybuy/Gateway/Http/LaybuyClient.php(99): Laybuy\\Laybuy\\Gateway\\Http\\RestClient->restPost(\'/order/confirm\', \'{"token":"REDACTED...\')
#5 /var/www/html/app/code/Laybuy/Laybuy/Model/Laybuy.php(324): Laybuy\\Laybuy\\Gateway\\Http\\LaybuyClient->getLaybuyConfirmationOrderId(\'REDACTED...\')
#6 /var/www/html/app/code/Laybuy/Laybuy/Controller/Payment/Response.php(75): Laybuy\\Laybuy\\Model\\Laybuy->laybuyConfirm(\'REDACTED...\')
#7 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Laybuy\\Laybuy\\Controller\\Payment\\Response->execute()
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->___callParent(\'execute\', Array)
#9 /var/www/html/vendor/magento/framework/App/Action/Plugin/ActionFlagNoDispatchPlugin.php(51): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->Magento\\Framework\\Interception\\{closure}()
#10 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\\Framework\\App\\Action\\Plugin\\ActionFlagNoDispatchPlugin->aroundExecute(Object(Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor), Object($#11 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->Magento\\Framework\\Interception\\{closure}()
#12 /var/www/html/generated/code/Laybuy/Laybuy/Controller/Payment/Response/Interceptor.php(23): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->___callPlugins(\'execute\', Array, Array)
#13 /var/www/html/vendor/magento/framework/App/Action/Action.php(111): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->execute()
#14 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Framework\\App\\Action\\Action->dispatch(Object(Magento\\Framework\\App\\Request\\Http))
#15 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->___callParent(\'dispatch\', Array)
#16 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))
#17 /var/www/html/generated/code/Laybuy/Laybuy/Controller/Payment/Response/Interceptor.php(32): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->___callPlugins(\'dispatch\', Array, Array)
#18 /var/www/html/vendor/magento/framework/App/FrontController.php(186): Laybuy\\Laybuy\\Controller\\Payment\\Response\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))
#19 /var/www/html/vendor/magento/framework/App/FrontController.php(118): Magento\\Framework\\App\\FrontController->processRequest(Object(Magento\\Framework\\App\\Request\\Http), Object(Laybuy\\Laybuy\\Controller\\Payment\\Response\\Inte$#20 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Framework\\App\\FrontController->dispatch(Object(Magento\\Framework\\App\\Request\\Http))
#21 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Framework\\App\\FrontController\\Interceptor->___callParent(\'dispatch\', Array)
#22 /var/www/html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(99): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Req$#23 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\\Store\\App\\FrontController\\Plugin\\RequestPreprocessor->aroundDispatch(Object(Magento\\Framework\\App\\FrontController\\Interceptor), Object(Closur$#24 /var/www/html/app/code/Amasty/InvisibleCaptcha/Plugin/Predispatch.php(93): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))
#25 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Amasty\\InvisibleCaptcha\\Plugin\\Predispatch->aroundDispatch(Object(Magento\\Framework\\App\\FrontController\\Interceptor), Object(Closure), Object(Magento\\$#26 /var/www/html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(71): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Reque$#27 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\\PageCache\\Model\\App\\FrontController\\BuiltinPlugin->aroundDispatch(Object(Magento\\Framework\\App\\FrontController\\Interceptor), Object(Closure),$#28 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))
#29 /var/www/html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins(\'dispatch\', Array, NULL)
#30 /var/www/html/vendor/magento/framework/App/Http.php(116): Magento\\Framework\\App\\FrontController\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))
#31 /var/www/html/vendor/magento/framework/App/Bootstrap.php(263): Magento\\Framework\\App\\Http->launch()
#32 /var/www/html/pub/index.php(29): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))
#33 {main}',
)
[2021-09-17 23:30:19] Laybuy Logger.DEBUG: array (
  'Laybuy\\Laybuy\\Model\\Laybuy::laybuyCancelLAYBUY CANCEL STATUS:' => false,
  'TOKEN' => 'REDACTED',
)
[2021-09-17 23:30:19] Laybuy Logger.DEBUG: array (
  'method' => 'Laybuy\\Laybuy\\Gateway\\Http\\LaybuyClient::checkMerchantOrder',
  'Response' =>
  (object) array(
     'result' => 'ERROR',
     'error' => 'Order not found',
  ),
)
[2021-09-17 23:30:19] Laybuy Logger.DEBUG: array (
  'Laybuy\\Laybuy\\Model\\Laybuy::laybuyCheckOrderLAYBUY ORDER STATUS:' => false,
  'MERCHANT REFERENCE' => '000007359',
)
[2021-09-17 23:31:19] Laybuy Logger.DEBUG: array (
  'Laybuy\\Laybuy\\Controller\\Payment\\Process::execute' => 'start',
)
[2021-09-17 23:31:19] Laybuy Logger.DEBUG: array (
  'Laybuy\\Laybuy\\Model\\Laybuy::createLaybuyOrder CREATED ORDER' =>
  (object) array(
     'amount' => '279.90',
     'currency' => 'NZD',
     'returnUrl' => 'https://REDACTED/laybuy/payment/response/',
     'merchantReference' => '000007359',
     'customer' =>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant