-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add make_default method on AddPaymentSourcesToWallet class #2913
Add make_default method on AddPaymentSourcesToWallet class #2913
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we should do this. Storing data on behalf of the user is a decision the user needs to do not the store owner.
Instead we should add a checkbox to the confirm page that asks the user if we should store the payment method and don’t do it if not. Currently we always store the payment method, what should not be the case in times of GDPR and friends.
@tvdeyen I think you are right but we are already storing the credit card in the database, this just changes which one is considered the default one. I think it does not change which cards are being shown to the user on the next purchase but the last one used will be preselected I think, while at the moment the preselected one is the first added. Right @vassalloandrea ? UPDATE: it's the other way around (now you can choose to select the last one as default or it will always use the first one) but they are both saved in the database anyway. |
We store the payment source used on the payment, yes, but also we store it as default payment source in the users wallet. And this should not be the case IMO unless the user wants to. They should opt-in for this. Also the additional configuration option in this PR seems to be very store specific and should not be in core IMO. What could be in core is a user account page that let the use decide which payment source that they decided to be stored is their default one. Having the store deciding this is wrong IMO. |
👍 What about a class that each store can customize? Like: Spree::Config::Wallet.default_payment_method_setter_class which by default acts exactly as the one we have in core right now? |
Why not replace Maybe it makes sense to extract the "make payment method the default one" into a method, that a store then can override? Spree.config do |config|
...
config.add_payment_sources_to_wallet_class = 'My::AddPaymentSourcesToWallet'
...
end class My::AddPaymentSourcesToWallet < Spree::Wallet::AddPaymentSourcesToWallet
def make_default
order.user.wallet.default_wallet_payment_source = wallet_payment_sources.first
end
end |
I think this is a great solution @tvdeyen, thanks! |
774691f
to
38b18f9
Compare
make_default
method on AddPaymentSourcesToWallet
class
make_default
method on AddPaymentSourcesToWallet
class
core/spec/models/spree/wallet/add_payment_sources_to_wallet_spec.rb
Outdated
Show resolved
Hide resolved
38b18f9
to
44e5e20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to wait on @tvdeyen's feedback, but I'm okay with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks. Two suggestions.
core/spec/models/spree/wallet/add_payment_sources_to_wallet_spec.rb
Outdated
Show resolved
Hide resolved
core/spec/models/spree/wallet/add_payment_sources_to_wallet_spec.rb
Outdated
Show resolved
Hide resolved
44e5e20
to
48dd2fe
Compare
Hey @tvdeyen, I made the changes 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
@kennyadsl I actually lost track of this one. Where are we with the feature to ask the user if they actually want to store the payment source in the wallet? This is a feature we should provide (especially in times of GDPR)
core/spec/models/spree/wallet/add_payment_sources_to_wallet_spec.rb
Outdated
Show resolved
Hide resolved
48dd2fe
to
3f9a3ed
Compare
@vassalloandrea there's something off with the specs. Could you take a look? |
Move the logic to make the last payment source as default outside the add_to_wallet method to take advantage if someone wants to change only the make default behavior.
3f9a3ed
to
27fb811
Compare
Thanks @vassalloandrea! |
Fixes issue solidusio#4004 [1] PR solidusio#2913 [2] changed how the new default WalletPaymentSource was set, from using the last one found/created * within the Order's PaymentSources to the user's last WalletPaymentSource. A subtle difference which assumes that the user's last WalletPaymentSource was just created by add_to_wallet. However, if the Order's PaymentSource was from the User's wallet default and add_to_wallet is called, a new WalletPaymentSource would not be created * and make_default would try to set the new default as the last WalletPaymentSource. This would change the default if the last WalletPaymentSource was not the default. Now, the WalletPaymentSources are scoped to the order's PaymentSources and the last one is given to Wallet#default_wallet_payment_source=. Meaning that in this scenario, the default would given and ignored as it is already the default. [1] solidusio#4004 [2] solidusio#2913 * Wallet#add creates or finds the WalletPaymentSource if exists.
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic in the scenario where the user uses their default WalletPaymentSource for an order, but their default source is not their most recent WalletPaymentSource. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, it means it will keep the default payment source if used. This is because wallet#add finds or creates. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic in the scenario where the user uses their default WalletPaymentSource for an order, but their default source is not their most recent WalletPaymentSource. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, it means it will keep the default payment source if used. This is because wallet#add finds or creates. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic in the scenario where the user uses their default WalletPaymentSource for an order, but their default source is not their most recent WalletPaymentSource. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, it means it will keep the default payment source if used. This is because wallet#add finds or creates. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
PR solidusio#2913 [1] changed how the new default WalletPaymentSource was set. Before: - using the last one found/created by the Order's PaymentSources After: - using the user's last WalletPaymentSource. This is problematic when an order uses a default WalletPaymentSource but it's not the most recent one. Fixes issue solidusio#4004 [2] Now, #make_default uses WalletPaymentSources found or created by the order, which means it will keep the default payment source if used. [1] solidusio#2913 [2] solidusio#4004
Ref: #2652
Update:
After some consideration with @tvdeyen
With this PR we want to separate the
add_to_wallet
behavior from themake_default
one to help if someone wants to change only themake_default
logic without overriding theadd_to_wallet
.How it works
Now the
add_to_wallet
method calls themake_default
method after adding on the user wallet the payment sources.To change the
make_default
behavior now we can create own class and override themake_default
method.E.g.: #2913 (comment)