Skip to content

Commit 90ca417

Browse files
Bugfix: Do not process locked order to prevent timeouts
1 parent f2fd09a commit 90ca417

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

Controller/Checkout/Webhook.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Sales\Api\OrderRepositoryInterface;
1717
use Mollie\Payment\Helper\General as MollieHelper;
1818
use Mollie\Payment\Model\Mollie as MollieModel;
19+
use Mollie\Payment\Service\OrderLockService;
1920

2021
/**
2122
* Class Webhook
@@ -50,31 +51,27 @@ class Webhook extends Action
5051
* @var EncryptorInterface
5152
*/
5253
private $encryptor;
53-
5454
/**
55-
* Webhook constructor.
56-
*
57-
* @param Context $context
58-
* @param Session $checkoutSession
59-
* @param MollieModel $mollieModel
60-
* @param MollieHelper $mollieHelper
61-
* @param OrderRepositoryInterface $orderRepository
62-
* @param EncryptorInterface $encryptor
55+
* @var OrderLockService
6356
*/
57+
private $orderLockService;
58+
6459
public function __construct(
6560
Context $context,
6661
Session $checkoutSession,
6762
MollieModel $mollieModel,
6863
MollieHelper $mollieHelper,
6964
OrderRepositoryInterface $orderRepository,
70-
EncryptorInterface $encryptor
65+
EncryptorInterface $encryptor,
66+
OrderLockService $orderLockService
7167
) {
7268
$this->checkoutSession = $checkoutSession;
7369
$this->resultFactory = $context->getResultFactory();
7470
$this->mollieModel = $mollieModel;
7571
$this->mollieHelper = $mollieHelper;
7672
$this->orderRepository = $orderRepository;
7773
$this->encryptor = $encryptor;
74+
$this->orderLockService = $orderLockService;
7875
parent::__construct($context);
7976
}
8077

@@ -99,6 +96,14 @@ public function execute()
9996
}
10097

10198
foreach ($orders as $order) {
99+
// If this returns true, it means that the order is just created but did go straight to "paid".
100+
// That can happen for Apple Pay and Credit Card. In that case, Mollie immediately sends a webhook,
101+
// but we are not ready to process it yet.
102+
if ($this->orderLockService->isLocked($order)) {
103+
$this->mollieHelper->addTolog('info', 'Order is locked, skipping webhook');
104+
continue;
105+
}
106+
102107
$order->setMollieTransactionId($transactionId);
103108
$this->mollieModel->processTransactionForOrder($order, 'webhook');
104109
}

Service/OrderLockService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545

4646
public function execute(OrderInterface $order, callable $callback)
4747
{
48-
$key = 'mollie.order.' . $order->getEntityId();
48+
$key = $this->getKeyName($order);
4949
if ($this->lockService->checkIfIsLockedWithWait($key)) {
5050
throw new LocalizedException(__('Unable to get lock for %1', $key));
5151
}
@@ -85,4 +85,16 @@ public function execute(OrderInterface $order, callable $callback)
8585

8686
return $result;
8787
}
88+
89+
public function isLocked(OrderInterface $order): bool
90+
{
91+
$key = $this->getKeyName($order);
92+
93+
return $this->lockService->isLocked($key);
94+
}
95+
96+
private function getKeyName(OrderInterface $order): string
97+
{
98+
return 'mollie.order.' . $order->getEntityId();
99+
}
88100
}

0 commit comments

Comments
 (0)