mollie / magento2

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

[BUG] - POS device shows wrong payment state/outcome - magento webhook endpoint response too slow? #729

Closed nh-mdev closed 8 months ago

nh-mdev commented 10 months ago

Describe the bug Sometimes when paying via the POS system, the POS device shows a "X - Payment failed" message screen.
Even though checking the payment itself from within the mollie dashboard shows that it was successfully paid - it has the status "Paid".

Used versions

To Reproduce Steps to reproduce the behavior: This can be tricky to reproduce, since it's probably a timing issue and we are not 100 % sure why this happens.

  1. Setup an order via POS payment method.
  2. Pay via the POS device.
  3. POS device shows "payment in progress".
  4. Shortly after, POS device shows "X - Payment failed".
  5. Check mollie dashboard - it says payment was successful.
  6. If no error on the POS device shows up, try steps 1-5 with an artifical delay within the webhook logic.

We were able to consistently reproduce it from our side, by calling the magento webhook synchronous and then sending the "OK" response to mollie > results in "X - Payment failed".

When we instantly send mollie the "OK" response for the webhook request, the POS device works as expected and shows "Payment successful". In this flow, we dispatch an extra job to handle the request towards magentos mollie webhook endpoint in an async way.

Expected behavior Expected the POS device to correctly display the progress/state of the payment.

Actual behavior See above descriptions.

Additional context We already had the chance to discuss this issue with @fjbender when he was visiting us at our offices.
He suggested, that this issue might be related to magentos slow webhook endpoint response time.

fjbender commented 9 months ago

Thanks for the detailed write-up of the issue! I would generalize it as "Webhook response slow", which indeed is something we see within our Magento crowd occasionally.

Would you be able to profile a webhook call using e.g. Blackfire?

Frank-Magmodules commented 9 months ago

Hello @nh-mdev, appreciate you bringing up this issue! I've had a chat on this with our team to think about this issue from a Magento perspective but we don't have any additional input to provide beyond @fjbender comment. Thanks!

fjbender commented 9 months ago

Due to operational constraints on our end, we needed to introduce a bit less tolerance for slow webhooks. We need to come to a solution here, even if only for POS payments.

@Frank-Magmodules I feel like we're running a lot of expensive database lookups in both Mollie\Payment\Controller\Checkout\Webhook (https://github.com/mollie/magento2/blob/0f727ba196015529458799df95d18959d83e7a82/Controller/Checkout/Webhook.php#L81) and subsequently Mollie\Payment\Model\Mollie::processTransactionForOrder (https://github.com/mollie/magento2/blob/0f727ba196015529458799df95d18959d83e7a82/Model/Mollie.php#L349). Do you see any room for optimization there, even without having an exact profile of the cost of the operations?

Frank-Magmodules commented 9 months ago

Hello @fjbender! I understand your point, and we'll look into it!

Frank-Magmodules commented 8 months ago

HI There @nh-mdev ,

Once again thank you for opening this issue. We took a deep dive into this and came up with a solution for this: We have implemented a way to process the webhooks in the background in our latest release. As this is a big change, we have put this behind a feature flag.

If you want to enable this then you can do that under Stores -> Configuration -> Mollie -> Advanced -> Triggers & Languages -> Process transactions in the queue. Once we have enough feedback on this feature this will become the default.

I'm closing this issue for now, but please feel free to comment or reopen it if necessary.