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
106 stars 76 forks source link

PHP8.x Compatibility - Deprecated Functionality: strpos() #1224

Open samuelebau opened 9 months ago

samuelebau commented 9 months ago

What I Expected

I expected to refund an order paid with Amazon via API requests

What happened instead

Exception: Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/current/vendor/amzn/amazon-pay-magento-2-module/Plugin/OrderCurrencyComment.php on line 66 When I try to refund an order with different base_currency_code and order_currency_code

Steps to reproduce the issue

Your setup

samuelebau commented 9 months ago

I also resolved this issue with the patch below, please include this fix in the upcoming version.

diff --git a/vendor/amzn/amazon-pay-magento-2-module/Plugin/OrderCurrencyComment.php b/vendor/amzn/amazon-pay-magento-2-module/Plugin/OrderCurrencyComment.php
--- a/vendor/amzn/amazon-pay-magento-2-module/Plugin/OrderCurrencyComment.php
+++ b/vendor/amzn/amazon-pay-magento-2-module/Plugin/OrderCurrencyComment.php   (date 1698229883874)
@@ -61,9 +61,11 @@
         if ($subject->getMethod() == Config::CODE) {
             $order = $subject->getOrder();
             if ($order->getBaseCurrencyCode() != $order->getOrderCurrencyCode() &&
-                (($subject->getMessage() instanceof Phrase
-                && $subject->getMessage()->getText() == 'Canceled order online')
-                || strpos($subject->getTransactionId(), '-void') !== false)
+                (
+                    ($subject->getMessage() instanceof Phrase
+                    && $subject->getMessage()->getText() == 'Canceled order online')
+                    || strpos($subject->getTransactionId() ?? '', '-void') !== false
+                )
             ) {
                 return $result .' ['. $order->formatPriceTxt($subject->getAmountOrdered()) .']';
             }
sgabhart22 commented 9 months ago

Hello @samuelebau ,

I'm afraid I was unable to reproduce this issue on a clean 2.4.4-p4 EE instance running on PHP 8.1. The base currency was EUR and the order currency was SEK:

image

The underlying problem seems to be that, for some reason, there is no transaction ID associated with the Payment on your order(s) that need to be refunded. There shouldn't ever be a point where an Amazon Pay order has no transaction ID set on the Payment if it's been authorized, and especially if it's been captured; are there any customizations or third party extensions that might be affecting the way the Amazon Pay module records these transaction IDs?

Thanks, Spencer