From 5a142d3ee961e332d3e5b42d067408f1f2106576 Mon Sep 17 00:00:00 2001
From: Can Demiralp
Date: Wed, 13 Nov 2024 17:08:34 +0100
Subject: [PATCH] [ECP-9174] Rename the button
---
.../DownloadApplePayCertificate.php | 61 ++++++++-----------
.../adyen_alternative_payment_methods.xml | 2 +-
.../templates/config/applepay_button.phtml | 2 +-
3 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php b/Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php
index 5af0c4dce..a7ef97358 100644
--- a/Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php
+++ b/Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php
@@ -12,13 +12,8 @@
namespace Adyen\Payment\Controller\Adminhtml\Configuration;
use Adyen\AdyenException;
-use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
-use Magento\Framework\App\ResponseInterface;
-use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
-use Magento\Framework\Exception\FileSystemException;
-use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
@@ -35,29 +30,25 @@ class DownloadApplePayCertificate extends Action
const MAX_RATIO = 5;
const FILE_NAME = 'apple-developer-merchantid-domain-association';
const APPLEPAY_CERTIFICATE_URL = 'https://docs.adyen.com/payment-methods/apple-pay/web-component/apple-developer-merchantid-domain-association-2024.zip';
- private $directoryList;
- private $fileIo;
- private $adyenLogger;
+
+ private DirectoryList $directoryList;
+ private File $fileIo;
+ private AdyenLogger $adyenLogger;
public function __construct(
- Context $context,
+ Context $context,
DirectoryList $directoryList,
- File $fileIo,
- AdyenLogger $adyenLogger
- )
- {
+ File $fileIo,
+ AdyenLogger $adyenLogger
+ ) {
parent::__construct($context);
+
$this->directoryList = $directoryList;
$this->fileIo = $fileIo;
$this->adyenLogger = $adyenLogger;
}
- /**
- * @return ResponseInterface|Redirect|Redirect&ResultInterface|ResultInterface
- * @throws FileSystemException
- * @throws LocalizedExceptionff
- */
- public function execute()
+ public function execute(): ResultInterface
{
$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$redirect->setUrl($this->_redirect->getRefererUrl());
@@ -66,23 +57,19 @@ public function execute()
$directoryName = '.well-known';
$wellknownPath = $pubPath . '/' . $directoryName;
- $applepayPath = $wellknownPath . '/' . self::FILE_NAME;
-
$applepayUrl = self::APPLEPAY_CERTIFICATE_URL;
try {
- if ($this->fileIo->checkAndCreateFolder($wellknownPath, 0700)) {
- $this->downloadAndUnzip($applepayUrl, $wellknownPath);
- } else {
- $this->fileIo->chmod($wellknownPath, 0770);
- if (!$this->fileIo->fileExists($applepayPath)) {
- $this->downloadAndUnzip($applepayUrl, $wellknownPath);
- }
- }
+ $this->fileIo->checkAndCreateFolder($wellknownPath, 0700);
+ $this->downloadAndUnzip($applepayUrl, $wellknownPath);
+
+ $this->messageManager->addSuccessMessage(
+ __('Apple Pay domain association file has been successfully downloaded!')
+ );
} catch (Exception $e) {
- $errormessage = 'Failed to download the ApplePay certificate, please do so manually';
- $this->adyenLogger->addAdyenWarning($errormessage);
- $this->messageManager->addErrorMessage($errormessage);
+ $errorMessage = 'Failed to download the ApplePay domain association file!';
+ $this->adyenLogger->error(sprintf("%s %s", $errorMessage, $e->getMessage()));
+ $this->messageManager->addErrorMessage(__($errorMessage));
}
return $redirect;
@@ -92,9 +79,9 @@ public function execute()
* @param string $applepayUrl
* @param string $applepayPath
* @return void
- * @throws LocalizedException
+ * @throws AdyenException
*/
- private function downloadAndUnzip(string $applepayUrl, string $applepayPath)
+ private function downloadAndUnzip(string $applepayUrl, string $applepayPath): void
{
$tmpPath = tempnam(sys_get_temp_dir(), self::FILE_NAME);
file_put_contents($tmpPath, file_get_contents($applepayUrl));
@@ -112,12 +99,12 @@ private function downloadAndUnzip(string $applepayUrl, string $applepayPath)
$stats = $zip->statIndex($i);
// Prevent ZipSlip path traversal (S6096)
- if (strpos($filename, '../') !== false ||
- substr($filename, 0, 1) === '/') {
+ if (str_contains($filename, '../') ||
+ str_starts_with($filename, '/')) {
throw new AdyenException('The zip file is trying to ZipSlip please check the file');
}
- if (substr($filename, -1) !== '/') {
+ if (!str_ends_with($filename, '/')) {
$fileCount++;
if ($fileCount > 10) {
// Reached max. number of files
diff --git a/etc/adminhtml/system/adyen_alternative_payment_methods.xml b/etc/adminhtml/system/adyen_alternative_payment_methods.xml
index 21dcfb7a8..66a4dfbff 100755
--- a/etc/adminhtml/system/adyen_alternative_payment_methods.xml
+++ b/etc/adminhtml/system/adyen_alternative_payment_methods.xml
@@ -19,7 +19,7 @@
Set up additional payment methods to accept online and in-app payments and eliminate the need for traditional card-based transactions.
]]>
-
+
Adyen\Payment\Model\Config\Adminhtml\ApplepayCertificateButton
diff --git a/view/adminhtml/templates/config/applepay_button.phtml b/view/adminhtml/templates/config/applepay_button.phtml
index e57195c9f..1dd12f65e 100644
--- a/view/adminhtml/templates/config/applepay_button.phtml
+++ b/view/adminhtml/templates/config/applepay_button.phtml
@@ -1,3 +1,3 @@
-
+