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

Spree::Wallet & Non credit card payment sources #1707

Merged

Conversation

chrisradford
Copy link
Contributor

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:

This is an attempt to update Solidus to fully support non-credit-card payment sources, and to make that easier to do it also introduces the concept of Spree::Wallet (see the code comments in wallet.rb for a summary of that class).

What else is needed for this to be merged? Assuming this is still desirable.

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.

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_sources 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)
Copy link
Member

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'

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Member

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


# Find the default WalletPaymentSource for this wallet, if any.
# @return [WalletPaymentSource]
def default
Copy link
Member

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

Copy link
Contributor Author

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

# 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)
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 }
Copy link
Member

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

@@ -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
Copy link
Member

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
Copy link
Member

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?

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

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. 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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks!

Copy link
Contributor

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

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.

Go

@jordan-brough jordan-brough changed the title Non credit card payment sources Spree::Wallet & Non credit card payment sources Mar 1, 2017
@jordan-brough jordan-brough force-pushed the non-credit-card-payment-sources branch from 0d88ab1 to 0e00b48 Compare March 10, 2017 12:29
jordan-brough and others added 17 commits March 10, 2017 06:50
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
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
@jordan-brough jordan-brough force-pushed the non-credit-card-payment-sources branch 2 times, most recently from ff2d5f6 to d6e9585 Compare March 10, 2017 14:24
peterberkenbosch and others added 13 commits March 10, 2017 09:12
- 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
@jordan-brough jordan-brough force-pushed the non-credit-card-payment-sources branch from 28edc9a to c0329e0 Compare March 10, 2017 16:33
@jordan-brough jordan-brough merged commit 7289efd into solidusio:master Mar 13, 2017
@jordan-brough jordan-brough deleted the non-credit-card-payment-sources branch March 13, 2017 11:15
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.

5 participants