Skip to content
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

Conversation

vassalloandrea
Copy link
Contributor

@vassalloandrea vassalloandrea commented Oct 12, 2018

Ref: #2652

Update:

After some consideration with @tvdeyen

With this PR we want to separate the add_to_wallet behavior from the make_default one to help if someone wants to change only the make_default logic without overriding the add_to_wallet.

How it works

Now the add_to_wallet method calls the make_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 the make_default method.

E.g.: #2913 (comment)

Copy link
Member

@tvdeyen tvdeyen left a 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.

@kennyadsl
Copy link
Member

kennyadsl commented Oct 12, 2018

@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.

@tvdeyen
Copy link
Member

tvdeyen commented Oct 12, 2018

I think you are right but we are already storing the credit card in the database

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.

@kennyadsl
Copy link
Member

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?

@tvdeyen
Copy link
Member

tvdeyen commented Oct 15, 2018

What about a class that each store can customize?

Why not replace add_payment_sources_to_wallet_class with your custom code in your stores config?

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

@kennyadsl
Copy link
Member

I think this is a great solution @tvdeyen, thanks!

@vassalloandrea vassalloandrea force-pushed the last_payment_source_as_default_for_user_wallet branch from 774691f to 38b18f9 Compare December 12, 2018 16:00
@vassalloandrea vassalloandrea changed the title Add configuration to settle the last payment source as default Add make_default method on AddPaymentSourcesToWallet class Dec 12, 2018
@vassalloandrea vassalloandrea changed the title Add make_default method on AddPaymentSourcesToWallet class Add make_default method on AddPaymentSourcesToWallet class Dec 12, 2018
@vassalloandrea vassalloandrea force-pushed the last_payment_source_as_default_for_user_wallet branch from 38b18f9 to 44e5e20 Compare December 13, 2018 15:48
Copy link
Contributor

@jacobherrington jacobherrington left a 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

Copy link
Member

@tvdeyen tvdeyen left a 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.

@vassalloandrea vassalloandrea force-pushed the last_payment_source_as_default_for_user_wallet branch from 44e5e20 to 48dd2fe Compare June 14, 2019 14:06
@vassalloandrea
Copy link
Contributor Author

Hey @tvdeyen, I made the changes 👍

Copy link
Member

@tvdeyen tvdeyen left a 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)

@vassalloandrea vassalloandrea force-pushed the last_payment_source_as_default_for_user_wallet branch from 48dd2fe to 3f9a3ed Compare January 31, 2020 14:48
@aldesantis
Copy link
Member

@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.
@vassalloandrea vassalloandrea force-pushed the last_payment_source_as_default_for_user_wallet branch from 3f9a3ed to 27fb811 Compare February 7, 2020 10:08
@aldesantis aldesantis merged commit eadd9d8 into solidusio:master Feb 7, 2020
@aldesantis
Copy link
Member

Thanks @vassalloandrea!

@AlessioRocco AlessioRocco deleted the last_payment_source_as_default_for_user_wallet branch February 13, 2020 16:21
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Nov 1, 2021
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.
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Oct 31, 2022
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Nov 1, 2022
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Nov 3, 2022
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
RyanofWoods added a commit to nebulab/solidus that referenced this pull request Dec 21, 2022
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Jan 16, 2023
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Jan 17, 2023
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Jan 17, 2023
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Jan 27, 2023
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
RyanofWoods added a commit to RyanofWoods/solidus that referenced this pull request Feb 9, 2023
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
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.

None yet

5 participants