From 8501210f5500ab703b6928e43f769518ea488f3f Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Tue, 24 Oct 2023 15:40:07 +0300 Subject: [PATCH] BP-2374 - Remove Limit By IP from general settings account --- .../Validator/AvailableBasedOnIPValidator.php | 86 ----------- Model/Checks/CanUseForIP.php | 103 ------------- Model/ConfigProvider/Account.php | 16 -- .../AvailableBasedOnIPValidatorTest.php | 144 ------------------ etc/adminhtml/system/account.xml | 6 - etc/di.xml | 9 -- 6 files changed, 364 deletions(-) delete mode 100644 Gateway/Validator/AvailableBasedOnIPValidator.php delete mode 100644 Model/Checks/CanUseForIP.php delete mode 100644 Test/Unit/Gateway/Validator/AvailableBasedOnIPValidatorTest.php diff --git a/Gateway/Validator/AvailableBasedOnIPValidator.php b/Gateway/Validator/AvailableBasedOnIPValidator.php deleted file mode 100644 index dcb02e813..000000000 --- a/Gateway/Validator/AvailableBasedOnIPValidator.php +++ /dev/null @@ -1,86 +0,0 @@ -accountConfig = $accountConfig; - $this->configProviderMethodFactory = $configProviderMethodFactory; - $this->developmentHelper = $developmentHelper; - parent::__construct($resultFactory); - } - - /** - * Check if this payment method is limited by IP. - * - * @param array $validationSubject - * @return ResultInterface - */ - public function validate(array $validationSubject): ResultInterface - { - $isValid = true; - - if ($this->accountConfig->getLimitByIp() == 1) { - $storeId = SubjectReader::readQuote($validationSubject)->getStoreId() ?? null; - $isAllowed = $this->developmentHelper->isDevAllowed($storeId); - - if (!$isAllowed) { - $isValid = false; - } - } - - return $this->createResult($isValid); - } -} diff --git a/Model/Checks/CanUseForIP.php b/Model/Checks/CanUseForIP.php deleted file mode 100644 index ee75aaa9f..000000000 --- a/Model/Checks/CanUseForIP.php +++ /dev/null @@ -1,103 +0,0 @@ -configProviderFactory = $configProviderFactory; - $this->developmentHelper = $developmentHelper; - } - - /** - * Check whether payment method is applicable to quote - * - * @param MethodInterface $paymentMethod - * @param Quote $quote - * @return bool - * @throws Exception - */ - public function isApplicable(MethodInterface $paymentMethod, Quote $quote): bool - { - /** - * @var Account $accountConfig - */ - $accountConfig = $this->configProviderFactory->get('account'); - if ($accountConfig->getActive() == 0) { - return false; - } - - if (!$this->isAvailableBasedOnIp($accountConfig, $quote)) { - return false; - } - - return true; - } - - /** - * Check if this payment method is limited by IP. - * - * @param Account $accountConfig - * @param CartInterface|null $quote - * - * @return bool - */ - protected function isAvailableBasedOnIp( - Account $accountConfig, - CartInterface $quote = null - ): bool { - if ($accountConfig->getLimitByIp() == 1) { - $storeId = $quote ? $quote->getStoreId() : null; - $isAllowed = $this->developmentHelper->isDevAllowed($storeId); - - if (!$isAllowed) { - return false; - } - } - - return true; - } -} diff --git a/Model/ConfigProvider/Account.php b/Model/ConfigProvider/Account.php index f0a07e885..9e982bb5f 100644 --- a/Model/ConfigProvider/Account.php +++ b/Model/ConfigProvider/Account.php @@ -115,7 +115,6 @@ public function getConfig($store = null): array 'debug_types' => $this->getLogLevel($store), 'log_handler' => $this->getLogHandler($store), 'log_retention' => $this->getLogRetention($store), - 'limit_by_ip' => $this->getLimitByIp($store), 'fee_percentage_mode' => $this->getFeePercentageMode($store), 'payment_fee_label' => $this->getPaymentFeeLabel($store), 'order_status_new' => $this->getOrderStatusNew($store), @@ -493,21 +492,6 @@ public function getLogRetention($store = null) ); } - /** - * Display only for selected IPs - * - * @param null|int|string $store - * @return mixed - */ - public function getLimitByIp($store = null) - { - return $this->scopeConfig->getValue( - self::XPATH_ACCOUNT_LIMIT_BY_IP, - ScopeInterface::SCOPE_STORE, - $store - ); - } - /** * Get Fee percentage mode (Subtotal/Subtotal incl. tax) * diff --git a/Test/Unit/Gateway/Validator/AvailableBasedOnIPValidatorTest.php b/Test/Unit/Gateway/Validator/AvailableBasedOnIPValidatorTest.php deleted file mode 100644 index 6e9156bfe..000000000 --- a/Test/Unit/Gateway/Validator/AvailableBasedOnIPValidatorTest.php +++ /dev/null @@ -1,144 +0,0 @@ -resultFactoryMock = $this->getMockBuilder(ResultInterfaceFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->accountConfigMock = $this->getMockBuilder(AccountConfig::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->configProviderMethodFactoryMock = $this->getMockBuilder(ConfigProviderMethodFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->developmentHelperMock = $this->getMockBuilder(\Magento\Developer\Helper\Data::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->validator = new AvailableBasedOnIPValidator( - $this->resultFactoryMock, - $this->accountConfigMock, - $this->configProviderMethodFactoryMock, - $this->developmentHelperMock - ); - } - - /** - * @dataProvider availableBasedOnIPValidationDataProvider - */ - public function testValidate($limitByIp, $configLimitByIp, $storeId, $isDevAllowed, $expectedResult) - { - $quoteMock = $this->getMockBuilder(\Magento\Quote\Model\Quote::class) - ->disableOriginalConstructor() - ->getMock(); - $quoteMock->expects($this->atMost(1)) - ->method('getStoreId') - ->willReturn($storeId); - - $validationSubject = [ - 'paymentMethodInstance' => $this->getMockBuilder(MethodInterface::class) - ->disableOriginalConstructor() - ->getMock(), - 'quote' => $quoteMock, - ]; - - $this->accountConfigMock->expects($this->once()) - ->method('getLimitByIp') - ->willReturn($limitByIp); - - $this->developmentHelperMock->expects($this->atMost(1)) - ->method('isDevAllowed') - ->with($storeId) - ->willReturn($isDevAllowed); - - $expectedResultObj = $this->createMock(ResultInterface::class); - $this->resultFactoryMock->expects($this->once()) - ->method('create') - ->with(['isValid' => $expectedResult, 'failsDescription' => [], 'errorCodes' => []]) - ->willReturn($expectedResultObj); - - $result = $this->validator->validate($validationSubject); - $this->assertSame($expectedResultObj, $result); - } - - public function availableBasedOnIPValidationDataProvider() - { - return [ - 'limitByIp=0, config=0, isDevAllowed=1' => [ - 'limitByIp' => false, - 'configLimitByIp' => '0', - 'storeId' => 1, - 'isDevAllowed' => true, - 'expectedResult' => true, - ], - 'limitByIp=0, config=1, isDevAllowed=1' => [ - 'limitByIp' => false, - 'configLimitByIp' => '1', - 'storeId' => 1, - 'isDevAllowed' => true, - 'expectedResult' => true, - ], - 'limitByIp=1, config=0, isDevAllowed=1' => [ - 'limitByIp' => true, - 'configLimitByIp' => '0', - 'storeId' => 1, - 'isDevAllowed' => true, - 'expectedResult' => true, - ], - 'limitByIp=1, config=1, isDevAllowed=1' => [ - 'limitByIp' => true, - 'configLimitByIp' => '1', - 'storeId' => 1, - 'isDevAllowed' => true, - 'expectedResult' => true, - ], - 'limitByIp=0, config=1, store=0, isDevAllowed=0' => [ - 'limitByIp' => false, - 'configLimitByIp' => '1', - 'storeId' => 0, - 'isDevAllowed' => false, - 'expectedResult' => false, - ], - ]; - } -} diff --git a/etc/adminhtml/system/account.xml b/etc/adminhtml/system/account.xml index 75e90f7b2..2aa8d16af 100644 --- a/etc/adminhtml/system/account.xml +++ b/etc/adminhtml/system/account.xml @@ -253,12 +253,6 @@ - - - - Magento\Config\Model\Config\Source\Yesno - buckaroo_magento2/account/limit_by_ip - diff --git a/etc/di.xml b/etc/di.xml index b9739db3d..2b3cdfe19 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -512,7 +512,6 @@ Buckaroo\Magento2\Gateway\Validator\ActiveAccountValidator Buckaroo\Magento2\Gateway\Validator\AreaCodeValidator - Buckaroo\Magento2\Gateway\Validator\AvailableBasedOnIPValidator Buckaroo\Magento2\Gateway\Validator\AvailableBasedOnAmountValidator Buckaroo\Magento2\Gateway\Validator\AvailableBasedOnCurrencyValidator Buckaroo\Magento2\Gateway\Validator\AvailableBasedOnCustomerGroupValidator @@ -1043,14 +1042,6 @@ - - - - Buckaroo\Magento2\Model\Checks\CanUseForIP - - - -