amzn / amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
https://amzn.github.io/amazon-payments-magento-2-plugin/
Apache License 2.0
109 stars 77 forks source link

Undefined index 'charge_permission_id' #1126

Closed ccsliinc closed 2 years ago

ccsliinc commented 2 years ago

Async Error log was full of these.

amazonAsyncIpnLogger.ERROR: Exception: Notice: Undefined index: charge_permission_id in /var/www/shop/prod/vendor/amzn/amazon-pay-magento-2-module/Model/AsyncManagement/Charge.php on line 213 in /var/www/shop/prod/vendor/magento/framework/App/ErrorHandler.php:61 Stack trace:

0 /var/www/shop/prod/vendor/amzn/amazon-pay-magento-2-module/Model/AsyncManagement/Charge.php(213): Magento\Framework\App\ErrorHandler->handler()

1 /var/www/shop/prod/vendor/amzn/amazon-pay-magento-2-module/Model/AsyncManagement/Charge.php(167): Amazon\Pay\Model\AsyncManagement\Charge->decline()

2 /var/www/shop/prod/vendor/amzn/amazon-pay-magento-2-module/Model/AsyncUpdater.php(79): Amazon\Pay\Model\AsyncManagement\Charge->processStateChange()

3 /var/www/shop/prod/vendor/amzn/amazon-pay-magento-2-module/Cron/ProcessAsync.php(71): Amazon\Pay\Model\AsyncUpdater->processPending()

4 [internal function]: Amazon\Pay\Cron\ProcessAsync->execute()

5 /var/www/shop/prod/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php(368): call_user_func_array()

6 /var/www/shop/prod/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php(879): Magento\Cron\Observer\ProcessCronQueueObserver->_runJob()

7 /var/www/shop/prod/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php(840): Magento\Cron\Observer\ProcessCronQueueObserver->tryRunJob()

8 /var/www/shop/prod/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php(280): Magento\Cron\Observer\ProcessCronQueueObserver->processPendingJobs()

9 /var/www/shop/prod/vendor/magento/framework/Event/Invoker/InvokerDefault.php(88): Magento\Cron\Observer\ProcessCronQueueObserver->execute()

10 /var/www/shop/prod/vendor/magento/framework/Event/Invoker/InvokerDefault.php(74): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod()

11 /var/www/shop/prod/vendor/magento/framework/Event/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch()

12 /var/www/shop/prod/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch()

13 /var/www/shop/prod/vendor/magento/framework/App/Cron.php(86): Magento\Framework\Event\Manager\Proxy->dispatch()

14 /var/www/shop/prod/vendor/magento/module-cron/Console/Command/CronCommand.php(117): Magento\Framework\App\Cron->launch()

15 /var/www/shop/prod/vendor/symfony/console/Command/Command.php(255): Magento\Cron\Console\Command\CronCommand->execute()

16 /var/www/shop/prod/vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run()

17 /var/www/shop/prod/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Cron\Console\Command\CronCommand\Interceptor->___callParent()

18 /var/www/shop/prod/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Cron\Console\Command\CronCommand\Interceptor->Magento\Framework\Interception{closure}()

19 /var/www/shop/prod/generated/code/Magento/Cron/Console/Command/CronCommand/Interceptor.php(77): Magento\Cron\Console\Command\CronCommand\Interceptor->___callPlugins()

20 /var/www/shop/prod/vendor/symfony/console/Application.php(1009): Magento\Cron\Console\Command\CronCommand\Interceptor->run()

21 /var/www/shop/prod/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()

22 /var/www/shop/prod/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun()

23 /var/www/shop/prod/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun()

24 /var/www/shop/prod/bin/magento(23): Symfony\Component\Console\Application->run()

25 {main} [] []

Fixes # .

Additional details about this PR

sgabhart22 commented 2 years ago

Hello @ccsliinc ,

The proposed fix seems relatively harmless, it would certainly quiet down your error log. But I wonder if this isn't just masking the problem of why your store seems to have many orders getting declined that were paid with AP? If the call to completeCheckoutSession was completed successfully, the order should have a chargePermissionId set in the additional information.

ccsliinc commented 2 years ago

I without a doubt understand and it is something i am working on. Shouldn't there be a check in place regardless as that chargePermissionId could be missing?

sgabhart22 commented 2 years ago

@ccsliinc I don't think it hurts to have that check in place, but in the case that there isn't a chargePermissionId associated with an order, we would probably still want to log something to either the async error log or the paywithamazon log in order for the merchant/developer to see that something funny happened with that order. It would look much nicer than the bloated Magento stack trace and be more informative of the actual issue. Also could likely skip the call to closeChargePermission in that case, since it wouldn't be doing much with an empty chargePermissionId.

sgabhart22 commented 2 years ago

Hello again @ccsliinc ,

I expanded on your PR just a bit to include an additional logging statement in the case there is no charge permission ID set on a declined order. I cherry picked your commit to give credit where it's due, and this will likely be included in some form in an upcoming patch/minor release. Thanks again for the contribution!

Spencer

ccsliinc commented 2 years ago

Thank you, I left the message in my inbox to do that, but work has been crazy. I really appreciate it and glad to help.