Skip to content

Commit

Permalink
Bugfix: Use payment link expiry date when no method for expiry is found
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jul 16, 2024
1 parent ca64e77 commit 21e5d6f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 9 additions & 5 deletions Service/Mollie/Order/IsPaymentLinkExpired.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct(

public function execute(OrderInterface $order): bool
{
$methodCode = $this->methodCode->execute($order);
$this->methodCode->getExpiresAtMethod();
$this->methodCode->execute($order);
$methodCode = $this->methodCode->getExpiresAtMethod();
if (!$this->expires->availableForMethod($methodCode, $order->getStoreId())) {
return $this->checkWithDefaultDate($order);
}
Expand All @@ -51,11 +51,15 @@ public function execute(OrderInterface $order): bool
return $expiresAt < $order->getCreatedAt();
}

/**
* Default for when no expiry date is set on the chosen method.
*/
private function checkWithDefaultDate(OrderInterface $order): bool
{
$date = $this->timezone->scopeDate($order->getStoreId());
$date = $date->add(new \DateInterval('P28D'));
$now = $this->timezone->scopeDate($order->getStoreId());
$orderDate = $this->timezone->scopeDate($order->getStoreId(), $order->getCreatedAt());
$diff = $now->diff($orderDate);

return $date->format('Y-m-d H:i:s') < $order->getCreatedAt();
return $diff->days >= 28;
}
}
1 change: 1 addition & 0 deletions Service/Order/MethodCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private function paymentLinkMethod(OrderInterface $order): string
}

if (!is_array($additionalInformation['limited_methods']) || count($additionalInformation['limited_methods']) !== 1) {
$this->expiresAtMethod = 'paymentlink';
return '';
}

Expand Down
33 changes: 29 additions & 4 deletions Test/Integration/Service/Mollie/Order/IsPaymentLinkExpiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testIsValidTheDayBeforeTheDefaultExpire(): void

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P28D'))->setTime(0, 0, 0);
$order->setcreatedAt($date->format('Y-m-d H:i:s'));
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$instance = $this->objectManager->create(IsPaymentLinkExpired::class);

Expand All @@ -42,7 +42,7 @@ public function testIsInvalidTheDayAfterTheDefaultExpire(): void

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P29D'))->setTime(23, 59, 59);
$order->setcreatedAt($date->format('Y-m-d H:i:s'));
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$instance = $this->objectManager->create(IsPaymentLinkExpired::class);

Expand All @@ -61,7 +61,7 @@ public function testIsValidWhenAvailableForMethodIsSetTheDayBefore(): void

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P9D'))->setTime(0, 0, 0);
$order->setcreatedAt($date->format('Y-m-d H:i:s'));
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$order->getPayment()->setAdditionalInformation(['limited_methods' => ['ideal']]);

Expand All @@ -82,12 +82,37 @@ public function testIsValidWhenAvailableForMethodIsSetTheDayAfter(): void

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P11D'))->setTime(23, 59, 59);
$order->setcreatedAt($date->format('Y-m-d H:i:s'));
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$order->getPayment()->setAdditionalInformation(['limited_methods' => ['ideal']]);

$instance = $this->objectManager->create(IsPaymentLinkExpired::class);

$this->assertTrue($instance->execute($order));
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoConfigFixture default_store payment/mollie_methods_paymentlink/days_before_expire 10
*/
public function testUsesPaymentlinkForExpiryWhenNoLimitedMethodsAreSet(): void
{
$order = $this->loadOrder('100000001');
$order->getPayment()->setMethod(Paymentlink::CODE);
$order->getPayment()->setAdditionalInformation(['limited_methods' => null]);

$instance = $this->objectManager->create(IsPaymentLinkExpired::class);

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P9D'))->setTime(23, 59, 59);
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$this->assertFalse($instance->execute($order));

$date = new \DateTimeImmutable();
$date = $date->add(new \DateInterval('P11D'))->setTime(23, 59, 59);
$order->setCreatedAt($date->format('Y-m-d H:i:s'));

$this->assertTrue($instance->execute($order));
}
}

0 comments on commit 21e5d6f

Please sign in to comment.