mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
100 stars 53 forks source link

Order fallback in webhooks does not always work as expected #630

Closed lphilippo closed 1 year ago

lphilippo commented 1 year ago

Describe the bug

We encountered an odd case that seems related to the webhook improvements of release 2.20.0 Validate webhook by order id(s) as fallback.

With this version we have (very) incidental orders where the Mollie Transaction ID is not (yet) set on the order. This is a situation that the order fallback mechanism of 2.20.0 should resolve, however, if we understand those changes correctly.

After debugging, we were able to solve our issues in Mollie\Payment\Model\Mollie::processTransactionForOrder. At the start of this method, $order->getMollieTransactionId(); returns the correct ID (which is being set in the Webhook controller, just prior to calling processTransactionForOrder), but inside the closure of $this->orderLockService->execute, this same method calls returns an empty value. The empty value then causes the payment lookup to fail.

The underlying cause is that $this->orderLockService->execute performs a fresh database load of the Order model, and thereby overwriting (again) the transaction ID that was set in the controller, back to an empty value.

As a temporarily hotfix, we added the following lines inside the closure, to simply re-add the missing transaction ID for now:

// Start hotfix
if (empty($order->getMollieTransactionId())) {
    $order->setMollieTransactionId($transactionId);
}
// End hotfix.

This results in having a successful webhook process, including setting the Mollie transaction ID on the order. A better place to fix this, once confirmed, might be the orderLockService itself.

We're aware that this hopefully is an edge case, but following the intended logic of the webhook with the order fallback, we think the current behaviour is not what's expected.

Used versions Magento 2.4.5 Open source Mollie version number 2.23.0

joachimVT commented 1 year ago

I don't know if this is related but we are facing similar issues. Customer pays, webhook is successfully called, yet the status from the order is stated as 'Canceled' in Magento. Screenshots: screenshot-1 screenshot-1 screenshot-3

Used versions Magento 2.4.5 Open source Mollie version number 2.20.1

Frank-Magmodules commented 1 year ago

Hi @joachimVT and @lphilippo , we are happy that we have caught this issue within the new 2.25.0 release and now make sure the transaction ID keeps set on the order. Thank you for bringing this to our attention.

We will mark this issue as resolved for now, but if you have any further questions or concerns, please don’t hesitate to reopen the issue or contact us for additional assistance.