-
-
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
Spree::Wallet & Non credit card payment sources #1707
Spree::Wallet & Non credit card payment sources #1707
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.
Overall a great improvement!
I have some concerns about naming, especially within the wallet class (I actually really love this abstraction).
I want to avoid to use wallet_payment_source
s as much as possible and rather use payment_source
for interaction with the wallet wherever we can.
Also I found some typos and incorrect deprecation usage.
Thank you for picking this up and to all other contributors to this.
CHANGELOG.md
Outdated
@@ -282,6 +282,9 @@ | |||
This was unnecessary since it didn't update the order totals, and running | |||
order.update! would recalculate the adjustments and totals again. | |||
|
|||
* Filter orders by store when more than a single store is present. [#1149](https://github.com/solidusio/solidus/pull/1140) |
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 believe this doesn't belong here. Although I think we we should add an changelog entry.
@@ -23,6 +23,8 @@ module UserMethods | |||
has_many :store_credit_events, through: :store_credits | |||
money_methods :total_available_store_credit | |||
|
|||
has_many :wallet_payment_sources, foreign_key: 'user_id', class_name: 'Spree::WalletPaymentSource' | |||
|
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.
Can these be moved into user_payment_source
module?
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.
Personally I'm not a huge fan of that module, and most of it is going away. How about the reverse - bring the has_many
from that module into here? Then the whole module goes away soon.
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.
Absolutely!
def wallet_payment_sources | ||
user.wallet_payment_sources.to_a | ||
end | ||
|
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.
Could we add another method?
def payment_sources
wallet_payment_sources.collect(&:payment_source)
end
core/app/models/spree/wallet.rb
Outdated
|
||
# Find the default WalletPaymentSource for this wallet, if any. | ||
# @return [WalletPaymentSource] | ||
def default |
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.
Can we rename this into default_payment_source
and return an actual PaymentSource
? wallet.default
sounds like getting the default wallet and we don't actually need the wallet_payment_source
object. All we want deal with is PaymentSource
s.
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.
def default_wallet_payment_source
core/app/models/spree/wallet.rb
Outdated
# It must be in the wallet already. Pass nil to clear the default. | ||
# @return [WalletPaymentSource] the associated WalletPaymentSource, or nil if clearing | ||
# the default. | ||
def default=(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.
Can we rename this into default_payment_source=
? wallet.default=
sounds like setting the default wallet.
end | ||
|
||
describe "#to_active_merchant" do | ||
context "#to_active_merchant" do |
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.
Can we leave this a describe
block?
|
||
second.update_attributes!(default: true) | ||
it 'allows this card to save even if the previously default card has expired' do |
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.
This test is identical to the previous one.
@@ -81,6 +81,10 @@ module Spree | |||
} | |||
end | |||
|
|||
around do |example| | |||
ActiveSupport::Deprecation.silence { example.run } |
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.
We don't want to silence ActiveSupport::Deprecation
but Spree::Deprecation
here
core/spec/models/spree/user_spec.rb
Outdated
@@ -92,7 +92,9 @@ | |||
end | |||
|
|||
it "has payment sources" do | |||
expect(user.payment_sources.first.gateway_customer_profile_id).not_to be_empty | |||
ActiveSupport::Deprecation.silence do |
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.
We don't want to silence ActiveSupport::Deprecation
but Spree::Deprecation
here
it { is_expected.to respond_to(:user) } | ||
end | ||
|
||
context "#can_capture?" do |
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.
Can we use a describe
block for methods?
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
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. The specs will pass, if you fix the foreign key usage in the migrations
@@ -1,7 +1,7 @@ | |||
class CreateSpreeWalletPaymentSources < ActiveRecord::Migration[4.2] | |||
def change | |||
create_table :spree_wallet_payment_sources do |t| | |||
t.references :user, index: true, null: false | |||
t.references :user, foreign_key: true |
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.
You need to pass {to_table: Spree.user_class.table_name}
to foreign_key
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.
Ah, thanks!
032a302
to
79618fc
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'm good with this, except for the commits that fix things for Rails 5 and that fix the migration's foreign key. Those should be merged with the commit that introduces the code they're fixing (this will probably also make sure all commits are green again).
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.
Go
0d88ab1
to
0e00b48
Compare
Extracted from these commits from mamhoff: - spree/spree@7f706d0 - spree/spree@a3b66ae
Based largely on this commit from mamhoff: - spree/spree@a3b66ae
To help tell whether payment sources should be saved in the Wallet or just reused in general (e.g. for unreturned exchange charges).
TODO: Use this in frontend and deprecate `existing_card_id`.
TODO: Deprecate existing_card and existing_card_id
And deprecate User#default_credit_card
For any stores using legacy payment sources that do not inherit from PaymentSource.
- Update Spree::StoreCredit to inherit from Spree::PaymentSource - Fix comment text in wallet
- Rename wallet_source#source to payment_source - Reflected the name change in the migrations
ff2d5f6
to
d6e9585
Compare
- Ensure the `payment_source` is a `Spree::PaymentSource` - Add spec for wallet_payment_source#payment_source validation - Add locale for invalid payment_source
The "inverse_of" relationship required some extra work for this
This updates the `Spree::Gateway#reusable_sources method to fetch those sources from the wallet on the user instead of only looking for credit cards. See Solidus PR 1442.
- Update the comment on the payment builder so it's clear that this will use the default source in the user's wallet. - Fix issue with more then 1 payment being created. Added back the check on payments that exist on the order with the same payment source
- Return the actual reusable payment sources - Deprecate Gateway#sources_by_order and renamed it to reusable_payment_sources to reflect the purpose of the method better
Fix deprecation warnings on calling the PaymentCreate with passing in the existing_credit_card_id. Replace that with the wallet_payment_source_id.
- Add specs for `Spree::Wallet` - Update payment spec to remove source_attributes usage
Rather than ActiveSupport::Deprecation
- And the same with the setter. - Update related specs.
…nt source And add Wallet::Unauthorized when attempting to set a default that doesn't belong to the wallet. ../core/spec/models/spree/order/checkout_spec.rb
28edc9a
to
c0329e0
Compare
This PR takes the work from #1091 and #1414 by @jordan-brough and @peterberkenbosch, rebases it over the latest
master
and updates a single failing spec (squashed into another commit).From the original PR:
What else is needed for this to be merged? Assuming this is still desirable.