16
16
use Magento \Sales \Api \OrderRepositoryInterface ;
17
17
use Mollie \Payment \Helper \General as MollieHelper ;
18
18
use Mollie \Payment \Model \Mollie as MollieModel ;
19
+ use Mollie \Payment \Service \OrderLockService ;
19
20
20
21
/**
21
22
* Class Webhook
@@ -50,31 +51,27 @@ class Webhook extends Action
50
51
* @var EncryptorInterface
51
52
*/
52
53
private $ encryptor ;
53
-
54
54
/**
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
63
56
*/
57
+ private $ orderLockService ;
58
+
64
59
public function __construct (
65
60
Context $ context ,
66
61
Session $ checkoutSession ,
67
62
MollieModel $ mollieModel ,
68
63
MollieHelper $ mollieHelper ,
69
64
OrderRepositoryInterface $ orderRepository ,
70
- EncryptorInterface $ encryptor
65
+ EncryptorInterface $ encryptor ,
66
+ OrderLockService $ orderLockService
71
67
) {
72
68
$ this ->checkoutSession = $ checkoutSession ;
73
69
$ this ->resultFactory = $ context ->getResultFactory ();
74
70
$ this ->mollieModel = $ mollieModel ;
75
71
$ this ->mollieHelper = $ mollieHelper ;
76
72
$ this ->orderRepository = $ orderRepository ;
77
73
$ this ->encryptor = $ encryptor ;
74
+ $ this ->orderLockService = $ orderLockService ;
78
75
parent ::__construct ($ context );
79
76
}
80
77
@@ -99,6 +96,14 @@ public function execute()
99
96
}
100
97
101
98
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
+
102
107
$ order ->setMollieTransactionId ($ transactionId );
103
108
$ this ->mollieModel ->processTransactionForOrder ($ order , 'webhook ' );
104
109
}
0 commit comments