pay-now / paynow-magento2

Paynow plugin for Magento2
MIT License
2 stars 3 forks source link

Invalid argument supplied for foreach() in DigitalWalletConfigProvider #93

Open bartoszjuszczyk opened 7 months ago

bartoszjuszczyk commented 7 months ago

Magento version: 2.4.4-p2 PayNow version: 1.5.2

There is a line of code in the Paynow\PaymentGateway\Model\Ui\DigitalWalletConfigProvider that retrieves available digital wallets:

$paymentMethods = $this->paymentMethodsHelper->getDigitalWalletsPaymentMethods($currencyCode, $grandTotal);

It is followed by a foreach to which they are passed:

foreach ($paymentMethods as $paymentMethod) {
    if (in_array(PaymentMethodsToHide::PAYMENT_TYPE_TO_CONFIG_MAP[$paymentMethod['type'] ?? ''] ?? '', $this->configHelper->getPaymentMethodsToHide())) {
        $isActive = false;
        break;
    }
}

However, there is no check for null returned, causing an error to occur:

[2024-03-06T13:24:12.663499+00:00] main.CRITICAL: Exception: Warning: Invalid argument supplied for foreach() in /var/www/html/vendor/pay-now/paynow-magento2/Model/Ui/DigitalWalletConfigProvider.php on line 34 in /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61

This error can cause the checkout to display incorrectly or not to display at all.

bartoszjuszczyk commented 7 months ago

PR: https://github.com/pay-now/paynow-magento2/pull/94