MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Refund error RefundResponseHandler::handle #58

Closed davekleijn closed 10 months ago

davekleijn commented 10 months ago

Describe the bug When creating a refund in the backend, we get an error message.

To Reproduce Steps to reproduce the behavior:

  1. Go to an existing invoice
  2. Click on 'Credit memo'
  3. Click on 'Refund'
  4. Error visible: "An error has happened during application run. See exception log for details."

Expected behavior Credit memo is created.

Versions Magento: 2.4.6-p2 Module version: 3.1.2

[2023-09-01T10:08:31.164481+00:00] main.CRITICAL: TypeError: MultiSafepay\ConnectCore\Gateway\Response\RefundResponseHandler::handle(): Argument #2 ($response) must be of type array, null given, called in /data/web/magento2_staging/vendor/magento/module-payment/Gateway/Command/GatewayCommand.php on line 117 and defined in /data/web/magento2_staging/vendor/multisafepay/magento2-core/Gateway/Response/RefundResponseHandler.php:44
Stack trace:
#0 /data/web/magento2_staging/vendor/magento/module-payment/Gateway/Command/GatewayCommand.php(117): MultiSafepay\ConnectCore\Gateway\Response\RefundResponseHandler->handle(Array, NULL)
#1 /data/web/magento2_staging/vendor/magento/module-payment/Model/Method/Adapter.php(549): Magento\Payment\Gateway\Command\GatewayCommand->execute(Array)
#2 /data/web/magento2_staging/vendor/magento/module-payment/Model/Method/Adapter.php(475): Magento\Payment\Model\Method\Adapter->executeCommand('...', Array)
#3 /data/web/magento2_staging/vendor/magento/module-sales/Model/Order/Payment.php(699): Magento\Payment\Model\Method\Adapter->refund(Object(Magento\Sales\Model\Order\Payment\Interceptor), '...')
#4 /data/web/magento2_staging/vendor/magento/module-sales/Model/Order/Creditmemo/RefundOperation.php(118): Magento\Sales\Model\Order\Payment->refund(Object(Magento\Sales\Model\Order\Creditmemo))
#5 /data/web/magento2_staging/vendor/magento/module-sales/Model/Order/RefundAdapter.php(39): Magento\Sales\Model\Order\Creditmemo\RefundOperation->execute(Object(Magento\Sales\Model\Order\Creditmemo), Object(Magento\Sales\Model\Order\Interceptor), true)
#6 /data/web/magento2_staging/vendor/magento/module-sales/Model/Service/CreditmemoService.php(166): Magento\Sales\Model\Order\RefundAdapter->refund(Object(Magento\Sales\Model\Order\Creditmemo), Object(Magento\Sales\Model\Order\Interceptor), true)
#7 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Sales\Model\Service\CreditmemoService->refund(Object(Magento\Sales\Model\Order\Creditmemo), false)
#8 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sales\Model\Service\CreditmemoService\Interceptor->___callParent('...', Array)
#9 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sales\Model\Service\CreditmemoService\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Sales\Model\Order\Creditmemo), false)
#10 /data/web/magento2_staging/generated/code/Magento/Sales/Model/Service/CreditmemoService/Interceptor.php(23): Magento\Sales\Model\Service\CreditmemoService\Interceptor->___callPlugins('...', Array, Array)
#11 /data/web/magento2_staging/vendor/magento/module-sales/Controller/Adminhtml/Order/Creditmemo/Save.php(119): Magento\Sales\Model\Service\CreditmemoService\Interceptor->refund(Object(Magento\Sales\Model\Order\Creditmemo), false)
#12 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save->execute()
#13 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->___callParent('...', Array)
#14 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->Magento\Framework\Interception\{closure}()
#15 /data/web/magento2_staging/generated/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save/Interceptor.php(23): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->___callPlugins('...', Array, Array)
#16 /data/web/magento2_staging/vendor/magento/framework/App/Action/Action.php(111): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->execute()
#17 /data/web/magento2_staging/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#18 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#19 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->___callParent('...', Array)
#20 /data/web/magento2_staging/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#21 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#22 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 /data/web/magento2_staging/generated/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save/Interceptor.php(32): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->___callPlugins('...', Array, Array)
#24 /data/web/magento2_staging/vendor/magento/framework/App/FrontController.php(245): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#25 /data/web/magento2_staging/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse(Object(Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor), Object(Magento\Framework\App\Request\Http))
#26 /data/web/magento2_staging/vendor/magento/framework/App/FrontController.php(146): Magento\Framework\App\FrontController->processRequest(Object(Magento\Framework\App\Request\Http), Object(Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save\Interceptor))
#27 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#28 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('...', Array)
#29 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#30 /data/web/magento2_staging/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins('...', Array, Array)
#31 /data/web/magento2_staging/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#32 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Http->launch()
#33 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\Http\Interceptor->___callParent('...', Array)
#34 /data/web/magento2_staging/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#35 /data/web/magento2_staging/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http\Interceptor->___callPlugins('...', Array, Array)
#36 /data/web/magento2_staging/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#37 /data/web/magento2_staging/pub/index.php(30): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#38 {main} {"exception":"[object] (TypeError(code: 0): MultiSafepay\\ConnectCore\\Gateway\\Response\\RefundResponseHandler::handle(): Argument #2 ($response) must be of type array, null given, called in /data/web/magento2_staging/vendor/magento/module-payment/Gateway/Command/GatewayCommand.php on line 117 at /data/web/magento2_staging/vendor/multisafepay/magento2-core/Gateway/Response/RefundResponseHandler.php:44)"} []
vinodsowdagar commented 10 months ago

Hi @Davie82 ,

Thank you for the report.

I've tried reproducing the issue, but couldn't. There most likely was an issue with processing the refund at MultiSafepay and one of the following exceptions might have occured: InvalidApiKeyException, ApiException or ClientExceptionInterface. We are logging the exception in the var/log/multisafepay.log as an error, so maybe you could look into that and find out what happened. The multisafepay.log can also be downloaded through the Magento backend if server access is not available. See instructions here: https://docs.multisafepay.com/docs/magento-2#logs

Currently I have a change in review where we are changing this to throw a CouldNotRefundException instead with an encapsulation of the original exception message to show as the visible error, so it will be more clear what actually happened, instead of it showing "An error has happened during application run. See exception log for details."

When this change has been released, I will let you know.

davekleijn commented 10 months ago

Thank you for the information. I will do some further debugging.

vinodsowdagar commented 10 months ago

Hi @Davie82 ,

We've made a new release where we changed the error message when a refund fails. https://github.com/MultiSafepay/magento2/releases/tag/3.1.3

It should be more clear now why a refund has failed. If you get an error which you do not understand, please contact the integration team at integration@multisafepay.com so they can help you out.

For now I am closing this issue.