Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dimitriBouteille opened this issue Oct 22, 2024 · 2 comments · Fixed by #2796
Closed

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

dimitriBouteille opened this issue Oct 22, 2024 · 2 comments · Fixed by #2796
Assignees
Labels
Bug report Indicates that issue has been marked as a possible bug

Comments

@dimitriBouteille
Copy link
Contributor

dimitriBouteille commented Oct 22, 2024

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 :

  • On the test environment, if the client goes to /adyen/return twice, the page /checkout/success is displayed the second time.
  • On the production env, if the customer clicks Cancel payment, the success page is displayed.

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, ...

private function isResponseAlreadyProcessed(Order $order, array $paymentsDetailsResponse): bool
{
$pspReference = $paymentsDetailsResponse['pspReference'] ?? null;
$merchantReference = $paymentsDetailsResponse['merchantReference'] ?? null;
if (!$pspReference || !$merchantReference) {
return false;
}
$history = $order->getStatusHistories();
foreach ($history as $status) {
$comment = $status->getComment();
if (str_contains($comment, $pspReference) !== false) {
return true;
}
}
return false;

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

Here is what happens globally :

  • First call to /adyen/return
  • Save order history with PSP reference
  • validateRedirectResponse return false
  • Redirect to /cart with error
  • Second call to /adyen/return
  • isResponseAlreadyProcessed returns true because the PSP reference exist in order comment history
  • validateRedirectResponse returns true
  • Redirect to /checkout/success with canceled error -_-

To Reproduce

In testing environment :

  • Place order with Twint method
  • Cancel payment
  • /checkout/cart page is displayed with error (payment canceled)
  • Call /adyen/return with same arguments
  • /checkout/success is displayed with error (payment canceled)

In production environment :

  • Place order with Twint method
  • Click on Cancel payment in Twint interface
  • /checkout/success is displayed with error (payment canceled)

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

@dimitriBouteille dimitriBouteille added the Bug report Indicates that issue has been marked as a possible bug label Oct 22, 2024
@candemiralp candemiralp changed the title Success page displayed if payment is canceled [ECP-9534] Success page displayed if payment is canceled Oct 28, 2024
@candemiralp
Copy link
Member

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
Copy link
Contributor

Hey @dimitriBouteille,

Here is the related PR - #2796
Closing the issue.

Regards!
Khushboo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug report Indicates that issue has been marked as a possible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants