-
-
Save Frank-Magmodules/3ff3e2f466cd4aa937dd06f948258046 to your computer and use it in GitHub Desktop.
Patch for issue https://github.com/mollie/magento2/issues/718
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Model/Client/Orders.php b/Model/Client/Orders.php | |
index 608cde8f..82acaf41 100644 | |
--- a/Model/Client/Orders.php | |
+++ b/Model/Client/Orders.php | |
@@ -261,8 +261,11 @@ public function startTransaction(OrderInterface $order, $mollieApi) | |
$orderData['method'] = $additionalData['limited_methods']; | |
} | |
- if ($this->expires->availableForMethod($method, $storeId)) { | |
- $orderData['expiresAt'] = $this->expires->atDateForMethod($method, $storeId); | |
+ if ($this->expires->availableForMethod($this->methodCode->getExpiresAtMethod(), $storeId)) { | |
+ $orderData['expiresAt'] = $this->expires->atDateForMethod( | |
+ $this->methodCode->getExpiresAtMethod(), | |
+ $storeId | |
+ ); | |
} | |
$orderData = $this->buildTransaction->execute($order, static::CHECKOUT_TYPE, $orderData); | |
diff --git a/Service/Order/MethodCode.php b/Service/Order/MethodCode.php | |
index 10b2b0b0..c61232c8 100644 | |
--- a/Service/Order/MethodCode.php | |
+++ b/Service/Order/MethodCode.php | |
@@ -12,21 +12,37 @@ | |
class MethodCode | |
{ | |
+ /** | |
+ * @var string | |
+ */ | |
+ private $expiresAtMethod = ''; | |
+ | |
public function execute(OrderInterface $order): string | |
{ | |
$method = $order->getPayment()->getMethodInstance()->getCode(); | |
+ $this->expiresAtMethod = $method; | |
if ($method == 'mollie_methods_paymentlink') { | |
return $this->paymentLinkMethod($order); | |
} | |
- if ($method == 'mollie_methods_paymentlink' || strstr($method, 'mollie_methods') === false) { | |
+ if (strstr($method, 'mollie_methods') === false) { | |
return ''; | |
} | |
return str_replace('mollie_methods_', '', $method); | |
} | |
+ /* | |
+ * From which method do we need to get the expires_at date? When a specific method is selected, we use that. | |
+ * When the payment link is used, we use the first limited method. When the payment link has multiple methods, | |
+ * we use the payment link settings to determine the expires_at date. | |
+ */ | |
+ public function getExpiresAtMethod(): string | |
+ { | |
+ return str_replace('mollie_methods_', '', $this->expiresAtMethod); | |
+ } | |
+ | |
private function paymentLinkMethod(OrderInterface $order): string | |
{ | |
$additionalInformation = $order->getPayment()->getAdditionalInformation(); | |
@@ -38,6 +54,8 @@ private function paymentLinkMethod(OrderInterface $order): string | |
return ''; | |
} | |
+ $this->expiresAtMethod = $additionalInformation['limited_methods'][0]; | |
+ | |
return str_replace('mollie_methods_', '', $additionalInformation['limited_methods'][0]); | |
} | |
} | |
diff --git a/Test/Integration/Model/Client/OrdersTest.php b/Test/Integration/Model/Client/OrdersTest.php | |
index 7d654292..e2154738 100644 | |
--- a/Test/Integration/Model/Client/OrdersTest.php | |
+++ b/Test/Integration/Model/Client/OrdersTest.php | |
@@ -154,31 +154,40 @@ protected function mollieOrderMock($status, $currency) | |
* @magentoDataFixture Magento/Sales/_files/quote.php | |
* @magentoDataFixture Magento/Sales/_files/order.php | |
* @magentoConfigFixture default_store payment/mollie_methods_ideal/days_before_expire 5 | |
+ * @magentoConfigFixture default_store payment/mollie_methods_paymentlink/days_before_expire 6 | |
* | |
* @throws \Magento\Framework\Exception\LocalizedException | |
* @throws \Mollie\Api\Exceptions\ApiException | |
+ * | |
+ * @dataProvider startTransactionIncludesTheExpiresAtParameterProvider | |
*/ | |
- public function testStartTransactionIncludesTheExpiresAtParameter() | |
- { | |
+ public function testStartTransactionIncludesTheExpiresAtParameter( | |
+ string $method, | |
+ int $days, | |
+ array $limitedMethods | |
+ ): void { | |
$cart = $this->objectManager->create(Quote::class); | |
$cart->load('test01', 'reserved_order_id'); | |
$order = $this->loadOrder('100000001'); | |
$order->setBaseCurrencyCode('EUR'); | |
$order->setQuoteId($cart->getId()); | |
- $order->getPayment()->setMethod('mollie_methods_ideal'); | |
+ $order->getPayment()->setMethod($method); | |
+ if ($limitedMethods) { | |
+ $order->getPayment()->setAdditionalInformation('limited_methods', $limitedMethods); | |
+ } | |
$mollieOrderMock = $this->createMock(\Mollie\Api\Resources\Order::class); | |
$mollieOrderMock->id = 'abc123'; | |
$mollieApiMock = $this->createMock(MollieApiClient::class); | |
$orderEndpointMock = $this->createMock(OrderEndpoint::class); | |
- $orderEndpointMock->method('create')->with( $this->callback(function ($orderData) { | |
+ $orderEndpointMock->method('create')->with( $this->callback(function ($orderData) use ($days) { | |
$this->assertArrayHasKey('expiresAt', $orderData); | |
$this->assertNotEmpty($orderData['expiresAt']); | |
$now = $this->objectManager->create(TimezoneInterface::class)->scopeDate(null); | |
- $expected = $now->add(new \DateInterval('P5D')); | |
+ $expected = $now->add(new \DateInterval('P' . $days . 'D')); | |
$this->assertEquals($expected->format('Y-m-d'), $orderData['expiresAt']); | |
@@ -195,6 +204,18 @@ public function testStartTransactionIncludesTheExpiresAtParameter() | |
$instance->startTransaction($order, $mollieApiMock); | |
} | |
+ public function startTransactionIncludesTheExpiresAtParameterProvider(): array | |
+ { | |
+ return [ | |
+ 'ideal' => | |
+ ['mollie_methods_ideal', 5, []], | |
+ 'payment link with single method should use method' => | |
+ ['mollie_methods_paymentlink', 5, ['ideal']], | |
+ 'payment link with multiple methods should use payment link' => | |
+ ['mollie_methods_paymentlink', 6, ['ideal', 'creditcard']], | |
+ ]; | |
+ } | |
+ | |
public function checksIfTheOrderHasAnUpdateProvider(): array | |
{ | |
return [ | |
diff --git a/Test/Integration/Service/Order/MethodCodeTest.php b/Test/Integration/Service/Order/MethodCodeTest.php | |
index be04f8de..b8708e67 100644 | |
--- a/Test/Integration/Service/Order/MethodCodeTest.php | |
+++ b/Test/Integration/Service/Order/MethodCodeTest.php | |
@@ -71,4 +71,48 @@ public function testReturnsPaymentLinkReturnsTheSingleLimitedMethod(): void | |
$this->assertEquals('ideal', $result); | |
} | |
+ | |
+ public function testReturnsMethodAsExpiryMethod(): void | |
+ { | |
+ $order = $this->loadOrderById('100000001'); | |
+ $order->getPayment()->setMethod('mollie_methods_ideal'); | |
+ | |
+ $instance = $this->objectManager->create(MethodCode::class); | |
+ | |
+ $instance->execute($order); | |
+ | |
+ $this->assertEquals('ideal', $instance->getExpiresAtMethod()); | |
+ } | |
+ | |
+ public function testReturnsPaymentLinkAsExpiryMethodWhenApplicable(): void | |
+ { | |
+ $order = $this->loadOrderById('100000001'); | |
+ $order->getPayment()->setMethod('mollie_methods_paymentlink'); | |
+ $order->getPayment()->setAdditionalInformation( | |
+ 'limited_methods', | |
+ ['mollie_methods_ideal', 'mollie_methods_eps'] | |
+ ); | |
+ | |
+ $instance = $this->objectManager->create(MethodCode::class); | |
+ | |
+ $instance->execute($order); | |
+ | |
+ $this->assertEquals('paymentlink', $instance->getExpiresAtMethod()); | |
+ } | |
+ | |
+ public function testReturnsMethodWhenSingleLimitedMethod(): void | |
+ { | |
+ $order = $this->loadOrderById('100000001'); | |
+ $order->getPayment()->setMethod('mollie_methods_paymentlink'); | |
+ $order->getPayment()->setAdditionalInformation( | |
+ 'limited_methods', | |
+ ['mollie_methods_ideal'] | |
+ ); | |
+ | |
+ $instance = $this->objectManager->create(MethodCode::class); | |
+ | |
+ $instance->execute($order); | |
+ | |
+ $this->assertEquals('ideal', $instance->getExpiresAtMethod()); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment