-
-
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
Fix setting the wallet's default payment source to the same value #1888
Conversation
@@ -95,6 +95,19 @@ | |||
end | |||
end | |||
|
|||
context "with the same payment source already set to default" do | |||
let!(:wallet_credit_card) { subject.add(credit_card) } | |||
|
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.
Trailing whitespace detected.
core/app/models/spree/wallet.rb
Outdated
@@ -61,6 +61,11 @@ def default_wallet_payment_source=(wallet_payment_source) | |||
raise Unauthorized, "wallet_payment_source #{wallet_payment_source.id} does not belong to wallet of user #{user.id}" | |||
end | |||
|
|||
# Do not update the payment source if the passed source is already default | |||
if(default_wallet_payment_source.try(:id) == wallet_payment_source.id) |
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.
Space after keyword if is missing.
…set to the same value This fixes a bug where if the app tried to set the default payment method to the existing default, the wallet would end up with no default payment method
core/app/models/spree/wallet.rb
Outdated
@@ -61,6 +61,11 @@ def default_wallet_payment_source=(wallet_payment_source) | |||
raise Unauthorized, "wallet_payment_source #{wallet_payment_source.id} does not belong to wallet of user #{user.id}" | |||
end | |||
|
|||
# Do not update the payment source if the passed source is already default | |||
if default_wallet_payment_source.try(:id) == wallet_payment_source.try(:id) |
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.
What happens if both of these return nil
?
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.
It's probably better to also not use .try(:id)
. default_wallet_payment_source == wallet_payment_source
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.
If both return nil, it should signify that the system is trying to clear the default payment source (wallet_payment_source=>nil) and that the default payment source is already not set (default_wallet_payment_source=>nil). Since we just return for this case, nothing would change, which I would think is what would be wanted.
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.
@jhawthorn, made the change to not compare against the ids.
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.
👍 Looks good to me. Thanks.
I've spotted a second issue (assigning nil
errors), which I'll send a follow up PR to fix.
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!
…set to the same value
This fixes a bug where if the app tried to set the default payment method to the existing default, the wallet would end up with no default payment method