adyen-magento2 icon indicating copy to clipboard operation
adyen-magento2 copied to clipboard

[PW-8362] Missing card icons causes entire checkout to not render (with patch)

Open maaarghk opened this issue 1 year ago • 1 comments

An uncaught exception in the middle of generating checkoutConfig causes the block to not render and therefore the checkout frontend displays a blank screen. Adyen causes an exception like this by trying to load icon names dynamically. Missing icons include applepay, googlepay and sub-variants like mc_googlepay, mc_applepay, visa_googlepay, etc. Semi-related to another issue I raised https://github.com/Adyen/adyen-php-api-library/issues/438 - I would suggest a proper fix for this involves a CI job which for each build pulls a list of all possible card types directly from the Adyen API and checks these files / functions, instead of waiting for users who use those payment methods to get in touch!

Magento\Framework\View\Asset\File\NotFoundException: Unable to resolve the source file for Adyen_Payment::images/logos/mc_googlepay_small.png'
#0 vendor/adyen/module-payment/Helper/Data.php(1660): Magento\Framework\View\Asset\File->getSourceFile()
#1 vendor/adyen/module-payment/Model/Ui/PaymentMethodUiComponentProvider.php(68): Adyen\Payment\Helper\Data->getVariantIcon()

I suppose it will be practically quite difficult for you to cut a release every time the adyen backend implements a new payment type, and users might not upgrade anyway; breaking the checkout is a bad way to handle this. Here's a fix, with apologies that I don't have time to mess about cloning and applying it to raise a PR properly:

--- Helper/Data.php
+++ Helper/Data.php
@@ -34,6 +34,7 @@
 use Magento\Framework\Locale\ResolverInterface;
 use Magento\Framework\Module\ModuleListInterface;
 use Magento\Framework\Serialize\SerializerInterface;
+use Magento\Framework\View\Asset\File\NotFoundException;
 use Magento\Framework\View\Asset\Repository;
 use Magento\Framework\View\Asset\Source;
 use Magento\Sales\Api\OrderManagementInterface;
@@ -1656,7 +1657,13 @@
      */
     public function getVariantIcon($variant)
     {
-        $asset = $this->createAsset(sprintf("Adyen_Payment::images/logos/%s_small.png", $variant));
-        list($width, $height) = getimagesize($asset->getSourceFile());
+        try {
+            $asset = $this->createAsset(sprintf("Adyen_Payment::images/logos/%s_small.png", $variant));
+            $sourceFile = $asset->getSourceFile();
+        } catch (NotFoundException $exception) {
+            $asset = $this->createAsset("Adyen_Payment::images/logos/unknown_small.png");
+            $sourceFile = $asset->getSourceFile();
+        }
+        list($width, $height) = getimagesize($sourceFile);
         $icon = [
             'url' => $asset->getUrl(),

maaarghk avatar Mar 07 '23 14:03 maaarghk