solidus icon indicating copy to clipboard operation
solidus copied to clipboard

AddPaymentSourcesToWallet "randomly" changing the default

Open adammathys opened this issue 5 years ago • 2 comments

As of the introduction of #2913, we no longer set the default payment to one that was used on the current order. Instead, we implicitly pick the one with the biggest ID from all sources in a user's wallet. This can result in inconsistent behaviour where placing an order will change the default payment from the one the customer used and/or the one a customer has explicitly set as their default.

Solidus Version: v2.11+

To Reproduce

  1. Add two payment sources to a users wallet. Make the one with the smallest ID the default payment source.
  2. Complete checkout using the default payment source.

Current behavior After placing an order with the default payment source, the default will be changed to the wallet source with the largest ID. (Because order.user.wallet_payment_sources.last should implicitly order by ID.) Meaning we changed the user's default payment source without them ever selecting the new default.

Expected behavior Based on previous behaviour, default payment source should be unchanged after placing the order. (Given the steps used to reproduce.)

adammathys avatar Mar 22 '21 20:03 adammathys

Am I misunderstanding that the previous behaviour was for the reusable source on the order with the highest ID would previously have been selected as the default. That's how I'm reading this.

jarednorman avatar Mar 22 '21 22:03 jarednorman

Correct, the previous behaviour would be to pick the source with the largest Spree::Source#id that was part of a valid payment on that order.

The new logic instead picks the wallet source with the largest Spree::WalletPaymentSource#id from all of the sources in the wallet.

adammathys avatar Mar 22 '21 22:03 adammathys