Adyen / adyen-magento2

Adyen Payment plugin for Magento2
MIT License
155 stars 211 forks source link

[ECP-9534] Success page displayed if payment is canceled #2777

Closed dimitriBouteille closed 3 weeks ago

dimitriBouteille commented 1 month ago

Hello !

There is a small bug with the payment method Twint with classic magento - I have not tested with the other methods - in headless integration (graphql) no problem :

Capture d’écran du 2024-10-22 10-57-05

The problem between the two environments is slightly different but the source is the same: the function Adyen\Payment\Controller\Return\Index::validateRedirectResponse().

validateRedirectResponse :

When calling the /adyen/return for the first time, this function returns false.

On the second call, there is a check using the isResponseAlreadyProcessed function to verify whether the payment has already been processed or not. The problem is that isResponseAlreadyProcessed returns true.

The isResponseAlreadyProcessed function is based on the order history to know if the reference PSP reference exists in the comments. On the second call, there is a comment with the PSP reference and returns true without checking if the payment is valid, canceled, ...

https://github.com/Adyen/adyen-magento2/blob/e3af5ed622fce24d449cf0be3373071c3d59a8c3/Controller/Return/Index.php#L198-L216

Capture d’écran 2024-10-22 à 11 17 21

Here is what happens globally :

To Reproduce

In testing environment :

In production environment :

Between the production and test env, there is a difference since on the production environment Twint or Adyen makes two calls to /adyen/return, I do not know why:( Here is an example of the logs in production :

[2024-10-17T10:12:24.531466+00:00] AdyenLoggerTest.ADYEN_RESULT: Processing redirect response Ctx|[]| Extra|{"uid":"2a8c72f"}|
[2024-10-17T10:12:25.108650+00:00] AdyenLoggerTest.ADYEN_RESULT: Updating the order Ctx|[]| Extra|{"uid":"2a8c72f"}|
[2024-10-17T10:12:25.170563+00:00] AdyenLoggerTest.ADYEN_RESULT: The order cannot be cancelled Ctx|[]| Extra|{"uid":"2a8c72f"}|
[2024-10-17T10:12:25.298058+00:00] AdyenLoggerTest.ADYEN_RESULT: /vendor/adyen/module-payment/Controller/Return/Index.php Ctx|{"result":false,"HTTP_REFERER":"https://pay.twint.ch/"}| Extra|{"uid":"2a8c72f"}|
[2024-10-17T10:12:25.378610+00:00] AdyenLoggerTest.ADYEN_RESULT: Payment for order 25000147608 was unsuccessful, it will be cancelled when the OFFER_CLOSED notification has been processed. Ctx|[]| Extra|{"uid":"2a8c72f"}|
[2024-10-17T10:12:27.556453+00:00] AdyenLoggerTest.ADYEN_RESULT: Processing redirect response Ctx|[]| Extra|{"uid":"f685fca"}|
[2024-10-17T10:12:27.959283+00:00] AdyenLoggerTest.ADYEN_RESULT: Duplicate response detected. Skipping processing. Ctx|[]| Extra|{"uid":"f685fca"}|
[2024-10-17T10:12:27.959642+00:00] AdyenLoggerTest.ADYEN_RESULT: /vendor/adyen/module-payment/Controller/Return/Index.php Ctx|{"result":true,"HTTP_REFERER":"https://pay.twint.ch/"}| Extra|{"uid":"f685fca"}|

Expected behavior

If customer cancel payment, page /checkout/cart must be displayed in all cases with error (e.g: Payment canceled).

Magento version

2.4.5-p10

Plugin version

9.8.0

candemiralp commented 4 weeks ago

Hello @dimitriBouteille,

Thank you for creating this issue. We will fix that issue as a part of our internal ticket ECP-9534 together with #2775.

Best Regards, Can

khushboo-singhvi commented 3 weeks ago

Hey @dimitriBouteille,

Here is the related PR - https://github.com/Adyen/adyen-magento2/pull/2796 Closing the issue.

Regards! Khushboo