From e3c1aaa1ef760875d27bec480e6e26f72f48ff7a Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 15 Mar 2021 12:37:35 +0100 Subject: [PATCH 1/6] Feature: Allow to change the method request parameters --- Model/MollieConfigProvider.php | 34 +++++--- Service/Mollie/MethodParameters.php | 35 ++++++++ .../Parameters/ParameterPartInterface.php | 19 +++++ .../Model/Methods/AbstractMethodTest.php | 2 +- .../Model/Methods/ApplePayTest.php | 2 +- .../Mollie/MethodParameterPartTest.php | 79 +++++++++++++++++++ Test/Unit/Model/MollieConfigProviderTest.php | 5 +- etc/di.xml | 6 ++ 8 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 Service/Mollie/MethodParameters.php create mode 100644 Service/Mollie/Parameters/ParameterPartInterface.php create mode 100644 Test/Integration/Service/Mollie/MethodParameterPartTest.php diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 38108fe6030..51739a85715 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -20,6 +20,7 @@ use Mollie\Payment\Helper\General as MollieHelper; use Mollie\Payment\Model\Mollie as MollieModel; use Mollie\Payment\Service\Mollie\GetIssuers; +use Mollie\Payment\Service\Mollie\MethodParameters; /** * Class MollieConfigProvider @@ -101,19 +102,25 @@ class MollieConfigProvider implements ConfigProviderInterface */ private $storeManager; + /** + * @var MethodParameters + */ + private $methodParameters; + /** * MollieConfigProvider constructor. * - * @param Mollie $mollieModel - * @param MollieHelper $mollieHelper - * @param PaymentHelper $paymentHelper - * @param CheckoutSession $checkoutSession - * @param AssetRepository $assetRepository - * @param Escaper $escaper - * @param Resolver $localeResolver - * @param Config $config - * @param GetIssuers $getIssuers + * @param Mollie $mollieModel + * @param MollieHelper $mollieHelper + * @param PaymentHelper $paymentHelper + * @param CheckoutSession $checkoutSession + * @param AssetRepository $assetRepository + * @param Escaper $escaper + * @param Resolver $localeResolver + * @param Config $config + * @param GetIssuers $getIssuers * @param StoreManagerInterface $storeManager + * @param MethodParameters $methodParameters */ public function __construct( MollieModel $mollieModel, @@ -125,7 +132,8 @@ public function __construct( Resolver $localeResolver, Config $config, GetIssuers $getIssuers, - StoreManagerInterface $storeManager + StoreManagerInterface $storeManager, + MethodParameters $methodParameters ) { $this->mollieModel = $mollieModel; $this->mollieHelper = $mollieHelper; @@ -137,6 +145,8 @@ public function __construct( $this->localeResolver = $localeResolver; $this->getIssuers = $getIssuers; $this->storeManager = $storeManager; + $this->methodParameters = $methodParameters; + foreach ($this->methodCodes as $code) { $this->methods[$code] = $this->getMethodInstance($code); } @@ -230,13 +240,13 @@ public function getActiveMethods($mollieApi, CartInterface $cart = null) try { $amount = $this->mollieHelper->getOrderAmountByQuote($cart); - $params = [ + $parameters = [ 'amount[value]' => $amount['value'], 'amount[currency]' => $amount['currency'], 'resource' => 'orders', 'includeWallets' => 'applepay', ]; - $apiMethods = $mollieApi->methods->all($params); + $apiMethods = $mollieApi->methods->allActive($this->methodParameters->enhance($parameters, $cart)); foreach ($apiMethods as $method) { $methodId = 'mollie_methods_' . $method->id; diff --git a/Service/Mollie/MethodParameters.php b/Service/Mollie/MethodParameters.php new file mode 100644 index 00000000000..503b9fa59ee --- /dev/null +++ b/Service/Mollie/MethodParameters.php @@ -0,0 +1,35 @@ +parametersParts = $parametersParts; + } + + public function enhance(array $parameters, CartInterface $cart): array + { + foreach ($this->parametersParts as $parametersPart) { + $parameters = $parametersPart->enhance($parameters, $cart); + } + + return $parameters; + } +} diff --git a/Service/Mollie/Parameters/ParameterPartInterface.php b/Service/Mollie/Parameters/ParameterPartInterface.php new file mode 100644 index 00000000000..1e077ce36ab --- /dev/null +++ b/Service/Mollie/Parameters/ParameterPartInterface.php @@ -0,0 +1,19 @@ +createMock(MollieApiClient::class); $mollieApiClient->methods = $this->createMock(MethodEndpoint::class); - $mollieApiClient->methods->method('all')->willReturn($methodCollection); + $mollieApiClient->methods->method('allActive')->willReturn($methodCollection); /** @var MollieConfigProvider $instance */ $instance = $this->objectManager->create(MollieConfigProvider::class, [ diff --git a/Test/Integration/Model/Methods/ApplePayTest.php b/Test/Integration/Model/Methods/ApplePayTest.php index 957db48c5ee..487e517682d 100644 --- a/Test/Integration/Model/Methods/ApplePayTest.php +++ b/Test/Integration/Model/Methods/ApplePayTest.php @@ -25,7 +25,7 @@ public function testTheIncludeWalletsParameterIsUsed() $mollieApiClient = $this->createMock(MollieApiClient::class); $mollieApiClient->methods = $this->createMock(MethodEndpoint::class); - $mollieApiClient->methods->expects($this->once())->method('all')->with($this->callback(function ($arguments) { + $mollieApiClient->methods->expects($this->once())->method('allActive')->with($this->callback(function ($arguments) { $this->assertArrayHasKey('includeWallets', $arguments); $this->assertEquals('applepay', $arguments['includeWallets']); diff --git a/Test/Integration/Service/Mollie/MethodParameterPartTest.php b/Test/Integration/Service/Mollie/MethodParameterPartTest.php new file mode 100644 index 00000000000..c454d149530 --- /dev/null +++ b/Test/Integration/Service/Mollie/MethodParameterPartTest.php @@ -0,0 +1,79 @@ + 10, + 'amount[currency]' => 'EUR', + 'resource' => 'orders', + 'includeWallets' => 'applepay', + ]; + + public function testChangesNothingWhenNoPartsAreConfigured() + { + /** @var MethodParameters $instance */ + $instance = $this->objectManager->create(MethodParameters::class, ['parametersParts' => []]); + + $result = $instance->enhance(static::DEFAULT_INPUT, $this->objectManager->create(CartInterface::class)); + + $this->assertEquals(static::DEFAULT_INPUT, $result); + } + + public function testTheParametersCanBeAdjusted() + { + $part = new class() implements ParameterPartInterface { + public function enhance(array $parameters, CartInterface $cart): array + { + return $parameters + ['test' => true]; + } + }; + + /** @var MethodParameters $instance */ + $instance = $this->objectManager->create(MethodParameters::class, ['parametersParts' => [ + 'testPart' => $part, + ]]); + + $result = $instance->enhance(static::DEFAULT_INPUT, $this->objectManager->create(CartInterface::class)); + + $this->assertEquals(static::DEFAULT_INPUT + ['test' => true], $result); + } + + public function testSupportsMultipleParameterParts() + { + $part1 = new class() implements ParameterPartInterface { + public function enhance(array $parameters, CartInterface $cart): array + { + return $parameters + ['test1' => true]; + } + }; + + $part2 = new class() implements ParameterPartInterface { + public function enhance(array $parameters, CartInterface $cart): array + { + return $parameters + ['test2' => true]; + } + }; + + /** @var MethodParameters $instance */ + $instance = $this->objectManager->create(MethodParameters::class, [ + 'parametersParts' => [ + 'test1' => $part1, + 'test2' => $part2, + ] + ]); + + $result = $instance->enhance(static::DEFAULT_INPUT, $this->objectManager->create(CartInterface::class)); + + $this->assertEquals(static::DEFAULT_INPUT + ['test1' => true, 'test2' => true], $result); + } +} diff --git a/Test/Unit/Model/MollieConfigProviderTest.php b/Test/Unit/Model/MollieConfigProviderTest.php index 23833e18e82..7247dc0fa25 100644 --- a/Test/Unit/Model/MollieConfigProviderTest.php +++ b/Test/Unit/Model/MollieConfigProviderTest.php @@ -5,6 +5,7 @@ use Mollie\Payment\Helper\General; use Mollie\Payment\Model\MollieConfigProvider; use Mollie\Payment\Test\Unit\UnitTestCase; +use Magento\Quote\Model\Quote; class MollieConfigProviderTest extends UnitTestCase { @@ -16,7 +17,7 @@ public function testCallsTheApiOnlyOnce() $mollieHelperMock->method('getOrderAmountByQuote')->willReturn(['value' => 100, 'currency' => 'EUR']); $methodsEndpointMock = $this->createMock(\Mollie\Api\Endpoints\MethodEndpoint::class); - $methodsEndpointMock->expects($this->once())->method('all')->willReturn([ + $methodsEndpointMock->expects($this->once())->method('allActive')->willReturn([ (object)[ 'id' => 'ideal', 'image' => (object)[ @@ -31,7 +32,7 @@ public function testCallsTheApiOnlyOnce() 'mollieHelper' => $mollieHelperMock, ]); - $result = $instance->getActiveMethods($client); + $result = $instance->getActiveMethods($client, $this->objectManager->getObject(Quote::class)); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('mollie_methods_ideal', $result); $this->assertEquals('ideal.svg', $result['mollie_methods_ideal']['image']); diff --git a/etc/di.xml b/etc/di.xml index 9a7df838aba..ba5c514f3a6 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -175,4 +175,10 @@ + + + + + + From 9267f4616f0c1d765b446a8bbbc228ccd5fe3720 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 22 Mar 2021 08:37:21 +0100 Subject: [PATCH 2/6] Feature: Lint PHP files in all supported versions --- .github/workflows/linting.yml | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/linting.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 00000000000..609744ce8cf --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,38 @@ +name: Lint PHP files +on: push + +jobs: + php-70: + runs-on: ubuntu-latest + steps: + - uses: StephaneBour/actions-php-lint@7.0 + with: + dir: './' + + php-71: + runs-on: ubuntu-latest + steps: + - uses: StephaneBour/actions-php-lint@7.1 + with: + dir: './' + + php-72: + runs-on: ubuntu-latest + steps: + - uses: StephaneBour/actions-php-lint@7.2 + with: + dir: './' + + php-73: + runs-on: ubuntu-latest + steps: + - uses: StephaneBour/actions-php-lint@7.3 + with: + dir: './' + + php-74: + runs-on: ubuntu-latest + steps: + - uses: StephaneBour/actions-php-lint@7.4 + with: + dir: './' From 5717ab0ced144e18f2ed5a4530fce2694a970acf Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 22 Mar 2021 09:27:43 +0100 Subject: [PATCH 3/6] Bugfix: A return type of void would throw an error on PHP 7.0 --- Service/Order/PaymentReminder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/Order/PaymentReminder.php b/Service/Order/PaymentReminder.php index d1b045cbc06..5e78bb29573 100644 --- a/Service/Order/PaymentReminder.php +++ b/Service/Order/PaymentReminder.php @@ -91,7 +91,7 @@ public function send(PendingPaymentReminderInterface $pendingPaymentReminder): O return $order; } - private function moveReminderFromPendingToSent(OrderInterface $order, PendingPaymentReminderInterface $pendingPaymentReminder): void + private function moveReminderFromPendingToSent(OrderInterface $order, PendingPaymentReminderInterface $pendingPaymentReminder) { if ($this->isAlreadySend($order)) { // Already sent, so delete the pending payment reminder. @@ -119,4 +119,4 @@ private function isAlreadySend(OrderInterface $order): bool return false; } } -} \ No newline at end of file +} From 6a49612821e86d5db1962fe730f38c1611011cc6 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 22 Mar 2021 09:34:45 +0100 Subject: [PATCH 4/6] Bugfix: The Voucher IsAvailable method could be called without a quote but that would fail --- Model/Methods/Voucher.php | 5 +++-- Test/Integration/Model/Methods/VoucherTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Model/Methods/Voucher.php b/Model/Methods/Voucher.php index 7e987fdbd2e..d1014a8a159 100644 --- a/Model/Methods/Voucher.php +++ b/Model/Methods/Voucher.php @@ -104,7 +104,8 @@ public function __construct( public function isAvailable(CartInterface $quote = null) { - $voucherCategory = $this->config->getVoucherCategory($quote->getStoreId()); + $storeId = $quote ? $quote->getStoreId() : null; + $voucherCategory = $this->config->getVoucherCategory($storeId); if ($quote && !$voucherCategory) { return false; } @@ -116,4 +117,4 @@ public function isAvailable(CartInterface $quote = null) return parent::isAvailable($quote); } -} \ No newline at end of file +} diff --git a/Test/Integration/Model/Methods/VoucherTest.php b/Test/Integration/Model/Methods/VoucherTest.php index 35a2a94186d..53441494117 100644 --- a/Test/Integration/Model/Methods/VoucherTest.php +++ b/Test/Integration/Model/Methods/VoucherTest.php @@ -48,4 +48,15 @@ public function testIsAvailableWhenTheCategoryIsSet() $instance = $this->objectManager->create(Voucher::class); $this->assertTrue($instance->isAvailable($cart)); } + + /** + * @magentoConfigFixture default_store payment/mollie_methods_voucher/category + */ + public function testIsAvailableWhenNoCategoryIsAvailable() + { + /** @var Voucher $instance */ + $instance = $this->objectManager->create(Voucher::class); + + $this->assertFalse($instance->isAvailable(null)); + } } From e90834b978a0b9bd7b53c47887dcf12b3811c688 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 22 Mar 2021 09:10:50 +0100 Subject: [PATCH 5/6] Feature: Magento versions used in the CI pipeline updated --- .github/workflows/integration-test.yml | 10 +++------- .github/workflows/phpstan.yml | 9 +++++++-- .github/workflows/setup-di-compile.yml | 14 +++++++------- .github/workflows/unit-test.yml | 10 +++++----- phpstan.neon | 2 ++ 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 96d0776c2d0..78748403fc0 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -11,16 +11,12 @@ jobs: MAGENTO_VERSION: 2.2.11 - PHP_VERSION: php71-fpm MAGENTO_VERSION: 2.2.11 - - PHP_VERSION: php71-fpm - MAGENTO_VERSION: 2.3.4 - - PHP_VERSION: php72-fpm - MAGENTO_VERSION: 2.3.4 - PHP_VERSION: php73-fpm - MAGENTO_VERSION: 2.3.4 + MAGENTO_VERSION: 2.3.6-p1 - PHP_VERSION: php73-fpm - MAGENTO_VERSION: 2.4.0 + MAGENTO_VERSION: 2.4.2 - PHP_VERSION: php74-fpm - MAGENTO_VERSION: 2.4.0 + MAGENTO_VERSION: 2.4.2 runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 8d380454e60..0d5c71565c3 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -6,8 +6,13 @@ jobs: build: strategy: matrix: - PHP_VERSION: [php71-fpm, php72-fpm] - MAGENTO_VERSION: [2.3.5-p1] + include: + - PHP_VERSION: php71-fpm + MAGENTO_VERSION: 2.3.5-p1 + - PHP_VERSION: php72-fpm + MAGENTO_VERSION: 2.3.5-p1 + - PHP_VERSION: php74-fpm + MAGENTO_VERSION: 2.4.2 runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/setup-di-compile.yml b/.github/workflows/setup-di-compile.yml index 72f658608a4..9118b1c28df 100644 --- a/.github/workflows/setup-di-compile.yml +++ b/.github/workflows/setup-di-compile.yml @@ -6,13 +6,13 @@ jobs: build: strategy: matrix: - PHP_VERSION: [php7-fpm, php71-fpm, php72-fpm] - MAGENTO_VERSION: [2.2.11, 2.3.5-p1] - exclude: - - PHP_VERSION: php7-fpm - MAGENTO_VERSION: 2.3.5-p1 - - PHP_VERSION: php72-fpm - MAGENTO_VERSION: 2.2.11 + include: + - PHP_VERSION: php7-fpm + MAGENTO_VERSION: 2.2.11 + - PHP_VERSION: php72-fpm + MAGENTO_VERSION: 2.3.6-p1 + - PHP_VERSION: php74-fpm + MAGENTO_VERSION: 2.4.2 runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5540f939306..4be90f8e546 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -11,15 +11,15 @@ jobs: - PHP_VERSION: php71-fpm MAGENTO_VERSION: 2.2.11 - PHP_VERSION: php71-fpm - MAGENTO_VERSION: 2.3.4 + MAGENTO_VERSION: 2.3.6-p1 - PHP_VERSION: php72-fpm - MAGENTO_VERSION: 2.3.4 + MAGENTO_VERSION: 2.3.6-p1 - PHP_VERSION: php73-fpm - MAGENTO_VERSION: 2.3.4 + MAGENTO_VERSION: 2.3.6-p1 - PHP_VERSION: php73-fpm - MAGENTO_VERSION: 2.4.0 + MAGENTO_VERSION: 2.4.2 - PHP_VERSION: php74-fpm - MAGENTO_VERSION: 2.4.0 + MAGENTO_VERSION: 2.4.2 runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/phpstan.neon b/phpstan.neon index 748ec2efea1..f6487485b53 100755 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,11 @@ parameters: level: 1 + reportUnmatchedIgnoredErrors: false ignoreErrors: # Not applicable on level 1 # - '#Call to an undefined method [a-zA-Z0-9\\_]+::(get|set|uns|has|calc|unset)[A-Z]#' - '#Variable \$block might not be defined.#' + - '#Undefined variable: \$block#' fileExtensions: - php - phtml From 32cd2743235702bef854774ea90354a27f5dd284 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 22 Mar 2021 14:51:47 +0100 Subject: [PATCH 6/6] Version bump --- composer.json | 2 +- etc/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c49d2c11821..37d2ae247e0 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.23.1", + "version": "1.24.0", "keywords": [ "mollie", "payment", diff --git a/etc/config.xml b/etc/config.xml index d2d40e06a94..c2be4f0ce55 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,7 +3,7 @@ - v1.23.1 + v1.24.0 0 0 test