forked from mollie/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Only check if the order can be re-ordered when the payment li…
…nk is expired mollie#795
- Loading branch information
1 parent
ca64e77
commit d317f69
Showing
2 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
Test/Integration/Service/Magento/PaymentLinkRedirectTest.php
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
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()); | ||
} | ||
} |