MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Orders jumping from processing to pending_payment #56

Closed jdereus87 closed 11 months ago

jdereus87 commented 11 months ago

Describe the bug On a rare occasion some of the orders jump from Processing back to Pending_Payment. Result is that the merchant does not properly process a customer payment and the order gets cancelled after 2 weeks leaving the payment in limbo.

To Reproduce It is very hard to reproduce.

Stack Magento 2.4.5-p1 MSP 2.21.1

Screenshots https://pasteboard.co/wYMYNmRLaKhK.png

Additional context This seems to look a lot like the bug that was fixed in 2.19.0: Fixed an issue where the order state switches to 'Pending payment' after 'Completed' in rare cases

I could update the MSP to its newest version, but judging by the change log I am not sure if this one is fixed yet. If you want anymore info i could plage a few log lines on relevant places. If so, let me know where / which files you want them. Also please let me know the recommended steps to proceed with this bug, should I update or should I wait untill this is sorted?

vinodsowdagar commented 11 months ago

Hi @jdereus87 ,

Thank you for the report.

It seems that there is another process which is putting the order back into pending_payment after our module has set it to processing. So the first thing to do would be to figure out which process this is. We have also improved our webhook process from version 3.0.0 and up. So if it is possible, upgrading to the latest version could also help.

Could you turn on the debug mode inside the MultiSafepay General Settings and when the issue happens again, send us the MultiSafepay logs?

Please send it to us at integration@multisafepay.com and refer to this Github issue.

bmelman commented 11 months ago

We have seen this happening too (currently at 2.21.0). Luckily duplicate warehouse imports failed so they were not shipped multiple times(!). We never found a source for these events setting orders back from processing to pending.

hostep commented 11 months ago

Not sure if this is helpful, but we had a similar issue happening a couple of months ago, and indeed at first we suspected the MultiSafepay module to be the problem, but after searching for a long time, we eventually found it was due to a custom module we wrote.

That module had a cronjob that ran every minute and that fetched a list of orders from the database based on some condition, looped over it, set some flag on it and saved the order objects one by one.

But there was a race condition happening occasionally:

This happened rarely, but still a couple of times per week, but that's because the shop has a loooot of orders coming in, which increases the chance of this happening. If you have a small amount of orders, the chance of this happening will be a lot less.

We eventually fixed it in our custom module, by not saving the full order object, but only the attribute value itself. We based our fix a bit on this change from core magento.

Anyway, it could be something completely else in your cases, but I'm just mentioning it as it's not always the payment module itself that's the cause of such strange problems.

jdereus87 commented 11 months ago

@Vinod-MultiSafepay Check. Thank you for thinking along. I will update the module first and see if the problem still persists. I will also turn on the MSP debug mode afterwards (I assume this turns on more extensive logging). You are right that this might not be the MSP module as a cause, but from the context it seemed similar to what was fixed in 2.19.

@bmelman Thank you for your confirmation. If I find the cause and/or a solution I will let you know. I did want to compare our stacks a bit if that is alright with you. The webshop that is experiencing the problem is a global multistore. It is using MSP primarily, but it does have some other PSPs that it is using for some outlier payment methods / direct methods:

While not a module, it uses picqer for its shipment fulfillment.

@hostep Thank your for the advice. I was focused on modules that used the setState() function on the order object. But as you rightfully pointed out, it might be just an unlucky timed save on the order object.

In general I think I might build a module based on the after order save event / (change state event?) that logs the Increment ID and a stack trace to identify this issue. When its done I will link it here.

vinodsowdagar commented 11 months ago

Hi @jdereus87 ,

We have a module which helps us debug these type of issues, maybe it can be of help for you too: https://github.com/MultiSafepay/magento2-order-save-inspector

We've made successful discoveries like this one with it: https://github.com/dhlparcel/plugin-magento2-release/issues/59

If you are feeling that you are not progressing further, please contact our integration team at integration@multisafepay.com to check how we can help you further.

jdereus87 commented 11 months ago

@Vinod-MultiSafepay

Great. Thanks! That saves me the time of building it myself.

I updated the MSP module to its newest version. I will see if the problem persists. If so I will add the order save inspector to figure out what is messing with the order status and let you know. For now I will close this issue.

Thanks again