Adyen / adyen-magento2

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

Swish orders wrongly updated to the Pending status from Canceled or Processing #2616

Closed marinagociulybe closed 4 months ago

marinagociulybe commented 4 months ago

Describe the bug After upgrading the Adyen module to 9.2.0 from version 8, some of the orders paid with the Swish payment method get wrongly updated back to Pending, after being in the correct states of Canceled or Processing.

To Reproduce I do not currently have a way to reproduce this, as the Swish payment method only offers a way to test the approved status. What I do see in the logs and on the order comments is:

  1. Request: /adyen/return?merchantReference=%ORDER ID%
  2. adyen/result.log: AdyenLoggerTest.ADYEN_RESULT: Updating the order
  3. Order comment:
    Adyen paymentsDetails response:
    authResult: Authorised
    pspReference: %REFERENCE%
    paymentMethod: swish
  4. Adyen notification comes in and the order is invoiced and updated to the Processing state
  5. Request: /rest/default/V1/adyen/guest-carts/%CART INFO%/payments-details -> I assume this is the request messing up with the order
  6. adyen/result.log: AdyenLoggerTest.ADYEN_RESULT: Updating the order
  7. Order comment:
    Adyen paymentsDetails response:
    authResult: Authorised
    pspReference: %REFERENCE%
    paymentMethod:
  8. This last comment also wrongly reverts the order back to Pending state

Expected behavior I expect orders to not get updated to Pending if the current status is Processing.

Magento version 8.4.6-p3

Plugin version 9.22.0

Additional context I've traced all this back to \Adyen\Payment\Helper\PaymentResponseHandler::handlePaymentsDetailsResponse when $this->orderHelper->setStatusOrderCreation($order) is called. I would expect this method to be triggered only when the order state is pending_payment, and not in the other situations. I've see the exact same behaviour with Canceled orders. They are reverted back to Pending by this method.

RokPopov commented 4 months ago

Hi @marinagociulybe,

Thank you for reporting this issue. This was fixed with this PR that was released in v9.5.1 of our plugin.

I am closing this issue for now.

Kind regards, Rok

marinagociulybe commented 4 months ago

@RokPopov, thanks for checking this! Unfortunately, I'm not sure that will solve all situations. I'm seeing this on orders where the payments were successful too. They are being reverted from Processing back into Pending. I suspect the issue is in that mentioned file, but on a different line: https://github.com/Adyen/adyen-magento2/blob/develop/Helper/PaymentResponseHandler.php#L200. The state and status of the order are changed without checking the presumption that the order is indeed in the state pending_payment.