Adyen / adyen-magento2

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

[PW-6564] OpenInvoice Orders get stuck in Payment review when Capture on shipment is enabled #1467

Closed Skullsneeze closed 2 years ago

Skullsneeze commented 2 years ago

Describe the bug With the "Capture on shipment for OpenInvoice Methods" setting enabled the payments do get captured within Adyen, but get stuck in the Payment Review status in Magento.

To Reproduce Steps to reproduce the behavior:

  1. In the Adyen configuration, enable the "Capture on shipment for OpenInvoice Methods" setting (under Advanced settings > Order processing). Leave the "Use auto-capture for OpenInvoice payments" disabled.
  2. Place an order with an OpenInvoice payment method (eg. Klarna Pay Later)
  3. Wait for the Authorization notification to be processed (Order status changes to Processing)
  4. Create a shipment for the order
  5. Wait for the Capture notification to be processed
  6. The order status is changed to Payment Review and an order comment is added saying the payment will be captured after being approved in the payment gateway.

Expected behavior After the Capture notification is processed the Order status is changed to "Complete".

Magento version 2.4.2

Plugin version 8.2.1

Desktop (please complete the following information):

Additional context

The order comment that is added follows this format:

An amount of €XXX.XX will be captured after being approved at the payment gateway. Transaction ID: "XXXXXXXXXXXXXXXX-capture"

When checking the cron and notification logs I see the following:

[2022-04-20 10:44:07] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Processing notification 40 {"is_exception":false} []
[2022-04-20 10:44:07] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: {"entity_id":"40","pspreference":"XXXXXXXXXXXXX","original_reference":"XXXXXXXXXXXX","merchant_reference":"XXXXXXXXXXXX","event_code":"CAPTURE","success":"true","payment_method":"klarna","amount_value":"XXXXXXXXX","amount_currency":"EUR","live":"false","additional_data":"a:1:{s:13:\"hmacSignature\";s:44:\"XXXXXXXXXXXXXXXXXXXX\";}","done":"0","processing":true,"error_count":"0","created_at":"2022-04-20 10:42:59"} {"is_exception":false} []
[2022-04-20 10:44:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Notification 40 will be processed {"orderId":"26381","orderIncrementId":"XXXXXXXXXXXX","orderState":"payment_review","orderStatus":"payment_review","is_exception":false} []
[2022-04-20 10:44:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: amount notification:XXXXX amount order:XXXXX {"is_exception":false} []
[2022-04-20 10:44:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created comment history for this notification {"is_exception":false} []
[2022-04-20 10:44:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Updating the Adyen attributes of the order {"is_exception":false} []
[2022-04-20 10:44:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Capture mode for klarna is by default set to manual {"is_exception":false} []

After this the notification record in the DB is not updated anymore and is "stuck" with the processing flag set to 1 and the done flag set to 0

tnaber commented 2 years ago

Hi @Skullsneeze,

Thank you for opening this issue. We are experiencing more problems in our flow upon invoicing (see #1390). They might be correlated. I have opened an internal ticket and we will be investigating shortly.

Cheers, TITUS

Skullsneeze commented 2 years ago

Hi @tnaber,

Thank for the quick reply. I think this is similar but still a different issue. I would expect an order that is captured on shipment to get the status that is configured for "Order status: payment confirmed", given the tooltip for this status says the following:

Status given to orders after capture result is confirmed by an AUTHORISATION webhook (if capture mode = immediate) or a CAPTURE webhook (if capture mode = manual capture) from Adyen.

I think the issue as I currently see it is that the manual capture which is set for the OpenInvoice payments prevents the status from being changed from Payment Review

Skullsneeze commented 2 years ago

Did some debugging in the meantime, and found this error poping up during the processing of the notification:

PHP Fatal error:  Uncaught Error: Call to a member function pay() on null in vendor/magento/module-sales/Model/Order/Invoice.php:368

This means the payment can not be retrieved from the order for some reason. Will continue looking into this on my end as well and will share any updates here

jordanvector commented 2 years ago

@tnaber has there been any progress issue? This issue is a blocker for us moving to the latest version of the adyen module.

tnaber commented 2 years ago

Hi @jordanvector,

I will increase the priority and pick this up next sprint (next week).

Cheers, Titus