diff --git a/src/Components/OrderExpiration/ExpireAction.php b/src/Components/OrderExpiration/ExpireAction.php
index 654f444db..a2888044b 100644
--- a/src/Components/OrderExpiration/ExpireAction.php
+++ b/src/Components/OrderExpiration/ExpireAction.php
@@ -3,6 +3,7 @@
namespace Kiener\MolliePayments\Components\OrderExpiration;
+use Kiener\MolliePayments\Handler\Method\BankTransferPayment;
use Kiener\MolliePayments\Repository\Order\OrderRepositoryInterface;
use Kiener\MolliePayments\Repository\SalesChannel\SalesChannelRepositoryInterface;
use Kiener\MolliePayments\Service\Order\OrderExpireService;
@@ -74,7 +75,7 @@ private function expireOrdersInSalesChannel(SalesChannelEntity $salesChannelEnti
$this->logger->info('Start expire orders for saleschannel', ['salesChannel' => $salesChannelEntity->getName()]);
$date = new \DateTime();
- $date->modify('-2 months');
+ $date->modify(sprintf('-%d days', (BankTransferPayment::DUE_DATE_MAX_DAYS + 1)));
$criteria = new Criteria();
$criteria->addAssociation('transactions.stateMachineState');
@@ -85,7 +86,9 @@ private function expireOrdersInSalesChannel(SalesChannelEntity $salesChannelEnti
$criteria->addSorting(new FieldSorting('orderDateTime', FieldSorting::DESCENDING));
$criteria->setLimit(10);
- $this->logger->debug('Search for orders with payment status in progress');
+ $this->logger->debug('Search for orders with payment status in progress older than date', [
+ 'date' => $date->format(Defaults::STORAGE_DATE_TIME_FORMAT),
+ ]);
$searchResult = $this->orderRepository->search($criteria, $context);
if ($searchResult->count() === 0) {
diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml
index fd0d003d2..c01f8c939 100644
--- a/src/Resources/config/services/services.xml
+++ b/src/Resources/config/services/services.xml
@@ -128,7 +128,9 @@
-
+
+
+
diff --git a/src/Service/Order/OrderExpireService.php b/src/Service/Order/OrderExpireService.php
index b342ae4d2..b7bd6a3ce 100644
--- a/src/Service/Order/OrderExpireService.php
+++ b/src/Service/Order/OrderExpireService.php
@@ -114,7 +114,11 @@ public function cancelExpiredOrders(OrderCollection $orders, Context $context):
$finalizeTransactionTimeInMinutes = $settings->getPaymentFinalizeTransactionTime();
if ($this->orderUsesSepaPayment($lastTransaction)) {
- $finalizeTransactionTimeInMinutes = (int)ceil($settings->getPaymentMethodBankTransferDueDateDays() / 24 / 60);
+ $bankTransferDueDays = $settings->getPaymentMethodBankTransferDueDateDays();
+ if ($bankTransferDueDays === null) {
+ $bankTransferDueDays = BankTransferPayment::DUE_DATE_MIN_DAYS;
+ }
+ $finalizeTransactionTimeInMinutes = 60 * 60 * 24 * $bankTransferDueDays;
}
if ($this->orderTimeService->isOrderAgeGreaterThan($order, $finalizeTransactionTimeInMinutes) === false) {
diff --git a/src/Service/Order/OrderTimeService.php b/src/Service/Order/OrderTimeService.php
index f1bc1c11e..2cc386715 100644
--- a/src/Service/Order/OrderTimeService.php
+++ b/src/Service/Order/OrderTimeService.php
@@ -4,8 +4,10 @@
namespace Kiener\MolliePayments\Service\Order;
use DateTime;
+use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
+use Shopware\Core\Defaults;
class OrderTimeService
{
@@ -14,9 +16,15 @@ class OrderTimeService
*/
private $now;
- public function __construct(?DateTime $now = null)
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ public function __construct(LoggerInterface $logger, ?DateTime $now = null)
{
$this->now = $now ?? new DateTime();
+ $this->logger = $logger;
}
/**
@@ -42,7 +50,7 @@ public function isOrderAgeGreaterThan(OrderEntity $order, int $minutes): bool
return false;
}
- $transitionDate = $lastTransaction->getCreatedAt();
+ $transitionDate = $lastTransaction->getUpdatedAt() ?? $lastTransaction->getCreatedAt();
if ($transitionDate === null) {
return false;
@@ -52,6 +60,13 @@ public function isOrderAgeGreaterThan(OrderEntity $order, int $minutes): bool
$diffInHours = $interval->h + ($interval->days * 24);
$diffInMinutes = $interval->i + ($diffInHours * 60);
+ $this->logger->debug('Check if order is expired', [
+ 'lastTransactionTime' => $transitionDate->format(Defaults::STORAGE_DATE_TIME_FORMAT),
+ 'now' => $this->now->format(Defaults::STORAGE_DATE_TIME_FORMAT),
+ 'diffInMinutes' => $diffInMinutes,
+ 'minutes'=>$minutes
+ ]);
+
return $diffInMinutes > $minutes;
}
}
diff --git a/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php b/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php
index e09c50c13..8b04ecb47 100644
--- a/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php
+++ b/tests/PHPUnit/Service/Order/OrderTimeServiceTest.php
@@ -6,6 +6,7 @@
use Kiener\MolliePayments\Service\Order\OrderTimeService;
use PHPUnit\Framework\TestCase;
+use Psr\Log\NullLogger;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionCollection;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
@@ -24,7 +25,7 @@ public function testDateComparisonLogic(\DateTime $now, \DateTime $orderDate, bo
{
$order = $this->orderMockWithLastTransactionTimestamp($orderDate);
- $result = (new OrderTimeService($now))->isOrderAgeGreaterThan($order, $compareValueInMinutes);
+ $result = (new OrderTimeService(new NullLogger(),$now))->isOrderAgeGreaterThan($order, $compareValueInMinutes);
$this->assertSame($expected, $result);
}