amzn / amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
https://amzn.github.io/amazon-payments-magento-2-plugin/
Apache License 2.0
109 stars 77 forks source link

Cannot create invoice for Order Magento 2.4.5 #1199

Closed bmitchell-ldg closed 1 year ago

bmitchell-ldg commented 1 year ago

What I expected

No errors when placing orders

What happened instead

The order is invoiced, moves to processing and is captured as expected but the following error is thrown "Cannot create invoice for Order" Screenshot 2023-07-04 at 10 09 07

Steps to reproduce the issue

Place an order with the below config set and the error is thrown for every order

Your setup

Findings so far: in Charge.php the loadInvoice function doesn't return any invoices. Screenshot 2023-07-04 at 10 03 31 Screenshot 2023-07-04 at 10 07 31

The invoice exists in M2, but it doesn't have the TRANSACTION_ID associated to it at this point.

CheckoutSessionManagement.php line 768 is where the capture is made 1 2

In that capture loadInvoice is used and loadInvoice is the function filtering on TRANSACTION_ID 3

But if you go back to CheckoutSessionManagement.php the TRANSACTION_ID isn’t populated with the $chargeId until further down line 810 4 Seems like the transaction_id is being populated too late.

To make sure it wasn't a conflict caused by a custom module or 3rd party module we also disabled everything back to core Magento using the Luma theme and the error was still thrown.

lcouget commented 1 year ago

Hi @bmitchell-ldg

Thank you for reporting this issue.

We noticed that even "cannot create invoice" error message is displayed, the invoice is successfully created. Here is an example:

image-20230704-210619

image-20230704-210833

We will continue investigating the issue to avoid the appearance of this error message during payment capture process.

Thank you. Regards,

dallin-beargroup commented 1 year ago

Was able to reproduce as well. The steps to reproduce are accurate, and the issue definitely centers aroundPayment : Charge when order is placed. As noted, the order appears to be in good health with exception to the extra order comment from \Amazon\Pay\Model\AsyncManagement\Charge::capture The second order comment (not throwing err) comes from \Amazon\Pay\Model\CheckoutSessionManagement::addCaptureComment This needs further review.

sgabhart22 commented 1 year ago

Hello @bmitchell-ldg ,

Thanks again for the call out here, definitely an annoying bit of noise on order history comments if nothing else. I've done some testing with Auth & Capture ('Charge when the order is placed') and both Authorization Modes, and I believe a reasonable solution is to also check the auth mode before calling the asyncCharge function. It seems like everything behaves as expected if the auth mode is Immediate, but we only see this errant comment in Automatic mode.

The attached patch should address this reasonably, since in Automatic mode, the capture will be initiated asynchronously later if it can't be done right away anyway. Please let us know if you're able to try it out or have any different solutions!

gh1199.patch.txt

Thanks again, Spencer

bmitchell-ldg commented 1 year ago

Thank you Spencer, i will apply that patch now and let you know if it resolves the issues. Thanks, Bev

bmitchell-ldg commented 1 year ago

Hello @sgabhart22 , The patch has been applied and resolved the issue. Thanks, Bev

sgabhart22 commented 1 year ago

Great news @bmitchell-ldg ! I appreciate the patience and feedback here, we'll go ahead and close this issue for now but keep our internal ticket open for tracking. This fix (or something very similar) will likely be included in an upcoming release.

Thanks again, Spencer