Skip to content

Commit

Permalink
Bugfix: Only check if the order can be re-ordered when the payment li…
Browse files Browse the repository at this point in the history
…nk is expired mollie#795
  • Loading branch information
michielgerritsen committed Aug 7, 2024
1 parent ca64e77 commit d317f69
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Service/Magento/PaymentLinkRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function execute(string $orderId): PaymentLinkRedirectResult
]);
}

if ($this->isPaymentLinkExpired->execute($order) || !$order->canReorder()) {
if ($this->isPaymentLinkExpired->execute($order)) {
return $this->paymentLinkRedirectResultFactory->create([
'redirectUrl' => null,
'isExpired' => true,
Expand Down
76 changes: 76 additions & 0 deletions Test/Integration/Service/Magento/PaymentLinkRedirectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Test\Integration\Service\Magento;

use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Magento\PaymentLinkRedirect;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class PaymentLinkRedirectTest extends IntegrationTestCase
{
public function testThrowsExceptionWhenOrderDoesNotExists(): void
{
$this->expectException(\Magento\Framework\Exception\NotFoundException::class);

$encryptor = $this->objectManager->get(EncryptorInterface::class);
$orderId = base64_encode($encryptor->encrypt('random string'));

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

$instance->execute($orderId);
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
*
* @return void
*/
public function testDoesNotRedirectWhenOrderAlreadyPaid(): void
{
$order = $this->loadOrder('100000001');
$order->setState(Order::STATE_PROCESSING);

$encryptor = $this->objectManager->get(EncryptorInterface::class);
$orderId = base64_encode($encryptor->encrypt($order->getEntityId()));

/** @var PaymentLinkRedirect $instance */
$instance = $this->objectManager->create(PaymentLinkRedirect::class);
$result = $instance->execute($orderId);

$this->assertTrue($result->isAlreadyPaid());
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
*
* @return void
*/
public function testDoesNotRedirectWhenExpired(): void
{
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);

$order = $this->loadOrder('100000001');
$order->setState(Order::STATE_PENDING_PAYMENT);
$order->setCreatedAt(date('Y-m-d H:i:s', strtotime('-31 days')));
$orderRepository->save($order);

$encryptor = $this->objectManager->get(EncryptorInterface::class);
$orderId = base64_encode($encryptor->encrypt($order->getEntityId()));

/** @var PaymentLinkRedirect $instance */
$instance = $this->objectManager->create(PaymentLinkRedirect::class);
$result = $instance->execute($orderId);

$this->assertTrue($result->isExpired());
}
}

0 comments on commit d317f69

Please sign in to comment.