Skip to content

Commit

Permalink
Merge pull request #371 from mollie/1.24.0
Browse files Browse the repository at this point in the history
1.24.0
  • Loading branch information
Marvin-Magmodules authored Mar 22, 2021
2 parents 7691c14 + 32cd274 commit a807f1d
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 43 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -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: './'
9 changes: 7 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Model/Methods/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -116,4 +117,4 @@ public function isAvailable(CartInterface $quote = null)

return parent::isAvailable($quote);
}
}
}
34 changes: 22 additions & 12 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions Service/Mollie/MethodParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Mollie;

use Magento\Quote\Api\Data\CartInterface;
use Mollie\Payment\Service\Mollie\Parameters\ParameterPartInterface;

class MethodParameters
{
/**
* @var ParameterPartInterface[]
*/
private $parametersParts;

/**
* @param ParameterPartInterface[] $parametersParts
*/
public function __construct(array $parametersParts)
{
$this->parametersParts = $parametersParts;
}

public function enhance(array $parameters, CartInterface $cart): array
{
foreach ($this->parametersParts as $parametersPart) {
$parameters = $parametersPart->enhance($parameters, $cart);
}

return $parameters;
}
}
19 changes: 19 additions & 0 deletions Service/Mollie/Parameters/ParameterPartInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Mollie\Parameters;

use Magento\Quote\Api\Data\CartInterface;

interface ParameterPartInterface
{
/**
* @param array $parameters
* @param CartInterface|null $cart
* @return array
*/
public function enhance(array $parameters, CartInterface $cart): array;
}
4 changes: 2 additions & 2 deletions Service/Order/PaymentReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -119,4 +119,4 @@ private function isAlreadySend(OrderInterface $order): bool
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion Test/Integration/Model/Methods/AbstractMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testThatTheMethodIsActive()

$mollieApiClient = $this->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, [
Expand Down
2 changes: 1 addition & 1 deletion Test/Integration/Model/Methods/ApplePayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down
11 changes: 11 additions & 0 deletions Test/Integration/Model/Methods/VoucherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
79 changes: 79 additions & 0 deletions Test/Integration/Service/Mollie/MethodParameterPartTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Mollie;

use Magento\Quote\Api\Data\CartInterface;
use Mollie\Payment\Service\Mollie\Parameters\ParameterPartInterface;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class MethodParametersTest extends IntegrationTestCase
{
const DEFAULT_INPUT = [
'amount[value]' => 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);
}
}
Loading

0 comments on commit a807f1d

Please sign in to comment.