From fcf62f9275bfbfb056dfb965b261b8f4292f69a4 Mon Sep 17 00:00:00 2001 From: Hossam Fares Date: Mon, 12 Feb 2024 14:45:35 +0000 Subject: [PATCH 1/9] skip POS payment method from toggling as this config is visual via Admin panel --- Helper/PaymentMethods.php | 5 +++++ Test/Unit/Helper/PaymentMethodsTest.php | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Helper/PaymentMethods.php b/Helper/PaymentMethods.php index 3e21ae4f0..0b595af4c 100644 --- a/Helper/PaymentMethods.php +++ b/Helper/PaymentMethods.php @@ -153,6 +153,11 @@ public function togglePaymentMethodsActivation(?bool $isActive =null): array } foreach ($this->getAdyenPaymentMethods() as $paymentMethod) { + //skip POS from toggling as this config is visual via Admin panel + if ($paymentMethod == Config::XML_ADYEN_POS_CLOUD) { + continue; + } + $value = $isActive ? '1': '0'; $field = 'active'; $this->configHelper->setConfigData($value, $field, $paymentMethod); diff --git a/Test/Unit/Helper/PaymentMethodsTest.php b/Test/Unit/Helper/PaymentMethodsTest.php index 647b5bedd..26f0dce53 100644 --- a/Test/Unit/Helper/PaymentMethodsTest.php +++ b/Test/Unit/Helper/PaymentMethodsTest.php @@ -170,7 +170,8 @@ public function testTogglePaymentMethodsActivation() [ 'adyen_cc' => [], 'adyen_oneclick' => [], - 'adyen_cc_vault' => [] + 'adyen_cc_vault' => [], + 'adyen_pos_cloud' => [], ]); $this->configHelperMock From b1d97740b40840ac59f2dbb4f0cdb805178e5c7d Mon Sep 17 00:00:00 2001 From: hossam-adyen <132500300+hossam-adyen@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:42:07 +0100 Subject: [PATCH 2/9] Update PaymentMethods.php --- Helper/PaymentMethods.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/PaymentMethods.php b/Helper/PaymentMethods.php index 0b595af4c..5599f64ee 100644 --- a/Helper/PaymentMethods.php +++ b/Helper/PaymentMethods.php @@ -16,6 +16,7 @@ use Adyen\Payment\Logger\AdyenLogger; use Adyen\Payment\Model\Notification; use Adyen\Util\ManualCapture; +use Adyen\Payment\Model\Config\Backend\PaymentMethodsStatus; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; @@ -153,8 +154,7 @@ public function togglePaymentMethodsActivation(?bool $isActive =null): array } foreach ($this->getAdyenPaymentMethods() as $paymentMethod) { - //skip POS from toggling as this config is visual via Admin panel - if ($paymentMethod == Config::XML_ADYEN_POS_CLOUD) { + if (in_array($paymentMethod, PaymentMethodsStatus::EXCLUDED_PAYMENT_METHODS) { continue; } From 90283d8d871ed4042f29498e91f4ff571f681179 Mon Sep 17 00:00:00 2001 From: hossam-adyen <132500300+hossam-adyen@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:43:45 +0100 Subject: [PATCH 3/9] Update Test/Unit/Helper/PaymentMethodsTest.php --- Test/Unit/Helper/PaymentMethodsTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Test/Unit/Helper/PaymentMethodsTest.php b/Test/Unit/Helper/PaymentMethodsTest.php index 26f0dce53..b12b776d1 100644 --- a/Test/Unit/Helper/PaymentMethodsTest.php +++ b/Test/Unit/Helper/PaymentMethodsTest.php @@ -172,6 +172,8 @@ public function testTogglePaymentMethodsActivation() 'adyen_oneclick' => [], 'adyen_cc_vault' => [], 'adyen_pos_cloud' => [], + 'adyen_moto' => [], + 'adyen_pay_by_link' => [], ]); $this->configHelperMock From 48ac8ef685a9fe85ed9ab616523a852e1983b45b Mon Sep 17 00:00:00 2001 From: hossam-adyen <132500300+hossam-adyen@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:53:14 +0100 Subject: [PATCH 4/9] Update Helper/PaymentMethods.php --- Helper/PaymentMethods.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/PaymentMethods.php b/Helper/PaymentMethods.php index 5599f64ee..a1aeaf5fd 100644 --- a/Helper/PaymentMethods.php +++ b/Helper/PaymentMethods.php @@ -154,7 +154,7 @@ public function togglePaymentMethodsActivation(?bool $isActive =null): array } foreach ($this->getAdyenPaymentMethods() as $paymentMethod) { - if (in_array($paymentMethod, PaymentMethodsStatus::EXCLUDED_PAYMENT_METHODS) { + if (in_array($paymentMethod, PaymentMethodsStatus::EXCLUDED_PAYMENT_METHODS)) { continue; } From 27f413ef31f732443b7a6c055fb1aa8e54867f2e Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Mon, 12 Feb 2024 18:06:10 +0100 Subject: [PATCH 5/9] Use toggle method in the helper method for PaymentMethodsStatus class --- Helper/PaymentMethods.php | 15 +++++++-- Model/Config/Backend/PaymentMethodsStatus.php | 31 +------------------ 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/Helper/PaymentMethods.php b/Helper/PaymentMethods.php index a1aeaf5fd..09fa3f5ef 100644 --- a/Helper/PaymentMethods.php +++ b/Helper/PaymentMethods.php @@ -15,8 +15,10 @@ use Adyen\Client; use Adyen\Payment\Logger\AdyenLogger; use Adyen\Payment\Model\Notification; +use Adyen\Payment\Model\Ui\Adminhtml\AdyenMotoConfigProvider; +use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider; +use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider; use Adyen\Util\ManualCapture; -use Adyen\Payment\Model\Config\Backend\PaymentMethodsStatus; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; @@ -55,6 +57,15 @@ class PaymentMethods extends AbstractHelper const ADYEN_GROUP_ALTERNATIVE_PAYMENT_METHODS = 'adyen-alternative-payment-method'; + /* + * Following payment methods should be enabled with their own configuration path. + */ + const EXCLUDED_PAYMENT_METHODS = [ + AdyenPayByLinkConfigProvider::CODE, + AdyenPosCloudConfigProvider::CODE, + AdyenMotoConfigProvider::CODE + ]; + protected CartRepositoryInterface $quoteRepository; protected ScopeConfigInterface $config; protected Data $adyenHelper; @@ -154,7 +165,7 @@ public function togglePaymentMethodsActivation(?bool $isActive =null): array } foreach ($this->getAdyenPaymentMethods() as $paymentMethod) { - if (in_array($paymentMethod, PaymentMethodsStatus::EXCLUDED_PAYMENT_METHODS)) { + if (in_array($paymentMethod, self::EXCLUDED_PAYMENT_METHODS)) { continue; } diff --git a/Model/Config/Backend/PaymentMethodsStatus.php b/Model/Config/Backend/PaymentMethodsStatus.php index d3e9debfc..03173c239 100644 --- a/Model/Config/Backend/PaymentMethodsStatus.php +++ b/Model/Config/Backend/PaymentMethodsStatus.php @@ -12,12 +12,8 @@ namespace Adyen\Payment\Model\Config\Backend; use Adyen\Payment\Helper\PaymentMethods; -use Adyen\Payment\Model\Ui\Adminhtml\AdyenMotoConfigProvider; -use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider; -use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider; use Magento\Framework\App\Cache\TypeListInterface; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\App\Config\Value; use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Model\Context; @@ -27,29 +23,17 @@ class PaymentMethodsStatus extends Value { protected PaymentMethods $paymentMethodsHelper; - private WriterInterface $configWriter; - - /* - * Following payment methods should be enabled with their own configuration path. - */ - const EXCLUDED_PAYMENT_METHODS = [ - AdyenPayByLinkConfigProvider::CODE, - AdyenPosCloudConfigProvider::CODE, - AdyenMotoConfigProvider::CODE - ]; public function __construct( Context $context, Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, - WriterInterface $configWriter, PaymentMethods $paymentMethodsHelper, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] ) { - $this->configWriter = $configWriter; $this->paymentMethodsHelper = $paymentMethodsHelper; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); @@ -57,20 +41,7 @@ public function __construct( public function afterSave(): PaymentMethodsStatus { - $value = $this->getValue(); - $adyenPaymentMethods = $this->paymentMethodsHelper->getAdyenPaymentMethods(); - - foreach ($adyenPaymentMethods as $adyenPaymentMethod) { - // Exclude following payment methods. They need to use their own configuration path. - if (in_array($adyenPaymentMethod, self::EXCLUDED_PAYMENT_METHODS)) { - continue; - } - - $this->configWriter->save( - 'payment/' . $adyenPaymentMethod . '/active', - $value, - ); - } + $this->paymentMethodsHelper->togglePaymentMethodsActivation($this->getValue()); return $this; } From 4e0689880bd08c268471ec2ccfab57b2363f6134 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 13 Feb 2024 09:13:52 +0100 Subject: [PATCH 6/9] Write unit test for PaymentMethodsStatus class --- .../Backend/PaymentMethodsStatusTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php diff --git a/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php b/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php new file mode 100644 index 000000000..5932713dd --- /dev/null +++ b/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php @@ -0,0 +1,41 @@ + + */ + +namespace Adyen\Payment\Test\Unit\Model\Config\Backend; + +use Adyen\Payment\Helper\PaymentMethods; +use Adyen\Payment\Model\Config\Backend\PaymentMethodsStatus; +use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +class PaymentMethodsStatusTest extends AbstractAdyenTestCase +{ + const ENABLED_METHODS = [ + 'adyen_cc', + 'adyen_ideal' + ]; + + public function testAfterSave() + { + $paymentMethodsHelperMock = $this->createMock(PaymentMethods::class); + $paymentMethodsHelperMock->method('togglePaymentMethodsActivation') + ->willReturn(self::ENABLED_METHODS); + + $objectManager = new ObjectManager($this); + $paymentMethodsStatus = $objectManager->getObject(PaymentMethodsStatus::class, [ + 'paymentMethodsHelper' => $paymentMethodsHelperMock + ]); + + $result = $paymentMethodsStatus->afterSave(); + + $this->assertIsArray($result); + } +} From ac46ba140e5b82a4ab189f4787695f8e91b73d7e Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 13 Feb 2024 09:15:39 +0100 Subject: [PATCH 7/9] Write unit test for PaymentMethodsStatus class --- Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php b/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php index 5932713dd..9035f6679 100644 --- a/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php +++ b/Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php @@ -36,6 +36,6 @@ public function testAfterSave() $result = $paymentMethodsStatus->afterSave(); - $this->assertIsArray($result); + $this->assertInstanceOf(PaymentMethodsStatus::class, $result); } } From 3521bc663d9f5e12adc22ac0f0f7444f4fc9c580 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 20 Feb 2024 13:33:36 +0100 Subject: [PATCH 8/9] Update Model/Config/Backend/PaymentMethodsStatus.php --- Model/Config/Backend/PaymentMethodsStatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Config/Backend/PaymentMethodsStatus.php b/Model/Config/Backend/PaymentMethodsStatus.php index 03173c239..199a1f8e7 100644 --- a/Model/Config/Backend/PaymentMethodsStatus.php +++ b/Model/Config/Backend/PaymentMethodsStatus.php @@ -41,7 +41,7 @@ public function __construct( public function afterSave(): PaymentMethodsStatus { - $this->paymentMethodsHelper->togglePaymentMethodsActivation($this->getValue()); + $this->paymentMethodsHelper->togglePaymentMethodsActivation((bool) $this->getValue()); return $this; } From 8ace095cffbad248e6931550105c9e88456373f4 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 21 Feb 2024 15:11:45 +0100 Subject: [PATCH 9/9] Enable Pay by Link individually --- .github/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/Makefile b/.github/Makefile index c437dc72b..58fc1713a 100644 --- a/.github/Makefile +++ b/.github/Makefile @@ -30,6 +30,7 @@ configure: n98-magerun2.phar bin/magento config:set payment/adyen_abstract/demo_mode 1 bin/magento adyen:enablepaymentmethods:run bin/magento config:set payment/adyen_abstract/has_holder_name 1 + bin/magento config:set payment/adyen_pay_by_link/active 1 bin/magento config:set payment/adyen_pay_by_link/days_to_expire 5 bin/magento config:set payment/adyen_giving/active 1 bin/magento config:set payment/adyen_giving/charity_description 'test'