Skip to content

Commit

Permalink
[ECP-9174] Rename the button
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Nov 13, 2024
1 parent e40f620 commit 5a142d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
61 changes: 24 additions & 37 deletions Controller/Adminhtml/Configuration/DownloadApplePayCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system/adyen_alternative_payment_methods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<![CDATA[<p>Set up additional payment methods to accept online and <a href="https://docs.adyen.com/get-started-with-adyen/payment-glossary#in-app-payments-or-mobile-payments" target="_blank">in-app payments</a> and eliminate the need for traditional card-based transactions.</p>]]>
</comment>
<field id="apple_pay_certificate_download" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Apple Pay Certificate</label>
<label>Apple Pay domain association file</label>
<frontend_model>Adyen\Payment\Model\Config\Adminhtml\ApplepayCertificateButton</frontend_model>
</field>
<field id="ratepay_id" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/templates/config/applepay_button.phtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php /** @var \Adyen\Payment\Model\Config\Adminhtml\ApplepayCertificateButton $block */ ?>

<input type="button" onclick="location.href='<?= $block->escapeJs($block->getActionUrl()) ?>';" value="Download certificate" />
<input type="button" onclick="location.href='<?= $block->escapeJs($block->getActionUrl()) ?>';" value="Download" />

0 comments on commit 5a142d3

Please sign in to comment.