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

Update known payment method logos

Open JustinElst opened this issue 1 year ago • 1 comments

Description

I created the following (quick and dirty) script to update the paymentmethod logo's in this package with the ones on https://checkoutshopper-live.adyen.com/checkoutshopper/images/logos/. The script is placed in 'updateLogos.php' in the root of the module and run with `php updateLogos.php'. There are allot of unused images in the 'view/base/web/images/logos' directory which need deleting or otherwise. Thats for another day.

<?php
$directory = 'view/base/web/images/logos';

// find logos from views dir
$logos = array_diff(scandir($directory), ['..', '.']);

// remove variant text and keep paymentgateway names
$logos = array_map(function ($logo) {
    $fileInfo = pathinfo($logo);
    $logo     = strtolower($fileInfo['filename']);
    $logo     = str_replace('_small', '', $logo);
    $logo     = str_replace('_grey', '', $logo);
    $logo     = str_replace('_tiny', '', $logo);

    return $logo;
}, $logos);

// make sure only one of each paymentgateway is used
$logos = array_unique($logos);
$logos = array_filter($logos);
sort($logos);

if (count($logos) === 0) {
    echo "No logos found, exiting." . PHP_EOL;
    exit();
}

echo count($logos) . " logos are found, processing.." . PHP_EOL;

// function to download logo's from adyen
function downloadLogo($logo, $directory, $format = "medium")
{
    $url = "https://checkoutshopper-live.adyen.com/checkoutshopper/images/logos/$format/$logo.png";

    $headers = get_headers($url);
    if (substr($headers[0], 9, 3) != "200") {
        echo "\tAdyen doesn't have the logo: $format/$logo.png" . PHP_EOL;

        return;
    }
    $fileInfo = pathinfo($url);
    if (file_put_contents($directory . DIRECTORY_SEPARATOR . 'new' . DIRECTORY_SEPARATOR . $fileInfo['filename'] . ($format === 'medium' ? '' : '_' . $format) . '.' . $fileInfo['extension'], file_get_contents($url))) {
        echo "\tLogo $format/$logo.png downloaded successfully" . PHP_EOL;
    }
    else {
        echo "\tLogo $format/$logo.png downloading failed." . PHP_EOL;
    }
}

// Make sure new logo dir is there.
if (!file_exists($directory . DIRECTORY_SEPARATOR . 'new')) {
    mkdir($directory . DIRECTORY_SEPARATOR . 'new', 0777, true);
}
foreach (array_unique($logos) as $value) {
    $value = strtolower($value);
    print(strtolower($value) . PHP_EOL);
    downloadLogo($value, $directory);
    downloadLogo($value, $directory, 'small');
}

Tested scenarios

Checked the downloaded images.

Fixed issue:

JustinElst avatar Jul 20 '22 08:07 JustinElst

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarcloud[bot] avatar Aug 22 '22 12:08 sonarcloud[bot]

@MrGekko Thanks for your pull contribution 👍

Regards, Jean Adyen

Morerice avatar Aug 22 '22 12:08 Morerice