Skip to content

Conversation

@d-kochnov-optimus
Copy link

In some cases, orders may not be placed for various reasons.

Magento 2 relies on compensating actions rather than a database transaction to roll back payment operations. If an error occurs during order placement, the framework (and more specifically, the payment module) catches the exception and triggers the appropriate cancellation logic. This typically involves calling a void, cancel, or refund method on the payment gateway via the payment adapter, ensuring that payments already authorized or captured are reversed externally. This design allows external payment processes—which may be slow or have their own integrity constraints—to be managed independently from the database operations, aligning with Magento 2 best practices.

It seems that your module does not handle errors related to order placement and does not attempt to cancel payments in these cases.

I have prepared a PR for the case when the order placement process was interrupted by an error, but the order (as well as the payment, transaction, invoice) had not yet been saved in the database. The plugin attempts to perform a refund in this case (we use the authorize and capture option for payments). The scenario with payments under the authorize scheme needs to be handled differently, using void transactions. This still needs to be implemented since, in its current form, the transaction status is not stored anywhere, and it is necessary either to store the transaction status in additional payment model information or to retrieve the transaction data in the canVoid and canRefund magento methods so that they take into account the current transaction status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants