Skip to content

Commit

Permalink
[ECP-9240] Refactor the process to download the Apple Pay domain asso…
Browse files Browse the repository at this point in the history
…ciation file, and change the misleading UI field label (#2818)

* [ECP-9240] Refactor download process

* [ECP-9240] Write unit tests for the controller

* [ECP-9240] Formatting

* [ECP-9240] Write unit tests

* [ECP-9240] Convert string label to phrase for localisation

* [ECP-9240] Start using CDN to download domain association file

---------

Co-authored-by: Can Demiralp <[email protected]>
  • Loading branch information
candemiralp and Can Demiralp authored Dec 24, 2024
1 parent 9270f00 commit 09dfcf3
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 170 deletions.
158 changes: 0 additions & 158 deletions Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Controller\Adminhtml\Configuration;

use Adyen\Payment\Logger\AdyenLogger;
use Exception;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action;
use Magento\Framework\Filesystem\Io\File;

class DownloadApplePayDomainAssociationFile extends Action
{
const FILE_NAME = 'apple-developer-merchantid-domain-association';
const REMOTE_PATH = 'https://bae81f955b.cdn.adyen.com/checkoutshopper/.well-known';
const PUB_PATH = 'pub';
const WELL_KNOWN_PATH = '.well-known';

public function __construct(
private readonly Context $context,
private readonly DirectoryList $directoryList,
private readonly File $fileIo,
private readonly AdyenLogger $adyenLogger
) {
parent::__construct($context);
}

/**
* @return ResultInterface|ResponseInterface
* @throws FileSystemException
*/
public function execute(): ResultInterface|ResponseInterface
{
$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$redirect->setUrl($this->_redirect->getRefererUrl());

try {
$pubPath = $this->directoryList->getPath(self::PUB_PATH);

$this->fileIo->checkAndCreateFolder(
sprintf("%s/%s", $pubPath, self::WELL_KNOWN_PATH),
0700
);

$source = sprintf("%s/%s", self::REMOTE_PATH, self::FILE_NAME);
$destination = sprintf("%s/%s/%s", $pubPath, self::WELL_KNOWN_PATH, self::FILE_NAME);

$file = $this->fileIo->read($source, $destination);

if (!$file) {
$errorMessage =
__('Error while downloading Apple Pay domain association file from the remote source!');
$this->adyenLogger->error(sprintf("%s %s", $errorMessage, $source));
$this->messageManager->addErrorMessage($errorMessage);
} else {
$successMessage = __('Apple Pay domain association file has been downloaded successfully!');
$this->adyenLogger->addAdyenDebug($successMessage);
$this->messageManager->addSuccessMessage($successMessage);
}
} catch (Exception $e) {
$errorMessage =
__('Unknown error while downloading Apple Pay domain association file!');
$this->adyenLogger->error(sprintf("%s %s", $errorMessage, $e->getMessage()));
$this->messageManager->addErrorMessage($errorMessage);
}

return $redirect;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
use Magento\Backend\Helper\Data;
use Magento\Framework\Data\Form\Element\AbstractElement;

class ApplepayCertificateButton extends Field
class ApplePayDomainAssociationFileButton extends Field
{
const APPLEPAY_BUTTON = 'Adyen_Payment::config/applepay_button.phtml';
const APPLEPAY_BUTTON = 'Adyen_Payment::config/applepay_domain_association_file_button.phtml';

/**
* @var Data
*/
protected $backendHelper;
protected Data $backendHelper;

/**
* @param Context $context
Expand All @@ -40,9 +40,9 @@ public function __construct(
}

/**
* @return $this|ApplepayCertificateButton
* @return $this|ApplePayDomainAssociationFileButton
*/
protected function _prepareLayout()
protected function _prepareLayout(): ApplePayDomainAssociationFileButton|static
{
parent::_prepareLayout();

Expand All @@ -57,7 +57,7 @@ protected function _prepareLayout()
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
protected function _getElementHtml(AbstractElement $element): string
{
$this->addData([
'id' => 'addbutton_button',
Expand All @@ -73,6 +73,6 @@ protected function _getElementHtml(AbstractElement $element)
*/
public function getActionUrl(): string
{
return $this->backendHelper->getUrl("adyen/configuration/DownloadApplePayCertificate");
return $this->backendHelper->getUrl("adyen/configuration/DownloadApplePayDomainAssociationFile");
}
}
Loading

0 comments on commit 09dfcf3

Please sign in to comment.