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
108 stars 76 forks source link

Check only active duplicated quote_id #1120

Closed kionez closed 2 years ago

kionez commented 2 years ago

What I expected \ Steps to reproduce the issue

  1. Add some products in cart
  2. Try to pay with another payment gateway wich restores quote on fail
  3. Return to magento with cart restored
  4. Pay with AmazonPay
  5. Complete order

What happened instead

When the point 2 fails, the payment gateway (i.e. easynolo/axerve-ecommerce-solutions, but many other works in the same way) cancel the current order and restores the quote, creating a duplicate. When AmazonPay's module checks for duplicated quote_id with canSubmitQuote, it fails reporting an error to customer and placing an open transaction without order_id on sellerscentral.

My proposed solution

As reported in https://github.com/amzn/amazon-payments-magento-2-plugin/issues/1107#issuecomment-1081549618 I think that the canSubmitQuote method in Model/CheckoutSessionManagement.php don't work well with other payment gateway which restores quote after failing.

I think that the module should check for active duplicate quote_id only, excluding canceled ones, so I'm testing a solution excluding canceled order from duplicated quote_id count adding: ->addFieldToFilter('status', ['neq' => \Magento\Sales\Model\Order::STATE_CANCELED]); to canSubmitQuote query. I write a new module which overrides the method and seems working fine, but I prefer to have an official confirmation that my idea is a good one and as I don't have much experience with the quote mechanism, there is probably a better solution :)

Your setup

kionez commented 2 years ago

I do a quick search between some other payment modules, many of them use restoreQuote() from session object to restore the old quote after failed payment, keeping the same quote_id in user's session

sgabhart22 commented 2 years ago

Hello @kionez ,

Just wanted to touch base with you again and let you know we are planning a minor release before the general availability of Magento 2.4.4 next week, and I believe we currently intend to include this fix. If anything changes I'll let you know, thanks again for the contribution!

Spencer

zichicc commented 2 years ago

issue solved by https://github.com/amzn/amazon-payments-magento-2-plugin/releases/tag/5.12.0

Please reopen if you still experience this issue.

Thanks a lot Best

Christian