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

Wrong payment method assigned to order if a different payment method is attempted first #1147

Closed gavinlimely closed 1 year ago

gavinlimely commented 1 year ago

After attempting an order with Checkout.com first, then changing to pay with Amazon pay instead. I expected the order to have amazon_payment_v2 stored in the method column of the sales_order_payment table. However checkoutcom_card_payment was stored instead.

The transaction went through as it should and the correct Amazon pay metadata was stored in the additional_information column, however the wrong payment method is displayed on the admin screen & the order confirmation email.

I think this is down to line 764-766 in Amazon\Pay\Model\CheckoutSessionManagement. I think if the empty check was removed, then this would work as expected.

sgabhart22 commented 1 year ago

Hello @gavinlimely ,

This is an interesting thought, and I could see how some checkout flows may not call /set-payment-information when the method is selected... Out of curiosity, are you using a One-Step Checkout extension, other third-party checkout extension, or a customized checkout experience? The standard Magento checkout should set payment method on the quote when the method's radio button is clicked, except on some older versions (< 2.3.4, I believe).

I don't think the proposed change should have any negative impact on performance or functionality; the quote's already been fetched, no harm setting the payment method code again even if it's already set correctly. We'll review this a little further but I think removing the empty() check on the payment method should be just fine. We may just update that comment to indicate more clearly why the method code is being set again.

Thanks for raising the issue! Spencer

gavinlimely commented 1 year ago

Hi @sgabhart22

No this is just the standard Magento checkout. It only seems to happen if a customer attempts a different payment method before choosing Amazon. We're using Magento 2.4.5-p1

Perhaps you could change the empty check to: if($payment->getMethod() !== Config::Code) ?

Thanks

sgabhart22 commented 1 year ago

Hello again @gavinlimely ,

That's interesting, I'm unable to reproduce that on 2.4.5-p1... Nonetheless, I think what you're suggesting is perfectly fine. Ensuring the correct payment method code is set on the quote before placing the order is inexpensive and could save confusion in the future.

If you'd like, you're welcome to create a PR including this change for an upcoming release. We wouldn't merge that directly, but we would cherry pick your commit into our release branch so you'd receive credit for the contribution. Either way, we'll still note this issue and make sure the change is included in an upcoming release.

Thanks again for looking into this! Spencer