magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

[Issue] Fix offline invoice capture (404) #39298

Open m2-assistant[bot] opened 4 weeks ago

m2-assistant[bot] commented 4 weeks ago

This issue is automatically created based on existing pull request: magento/magento2#39297: Fix offline invoice capture (404)


Description (*)

It's not possible to capture offline payment method invoices via the backend ('Capture' button). Trying it will lead to a 404.

Related Pull Requests

The issue comes from https://github.com/magento/magento2/commit/3e637056d1031185c7c8989f7a24302cecb5b27b#diff-f55a86b611d11bb9a801c4b16ba9ac4b17dab4c325d252b86d5d3a8b8275c291

The class has been changed to be implementing HttpPostActionInterface. Clicking the 'Capture' button will send a GET request. Magento's request validator \Magento\Framework\App\Request\HttpMethodValidator will throw an exception leading to a 404 because it expects a POST request.

Manual testing scenarios (*)

  1. create an order with an offline payment method
  2. create an invoice for the order (offline)
  3. capture the invoice
m2-assistant[bot] commented 4 weeks ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 4 weeks ago

Hi @nige-one,

Thanks for your reporting and collaboration.

We have tried to reproduce the issue in Latest 2.4-develop instance and we are not able to proceed further.Could you please elaborate the steps regarding Capture the invoice in Magento Backend.

Screenshot 2024-10-25 at 10 41 29

Thanks.

nige-one commented 4 weeks ago

Hi @engcom-Bravo thanks for checking. I missed that Magento's default offline payment methods do not allow to capture. We implemented a simple custom offline payment method with:

    protected $_canCapture = true;

This allows our merchant to track payments for manually managed payments (bank transfer).

I see that \Magento\Payment\Model\Method\AbstractMethod is marked as deprecated, propably based on the decision to move towards \Magento\Payment\Model\MethodInterface and its Adapter abstract implementation. But most (?) of the vanilla payment methods still rely on the AbstractMethod heavily.

Nonetheless, since the rendered 'Capture' button in the backend will always be a GET request: https://github.com/magento/magento2/blob/5a2037c35de89ce2c50e230164ff3ea7b67ac127/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php#L135 and https://github.com/magento/magento2/blob/5a2037c35de89ce2c50e230164ff3ea7b67ac127/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php#L232

the mentioned commit https://github.com/magento/magento2/commit/3e637056d1031185c7c8989f7a24302cecb5b27b#diff-f55a86b611d11bb9a801c4b16ba9ac4b17dab4c325d252b86d5d3a8b8275c291 will always break the button functionality.

One could argue to implement a "Paid" button for a custom offline payment method instead of the "Capture" one, but this will still render the "Capture" button useless anyway.

So, from my perspective this is a breaking change.

m2-assistant[bot] commented 2 weeks ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 1 week ago

Hello @nige-one,

Thanks for the detailed explanation!

We agree your point, hence confirming this issue after looking into the code changes.

Thanks

github-jira-sync-bot commented 1 week ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13336 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 week ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.