diff --git a/Controller/Adminhtml/Action/Apikey.php b/Controller/Adminhtml/Action/Apikey.php index 2a2bd2369d9..8d274afa7ed 100644 --- a/Controller/Adminhtml/Action/Apikey.php +++ b/Controller/Adminhtml/Action/Apikey.php @@ -11,6 +11,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\Encryption\EncryptorInterface; +use Magento\Store\Model\ScopeInterface; use Mollie\Payment\Helper\General as MollieHelper; use Mollie\Payment\Helper\Tests as TestsHelper; @@ -108,11 +109,11 @@ protected function _isAllowed() private function getKey(string $type): string { if (!$this->request->getParam($type . '_key') || $this->request->getParam($type . '_key') == '******') { - $value = $this->scopeConfig->getValue('payment/mollie_general/apikey_' . $type); + $value = $this->scopeConfig->getValue('payment/mollie_general/apikey_' . $type, ScopeInterface::SCOPE_STORE); return $this->encryptor->decrypt($value); } - return $this->request->getParam('test_key'); + return $this->request->getParam($type . '_key'); } } diff --git a/Observer/ControllerActionPredispatchCheckoutIndexIndex/RestoreQuoteOfUnsuccessfulPayment.php b/Observer/ControllerActionPredispatchCheckoutIndexIndex/RestoreQuoteOfUnsuccessfulPayment.php index 39ed6089732..e04cf1ea5bc 100644 --- a/Observer/ControllerActionPredispatchCheckoutIndexIndex/RestoreQuoteOfUnsuccessfulPayment.php +++ b/Observer/ControllerActionPredispatchCheckoutIndexIndex/RestoreQuoteOfUnsuccessfulPayment.php @@ -43,10 +43,10 @@ public function execute(Observer $observer) return; } - if ($order->getState() === Order::STATE_NEW && + if ($order->getState() === Order::STATE_PENDING_PAYMENT && $order->getStatus() === $this->config->orderStatusPending($order->getStoreId()) ) { $this->checkoutSession->restoreQuote(); } } -} \ No newline at end of file +} diff --git a/Service/Order/DeletePaymentReminder.php b/Service/Order/DeletePaymentReminder.php index a17c84e7b1c..f6cbf5d246e 100644 --- a/Service/Order/DeletePaymentReminder.php +++ b/Service/Order/DeletePaymentReminder.php @@ -76,7 +76,7 @@ public function delete($reference) if (is_numeric($reference)) { $criteria->addFilter(Order::CUSTOMER_ID, $reference); } else { - $criteria->addFilter(Order::CUSTOMER_ID, ['null' => true]); + $criteria->addFilter(Order::CUSTOMER_ID, '', 'null'); $criteria->addFilter(Order::CUSTOMER_EMAIL, $reference); } diff --git a/Test/Integration/BackendControllerTestCase.php b/Test/Integration/BackendControllerTestCase.php new file mode 100644 index 00000000000..c2df1e3c7e8 --- /dev/null +++ b/Test/Integration/BackendControllerTestCase.php @@ -0,0 +1,7 @@ +=')) { + require __DIR__ . '/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php'; +} else { + require __DIR__ . '/PHPUnit/BackendControllerTestCaseVersion8AndLower.php'; +} diff --git a/Test/Integration/Controller/Adminhtml/Action/ApikeyTest.php b/Test/Integration/Controller/Adminhtml/Action/ApikeyTest.php new file mode 100644 index 00000000000..fa903cf9d7b --- /dev/null +++ b/Test/Integration/Controller/Adminhtml/Action/ApikeyTest.php @@ -0,0 +1,154 @@ +mockMollieMethodsEndpointForRequestKeys('test_apikey123456789101112131415161718', ''); + + $this->dispatch('backend/mollie/action/apikey'); + + $result = json_decode($this->getResponse()->getContent(), true); + + $this->assertStringContainsString('Test API-key: Success!', $result['msg']); + $this->assertStringContainsString('Live API-key: Empty value', $result['msg']); + $this->assertTrue($result['success']); + } + + public function testValidatesTheLiveKey() + { + $this->mockMollieMethodsEndpointForRequestKeys('', 'live_apikey123456789101112131415161718'); + + $this->dispatch('backend/mollie/action/apikey'); + + $result = json_decode($this->getResponse()->getContent(), true); + + $this->assertStringContainsString('Test API-key: Empty value', $result['msg']); + $this->assertStringContainsString('Live API-key: Success!', $result['msg']); + $this->assertTrue($result['success']); + } + + public function testFallsBackOnTheConfigurationForTest() + { + $encryptorMock = $this->createMock(Encryptor::class); + + $encryptorMock->method('decrypt')->willReturnCallback(function ($input) use (&$count) { + $count++; + if ($count == 2) { + return 'test_apikey123456789101112131415161718'; + } + + if ($count === 3) { + return ''; + } + + return $input; + }); + + $this->mockMollieMethodsEndpointForConfigurationKeys('test_apikey123456789101112131415161718', ''); + + $this->_objectManager->addSharedInstance($encryptorMock, Encryptor::class); + + $this->dispatch('backend/mollie/action/apikey'); + + $result = json_decode($this->getResponse()->getContent(), true); + + $this->assertStringContainsString('Test API-key: Success!', $result['msg']); + $this->assertStringContainsString('Live API-key: Empty value', $result['msg']); + $this->assertTrue($result['success']); + } + + public function testFallsBackOnTheConfigurationForLive() + { + $count = 0; + $encryptorMock = $this->createMock(Encryptor::class); + $encryptorMock->method('decrypt')->willReturnCallback(function ($input) use (&$count) { + $count++; + if ($count == 2) { + return ''; + } + + if ($count === 3) { + return 'live_apikey123456789101112131415161718'; + } + + return $input; + }); + + $this->mockMollieMethodsEndpointForConfigurationKeys('', 'live_apikey123456789101112131415161718'); + + $this->_objectManager->addSharedInstance($encryptorMock, Encryptor::class); + + $this->dispatch('backend/mollie/action/apikey'); + + $result = json_decode($this->getResponse()->getContent(), true); + + $this->assertStringContainsString('Test API-key: Empty value', $result['msg']); + $this->assertStringContainsString('Live API-key: Success!', $result['msg']); + $this->assertTrue($result['success']); + } + + protected function mockMollieMethodsEndpointForRequestKeys(string $testApiKey, string $liveApiKey): void + { + $mollieModel = $this->_objectManager->get(Mollie::class); + $mollieModelMock = $this->createMock(Mollie::class); + foreach (array_filter([$testApiKey, $liveApiKey]) as $key) { + $api = $mollieModel->loadMollieApi($key); + + $api->methods = $this->createMock(MethodEndpoint::class); + $api->methods->method('all')->willReturn([]); + + $mollieModelMock->method('loadMollieApi')->with($key)->willReturn($api); + } + + $tests = $this->_objectManager->create(Tests::class, [ + 'mollieModel' => $mollieModelMock, + 'tests' => [], + ]); + + $this->_objectManager->addSharedInstance($tests, Tests::class); + + $this->getRequest()->setParams([ + 'test_key' => $testApiKey, + 'live_key' => $liveApiKey, + ]); + } + + protected function mockMollieMethodsEndpointForConfigurationKeys(string $testApiKey, string $liveApiKey): void + { + $mollieModel = $this->_objectManager->get(Mollie::class); + $mollieModelMock = $this->createMock(Mollie::class); + foreach (array_filter([$testApiKey, $liveApiKey]) as $key) { + $api = $mollieModel->loadMollieApi($key); + + $api->methods = $this->createMock(MethodEndpoint::class); + $api->methods->method('all')->willReturn([]); + + $mollieModelMock->method('loadMollieApi')->with($key)->willReturn($api); + } + + $tests = $this->_objectManager->create(Tests::class, [ + 'mollieModel' => $mollieModelMock, + 'tests' => [], + ]); + + $this->_objectManager->addSharedInstance($tests, Tests::class); + + $this->getRequest()->setParams([ + 'test_key' => '', + 'live_key' => '', + ]); + } +} diff --git a/Test/Integration/Etc/Config/MethodsConfigurationTest.php b/Test/Integration/Etc/Config/MethodsConfigurationTest.php new file mode 100644 index 00000000000..ce9d9d6b3b6 --- /dev/null +++ b/Test/Integration/Etc/Config/MethodsConfigurationTest.php @@ -0,0 +1,53 @@ +objectManager->get(Structure::class); + + $value = $config->getElementByConfigPath('payment/' . $method . '/days_before_expire'); + + $this->assertStringContainsString('digits-range-1-365', $value->getAttribute('frontend_class')); + } +} diff --git a/Test/Integration/PHPUnit/BackendControllerTestCaseVersion8AndLower.php b/Test/Integration/PHPUnit/BackendControllerTestCaseVersion8AndLower.php new file mode 100644 index 00000000000..5a979976aa5 --- /dev/null +++ b/Test/Integration/PHPUnit/BackendControllerTestCaseVersion8AndLower.php @@ -0,0 +1,28 @@ +setUpWithoutVoid(); + } + + protected function setUpWithoutVoid() + { + } + + public function assertStringContainsString($expected, $actual, $message = null) + { + $this->assertContains($expected, $actual, $message); + } +} diff --git a/Test/Integration/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php b/Test/Integration/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php new file mode 100644 index 00000000000..2a14a85d153 --- /dev/null +++ b/Test/Integration/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php @@ -0,0 +1,23 @@ +setUpWithoutVoid(); + } + + protected function setUpWithoutVoid() + { + } +} diff --git a/Test/Integration/PHPUnit/ControllerTestCaseVersion8AndLower.php b/Test/Integration/PHPUnit/ControllerTestCaseVersion8AndLower.php index b7869651ad9..8614b52bdef 100644 --- a/Test/Integration/PHPUnit/ControllerTestCaseVersion8AndLower.php +++ b/Test/Integration/PHPUnit/ControllerTestCaseVersion8AndLower.php @@ -20,4 +20,9 @@ protected function setUp() protected function setUpWithoutVoid() { } + + public function assertStringContainsString($expected, $actual, $message = null) + { + $this->assertContains($expected, $actual, $message); + } } diff --git a/composer.json b/composer.json index cd4f96b7cca..915ea694046 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "2.3.0", + "version": "2.4.0", "keywords": [ "mollie", "payment", @@ -46,6 +46,20 @@ "require": { "mollie/mollie-api-php": "^2.1", "magento/framework": ">=102.0.3", + "magento/module-backend": ">=100.3.3", + "magento/module-catalog": ">=100.3.3", + "magento/module-checkout": ">=100.3.3", + "magento/module-config": ">=100.3.3", + "magento/module-customer": ">=100.3.3", + "magento/module-eav": ">=100.3.3", + "magento/module-payment": ">=100.3.3", + "magento/module-quote": ">=100.3.3", + "magento/module-sales": ">=100.3.3", + "magento/module-sales-rule": ">=100.3.3", + "magento/module-store": ">=100.3.3", + "magento/module-tax": ">=100.3.3", + "magento/module-ui": ">=100.3.3", + "magento/module-vault": ">=100.3.3", "php": ">=7.1", "ext-json": "*" }, diff --git a/etc/adminhtml/methods/applepay.xml b/etc/adminhtml/methods/applepay.xml index 6c5aa59a295..0f7f56f92a2 100644 --- a/etc/adminhtml/methods/applepay.xml +++ b/etc/adminhtml/methods/applepay.xml @@ -58,7 +58,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_applepay/days_before_expire 1 diff --git a/etc/adminhtml/methods/bancontact.xml b/etc/adminhtml/methods/bancontact.xml index 01984e5bbbd..fddb9cec42a 100644 --- a/etc/adminhtml/methods/bancontact.xml +++ b/etc/adminhtml/methods/bancontact.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_bancontact/days_before_expire 1 diff --git a/etc/adminhtml/methods/banktransfer.xml b/etc/adminhtml/methods/banktransfer.xml index 0263eeacf4c..9101ddf95b6 100644 --- a/etc/adminhtml/methods/banktransfer.xml +++ b/etc/adminhtml/methods/banktransfer.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_banktransfer/days_before_expire 1 diff --git a/etc/adminhtml/methods/belfius.xml b/etc/adminhtml/methods/belfius.xml index 24e9f0ee6d7..507d69bc386 100644 --- a/etc/adminhtml/methods/belfius.xml +++ b/etc/adminhtml/methods/belfius.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_belfius/days_before_expire 1 diff --git a/etc/adminhtml/methods/creditcard.xml b/etc/adminhtml/methods/creditcard.xml index a513eed1360..0b48ffabc64 100644 --- a/etc/adminhtml/methods/creditcard.xml +++ b/etc/adminhtml/methods/creditcard.xml @@ -58,13 +58,12 @@ Customers API.]]> 1 - 0 - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_creditcard/days_before_expire 1 diff --git a/etc/adminhtml/methods/directdebit.xml b/etc/adminhtml/methods/directdebit.xml index 48629dc0477..0a61b965509 100644 --- a/etc/adminhtml/methods/directdebit.xml +++ b/etc/adminhtml/methods/directdebit.xml @@ -43,7 +43,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_directdebit/days_before_expire 1 diff --git a/etc/adminhtml/methods/eps.xml b/etc/adminhtml/methods/eps.xml index 2ebe6d43c3d..bd12effe839 100644 --- a/etc/adminhtml/methods/eps.xml +++ b/etc/adminhtml/methods/eps.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_eps/days_before_expire 1 diff --git a/etc/adminhtml/methods/giftcard.xml b/etc/adminhtml/methods/giftcard.xml index 6e2a4e79717..0feab519ba8 100644 --- a/etc/adminhtml/methods/giftcard.xml +++ b/etc/adminhtml/methods/giftcard.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_giftcard/days_before_expire 1 diff --git a/etc/adminhtml/methods/giropay.xml b/etc/adminhtml/methods/giropay.xml index bcbb81a8aae..b7ea1709017 100644 --- a/etc/adminhtml/methods/giropay.xml +++ b/etc/adminhtml/methods/giropay.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_giropay/days_before_expire 1 diff --git a/etc/adminhtml/methods/ideal.xml b/etc/adminhtml/methods/ideal.xml index e90502514af..39b7b842b6e 100644 --- a/etc/adminhtml/methods/ideal.xml +++ b/etc/adminhtml/methods/ideal.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_ideal/days_before_expire 1 diff --git a/etc/adminhtml/methods/kbc.xml b/etc/adminhtml/methods/kbc.xml index 944e22a909a..8ce1e7148e3 100644 --- a/etc/adminhtml/methods/kbc.xml +++ b/etc/adminhtml/methods/kbc.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_kbc/days_before_expire 1 diff --git a/etc/adminhtml/methods/klarnapaylater.xml b/etc/adminhtml/methods/klarnapaylater.xml index d6d109532c1..9a81fe4dae1 100644 --- a/etc/adminhtml/methods/klarnapaylater.xml +++ b/etc/adminhtml/methods/klarnapaylater.xml @@ -118,7 +118,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_klarnapaylater/days_before_expire 1 diff --git a/etc/adminhtml/methods/klarnapaynow.xml b/etc/adminhtml/methods/klarnapaynow.xml index bf541e48336..e7a219a17a7 100644 --- a/etc/adminhtml/methods/klarnapaynow.xml +++ b/etc/adminhtml/methods/klarnapaynow.xml @@ -118,7 +118,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_klarnapaynow/days_before_expire 1 diff --git a/etc/adminhtml/methods/klarnasliceit.xml b/etc/adminhtml/methods/klarnasliceit.xml index 6132a8256a0..05c00d60d51 100644 --- a/etc/adminhtml/methods/klarnasliceit.xml +++ b/etc/adminhtml/methods/klarnasliceit.xml @@ -118,7 +118,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_klarnasliceit/days_before_expire 1 diff --git a/etc/adminhtml/methods/mybank.xml b/etc/adminhtml/methods/mybank.xml index 07758f0057b..80dee701530 100644 --- a/etc/adminhtml/methods/mybank.xml +++ b/etc/adminhtml/methods/mybank.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_mybank/days_before_expire 1 diff --git a/etc/adminhtml/methods/paymentlink.xml b/etc/adminhtml/methods/paymentlink.xml index c75e2c71842..79110299191 100644 --- a/etc/adminhtml/methods/paymentlink.xml +++ b/etc/adminhtml/methods/paymentlink.xml @@ -155,7 +155,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_paymentlink/days_before_expire 1 diff --git a/etc/adminhtml/methods/paypal.xml b/etc/adminhtml/methods/paypal.xml index 81209aa4f4e..e956a5b2444 100644 --- a/etc/adminhtml/methods/paypal.xml +++ b/etc/adminhtml/methods/paypal.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_paypal/days_before_expire 1 diff --git a/etc/adminhtml/methods/paysafecard.xml b/etc/adminhtml/methods/paysafecard.xml index 433c5527682..cccbeb79044 100644 --- a/etc/adminhtml/methods/paysafecard.xml +++ b/etc/adminhtml/methods/paysafecard.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_paysafecard/days_before_expire 1 diff --git a/etc/adminhtml/methods/przelewy24.xml b/etc/adminhtml/methods/przelewy24.xml index e3acd1369b9..e8c70fae933 100644 --- a/etc/adminhtml/methods/przelewy24.xml +++ b/etc/adminhtml/methods/przelewy24.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_przelewy24/days_before_expire 1 diff --git a/etc/adminhtml/methods/sofort.xml b/etc/adminhtml/methods/sofort.xml index d5c725be453..a8cb14c6f1e 100644 --- a/etc/adminhtml/methods/sofort.xml +++ b/etc/adminhtml/methods/sofort.xml @@ -42,7 +42,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_sofort/days_before_expire 1 diff --git a/etc/adminhtml/methods/voucher.xml b/etc/adminhtml/methods/voucher.xml index 38f497649ea..db6a95aeed0 100644 --- a/etc/adminhtml/methods/voucher.xml +++ b/etc/adminhtml/methods/voucher.xml @@ -50,7 +50,7 @@ - validate-digits-range digits-range-1-100 + validate-digits-range digits-range-1-365 payment/mollie_methods_voucher/days_before_expire 1 diff --git a/etc/config.xml b/etc/config.xml index d3c6f92ac0b..0b36dc42d8a 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,7 +3,7 @@ - v2.3.0 + v2.4.0 0 0 test diff --git a/etc/module.xml b/etc/module.xml index 0c7b09c170b..55689b794e5 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -3,11 +3,19 @@ - - - + + + + + + + + + + +