Skip to content

[PIMAG-691] Bugfix: Limit methods for Payments API too #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ public function startTransaction(OrderInterface $order, $mollieApi)
$orderData['payment']['dueDate'] = $this->mollieHelper->getBanktransferDueDate($storeId);
}

if (isset($additionalData['limited_methods'])) {
$orderData['method'] = $additionalData['limited_methods'];
}

if ($this->expires->availableForMethod($this->methodCode->getExpiresAtMethod(), $storeId)) {
$orderData['expiresAt'] = $this->expires->atDateForMethod(
$this->methodCode->getExpiresAtMethod(),
Expand Down
28 changes: 28 additions & 0 deletions Service/Order/TransactionPart/LimitedMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Service\Order\TransactionPart;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Service\Order\TransactionPartInterface;

class LimitedMethods implements TransactionPartInterface
{
public function process(OrderInterface $order, $apiMethod, array $transaction): array
{
$additionalData = $order->getPayment()->getAdditionalInformation();

if (!array_key_exists('limited_methods', $additionalData) || !$additionalData['limited_methods']) {
return $transaction;
}

$transaction['method'] = $additionalData['limited_methods'];

return $transaction;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Test\Integration\Service\Order\TransactionPart;

use Mollie\Payment\Service\Order\TransactionPart\LimitedMethods;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class LimitedMethodsTest extends IntegrationTestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testSetsTheLimitedMethodsWhenValid(): void
{
$order = $this->loadOrderById('100000001');
$order->getPayment()->setAdditionalInformation('limited_methods', ['ideal', 'bancontact']);

/** @var LimitedMethods $instance */
$instance = $this->objectManager->create(LimitedMethods::class);

$result = $instance->process($order, 'orders', ['method' => 'creditcard']);

$this->assertArrayHasKey('method', $result);
$this->assertEquals(['ideal', 'bancontact'], $result['method']);
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testDoesNothingWhenTheValueIsEmpty(): void
{
$order = $this->loadOrderById('100000001');
$order->getPayment()->setAdditionalInformation('limited_methods', rand(0, 1) == 1 ? null : '');

/** @var LimitedMethods $instance */
$instance = $this->objectManager->create(LimitedMethods::class);

$result = $instance->process($order, 'orders', ['method' => 'creditcard']);

$this->assertEquals('creditcard', $result['method']);
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testDoesNothingWhenNotSet(): void
{
$order = $this->loadOrderById('100000001');

/** @var LimitedMethods $instance */
$instance = $this->objectManager->create(LimitedMethods::class);

$result = $instance->process($order, 'orders', ['method' => 'creditcard']);

$this->assertEquals('creditcard', $result['method']);
}
}
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<item name="CaptureMode" xsi:type="object">Mollie\Payment\Service\Order\TransactionPart\CaptureMode</item>
<item name="terminalId" xsi:type="object">Mollie\Payment\Service\Order\TransactionPart\TerminalId</item>
<item name="LimitStreetLength" xsi:type="object">Mollie\Payment\Service\Order\TransactionPart\LimitStreetLength</item>
<item name="LimitedMethods" xsi:type="object">Mollie\Payment\Service\Order\TransactionPart\LimitedMethods</item>
</argument>
</arguments>
</type>
Expand Down
Loading