Skip to content

Commit

Permalink
[EPC-9177] Refactor class names and implement comment modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Feb 3, 2025
1 parent 4fc60c5 commit f61619c
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Magento\Framework\View\Element\Template\Context;
use Magento\Theme\Block\Html\Notices;

class CleanupJobNotice extends Notices
class WebhookRemovalJobNotice extends Notices
{
public function __construct(
Context $context,
Expand All @@ -26,13 +26,11 @@ public function __construct(
}

/**
* Determines the visibility of the auto notification notice on Adyen Notifications Overview page.
*
* @return bool
*/
public function isAutoNotificationCleanupEnabled(): bool
public function isProcessedWebhookRemovalEnabled(): bool
{
return $this->configHelper->getIsWebhookCleanupEnabled();
return $this->configHelper->getIsProcessedWebhookRemovalEnabled();
}

/**
Expand All @@ -42,6 +40,6 @@ public function isAutoNotificationCleanupEnabled(): bool
*/
public function getNumberOfDays(): int
{
return $this->configHelper->getRequiredDaysForOldWebhooks();
return $this->configHelper->getProcessedWebhookRemovalTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
Expand All @@ -17,7 +17,7 @@
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\LocalizedException;

class ProcessedOldNotificationsProvider implements NotificationsProviderInterface
class ProcessedWebhooksProvider implements WebhooksProviderInterface
{
public function __construct(
private readonly AdyenNotificationRepositoryInterface $adyenNotificationRepository,
Expand All @@ -28,7 +28,7 @@ public function __construct(

public function provide(): array
{
$numberOfDays = $this->configHelper->getRequiredDaysForOldWebhooks();
$numberOfDays = $this->configHelper->getProcessedWebhookRemovalTime();

$dateFrom = date('Y-m-d H:i:s', time() - $numberOfDays * 24 * 60 * 60);

Expand All @@ -43,7 +43,7 @@ public function provide(): array
return $items->getItems();
} catch (LocalizedException $e) {
$errorMessage = sprintf(
__('An error occurred while providing notifications older than %s days!'),
__('An error occurred while providing webhooks older than %s days!'),
$numberOfDays
);

Expand All @@ -55,6 +55,6 @@ public function provide(): array

public function getProviderName(): string
{
return "Adyen processed old webhook notifications";
return "Adyen processed webhooks provider";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Cron\Providers;

interface NotificationsProviderInterface
interface WebhooksProviderInterface
{
/**
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
namespace Adyen\Payment\Cron;

use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
use Adyen\Payment\Cron\Providers\NotificationsProviderInterface;
use Adyen\Payment\Cron\Providers\WebhooksProviderInterface;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Exception;

class CleanupNotifications
class RemoveProcessedWebhooks
{
/**
* @param NotificationsProviderInterface[] $providers
* @param WebhooksProviderInterface[] $providers
*/
public function __construct(
private readonly array $providers,
Expand All @@ -35,7 +35,7 @@ public function __construct(
*/
public function execute(): void
{
$isWebhookCleanupEnabled = $this->configHelper->getIsWebhookCleanupEnabled();
$isWebhookCleanupEnabled = $this->configHelper->getIsProcessedWebhookRemovalEnabled();

if ($isWebhookCleanupEnabled === true) {
$numberOfItemsRemoved = 0;
Expand All @@ -51,7 +51,7 @@ public function execute(): void
'%1: Notification with entity_id %2 has been deleted because it was processed %3 days ago.',
$provider->getProviderName(),
$notificationToCleanup->getEntityId(),
$this->configHelper->getRequiredDaysForOldWebhooks()
$this->configHelper->getProcessedWebhookRemovalTime()
);
$this->adyenLogger->addAdyenNotification($message);

Expand Down
16 changes: 8 additions & 8 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Config
const XML_RECURRING_CONFIGURATION = 'recurring_configuration';
const XML_ALLOW_MULTISTORE_TOKENS = 'allow_multistore_tokens';
const XML_THREEDS_FLOW = 'threeds_flow';
const XML_CLEANUP_OLD_WEBHOOKS = 'cleanup_old_webhooks';
const XML_REQUIRED_DAYS_OLD_WEBHOOKS = 'required_days_old_webhooks';
const XML_REMOVE_PROCESSED_WEBHOOKS = 'remove_processed_webhooks';
const XML_PROCESSED_WEBHOOK_REMOVAL_TIME = 'processed_webhook_removal_time';

protected ScopeConfigInterface $scopeConfig;
private EncryptorInterface $encryptor;
Expand Down Expand Up @@ -595,35 +595,35 @@ public function getThreeDSFlow(int $storeId = null): string
}

/**
* Returns whether if the webhook clean-up by cronjob is enabled or not.
* Indicates whether if the processed webhook removal cronjob is enabled or not.
*
* This field can only be configured on default scope level as
* the notification table doesn't have nay relation with the stores.
*
* @return bool
*/
public function getIsWebhookCleanupEnabled(): bool
public function getIsProcessedWebhookRemovalEnabled(): bool
{
return $this->getConfigData(
self::XML_CLEANUP_OLD_WEBHOOKS,
self::XML_REMOVE_PROCESSED_WEBHOOKS,
self::XML_ADYEN_ABSTRACT_PREFIX,
null,
true
);
}

/**
* Returns the required number of days to clean-up notification by cronjob.
* Returns the required number of days to remove processed webhooks.
*
* This field can only be configured on default scope level as
* the notification table doesn't have nay relation with the stores.
*
* @return int
*/
public function getRequiredDaysForOldWebhooks(): int
public function getProcessedWebhookRemovalTime(): int
{
return (int) $this->getConfigData(
self::XML_REQUIRED_DAYS_OLD_WEBHOOKS,
self::XML_PROCESSED_WEBHOOK_REMOVAL_TIME,
self::XML_ADYEN_ABSTRACT_PREFIX,
null
);
Expand Down
35 changes: 35 additions & 0 deletions Model/Comment/WebhookRemovalNotice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2025 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Model\Comment;

use Adyen\Payment\Cron\Providers\ProcessedWebhooksProvider;
use Magento\Config\Model\Config\CommentInterface;

class WebhookRemovalNotice implements CommentInterface
{
public function __construct(
private readonly ProcessedWebhooksProvider $processedNotificationProvider
) { }

public function getCommentText($elementValue)
{
if ($elementValue === '0') {
$numberOfNotificationsToBeRemoved = count($this->processedNotificationProvider->provide());

return __(
'Enabling this feature will remove %1 processed webhooks from the database!',
$numberOfNotificationsToBeRemoved
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Adyen\Payment\Test\Unit\Block\Checkout;

use Adyen\Payment\Block\Adminhtml\Notification\CleanupJobNotice;
use Adyen\Payment\Block\Adminhtml\Notification\WebhookRemovalJobNotice;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\View\Element\Template\Context;
use PHPUnit\Framework\MockObject\MockObject;

class CleanupJobNoticeTest extends AbstractAdyenTestCase
class WebhookRemovalJobNoticeTest extends AbstractAdyenTestCase
{
protected ?CleanupJobNotice $cleanupJobNotice;
protected ?WebhookRemovalJobNotice $cleanupJobNotice;
protected Context|MockObject $contextMock;
protected Config|MockObject $configHelperMock;

Expand All @@ -30,7 +30,7 @@ protected function setUp(): void
{
$this->contextMock = $this->createMock(Context::class);
$this->configHelperMock = $this->createMock(Config::class);
$this->cleanupJobNotice = new CleanupJobNotice($this->contextMock, $this->configHelperMock);
$this->cleanupJobNotice = new WebhookRemovalJobNotice($this->contextMock, $this->configHelperMock);
}

/**
Expand All @@ -44,14 +44,14 @@ protected function tearDown(): void
/**
* @return void
*/
public function testIsAutoNotificationCleanupEnabled()
public function testIsProcessedWebhookRemovalEnabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->method('getIsProcessedWebhookRemovalEnabled')
->willReturn(true);

$this->assertTrue(
$this->cleanupJobNotice->isAutoNotificationCleanupEnabled()
$this->cleanupJobNotice->isProcessedWebhookRemovalEnabled()
);
}

Expand All @@ -63,7 +63,7 @@ public function testGetNumberOfDays()
$days = 90;

$this->configHelperMock->expects($this->once())
->method('getRequiredDaysForOldWebhooks')
->method('getProcessedWebhookRemovalTime')
->willReturn($days);

$this->assertEquals($days, $this->cleanupJobNotice->getNumberOfDays());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Adyen\Payment\Api\Data\NotificationInterface;
use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
use Adyen\Payment\Cron\Providers\ProcessedOldNotificationsProvider;
use Adyen\Payment\Cron\Providers\ProcessedWebhooksProvider;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
Expand All @@ -23,9 +23,9 @@
use Magento\Framework\Exception\LocalizedException;
use PHPUnit\Framework\MockObject\MockObject;

class ProcessedOldNotificationsProviderTest extends AbstractAdyenTestCase
class ProcessedNotificationsProviderTest extends AbstractAdyenTestCase
{
protected ?ProcessedOldNotificationsProvider $notificationsProvider;
protected ?ProcessedWebhooksProvider $notificationsProvider;
protected AdyenNotificationRepositoryInterface|MockObject $adyenNotificationRepositoryMock;
protected SearchCriteriaBuilder|MockObject $searchCriteriaBuilderMock;
protected Config|MockObject $configHelperMock;
Expand All @@ -39,7 +39,7 @@ protected function setUp(): void
$this->configHelperMock = $this->createMock(Config::class);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);

$this->notificationsProvider = new ProcessedOldNotificationsProvider(
$this->notificationsProvider = new ProcessedWebhooksProvider(
$this->adyenNotificationRepositoryMock,
$this->searchCriteriaBuilderMock,
$this->configHelperMock,
Expand All @@ -57,7 +57,7 @@ public function testProvideSuccess()
$expiryDays = 90;

$this->configHelperMock->expects($this->once())
->method('getRequiredDaysForOldWebhooks')
->method('getProcessedWebhookRemovalTime')
->willReturn($expiryDays);

$dateMock = date('Y-m-d H:i:s', time() - $expiryDays * 24 * 60 * 60);
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testProvideFailure()
$expiryDays = 90;

$this->configHelperMock->expects($this->once())
->method('getRequiredDaysForOldWebhooks')
->method('getProcessedWebhookRemovalTime')
->willReturn($expiryDays);

$dateMock = date('Y-m-d H:i:s', time() - $expiryDays * 24 * 60 * 60);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
namespace Adyen\Payment\Test\Cron;

use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
use Adyen\Payment\Cron\CleanupNotifications;
use Adyen\Payment\Cron\Providers\NotificationsProviderInterface;
use Adyen\Payment\Cron\RemoveProcessedWebhooks;
use Adyen\Payment\Cron\Providers\WebhooksProviderInterface;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\DB\Adapter\DeadlockException;
use PHPUnit\Framework\MockObject\MockObject;

class CleanupNotificationsTest extends AbstractAdyenTestCase
class RemoveProcessedWebhooksTest extends AbstractAdyenTestCase
{
protected ?CleanupNotifications $cleanupNotifications;
protected ?RemoveProcessedWebhooks $cleanupNotifications;
protected AdyenLogger|MockObject $adyenLoggerMock;
protected Config|MockObject $configHelperMock;
protected AdyenNotificationRepositoryInterface|MockObject $adyenNotificationRepositoryMock;
protected NotificationsProviderInterface|MockObject $notificationsProvider;
protected WebhooksProviderInterface|MockObject $notificationsProvider;
protected array $providers;

protected function setUp(): void
Expand All @@ -36,11 +36,11 @@ protected function setUp(): void
$this->configHelperMock = $this->createMock(Config::class);
$this->adyenNotificationRepositoryMock =
$this->createMock(AdyenNotificationRepositoryInterface::class);
$this->notificationsProvider = $this->createMock(NotificationsProviderInterface::class);
$this->notificationsProvider = $this->createMock(WebhooksProviderInterface::class);

$this->providers[] = $this->notificationsProvider;

$this->cleanupNotifications = new CleanupNotifications(
$this->cleanupNotifications = new RemoveProcessedWebhooks(
$this->providers,
$this->adyenLoggerMock,
$this->configHelperMock,
Expand All @@ -56,7 +56,7 @@ protected function tearDown(): void
public function testExecuteConfigEnabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->method('getIsProcessedWebhookRemovalEnabled')
->willReturn(true);

$notificationMock = $this->createMock(Notification::class);
Expand All @@ -77,7 +77,7 @@ public function testExecuteConfigEnabled()
public function testExecuteConfigDisabled()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->method('getIsProcessedWebhookRemovalEnabled')
->willReturn(false);

$this->notificationsProvider->expects($this->never())->method('provide');
Expand All @@ -90,7 +90,7 @@ public function testExecuteConfigDisabled()
public function testExecuteException()
{
$this->configHelperMock->expects($this->once())
->method('getIsWebhookCleanupEnabled')
->method('getIsProcessedWebhookRemovalEnabled')
->willReturn(true);

$notificationMock = $this->createMock(Notification::class);
Expand Down
Loading

0 comments on commit f61619c

Please sign in to comment.