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

Rename Gateway into PaymentMethod::CreditCard #2001

Merged
merged 11 commits into from
Jun 21, 2017

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Jun 7, 2017

The Spree::Gateway is an implementation of a credit card payment method. The current name is confusing.

With moving this class into the PaymentMethod namespace and changing its name to CreditCard it is now more obvious what this class actually is.

Several hints inside the class prove that:

  • It inherits from Spree::PaymentMethod
  • The source_class is Spree::CreditCard
  • In supports? it asks the gateway if it supports a certain credit card brand

Further actions are required. First on foremost solidus_gateway needs to be changed in a way that all credit card based payment methods inherit from Spree::PaymentMethod::CreditCard from now on and all non credit card payment methods inherit from Spree::PaymentMethod directly.

includes #2000


describe 'ActiveMerchant methods' do
class PaymentGateway
def initialize(options)

Choose a reason for hiding this comment

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

Put empty method definitions on a single line.

Spree::Deprecation.warn \
"provider_class is deprecated and will be removed from Solidus 3.0 " \
"(use gateway_class instead)"
self.public_send :provider_class

Choose a reason for hiding this comment

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

Redundant self detected.

# Represents the gateway class of this payment method
#
def gateway_class
if self.respond_to? :provider_class

Choose a reason for hiding this comment

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

Redundant self detected.

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.

This is excellent work. I ❤️ the added documentation, which is spot-on. I found two typos, which are absolute nits. 👍

# Uses STI (single table inheritance) to store all implemented payment methods
# in one table (+spree_payment_methods+).
#
# This class is not ment to be instantiated. Please create instances of concrete payment methods.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is excellent class documentation. Wow.

There's a typo in here though: "ment" should read "meant".

# The form your customer enters the payment information in during checkout
#
# 2. app/views/spree/checkout/existing_payment/_{method_type}.html.erb
# The payment information of your customers resuable sources during checkout
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "resuable" -> "reusable"

To remove confusion around payment methods, gateways and providers we rename the `Spree::Gateway::Bogus` and `Spree::Gateway::BogusSimple` payment methods into `Spree::PaymentMethod::BogusCreditCard` and `Spree::PaymentMethod::SimpleBogusCreditCard`.
Use `Spree:: PaymentMethod::BogusCreditCard` and `Spree::PaymentMethod::SimpleBogusCreditCard ` instead.
@tvdeyen
Copy link
Member Author

tvdeyen commented Jun 8, 2017

@mamhoff thanks! Fixed

Also now includes #2000

Running

    rake solidus:migrations:rename_gateways:up

helps migrating your data to new bogus payment method class names.

    rake solidus:migrations:rename_gateways:down

reverts this.

Also includes a migration that invokes that task, so you don't need to care when deploying this change.
`Spree::Gateway` holds many methods that actually belongs into its parent class - `Spree::PaymentMethod`.

It rather should only hold commonalities that are relevant for credit card payment methods.

All payment methods that are not a credit card should inherit directly from `Spree::PaymentMethod` - like `Spree::PaymentMethod::StoreCredit` and friends already does.
In order to remove confusing parts of our current payment methods implementation we rename the `provider` methods from `Spree::PaymentMethod` into `gateway`.

A gateway is a class that implements the API communication to the provider. See the `active_merchant` gem for a set of gateway classes we use in `solidus_gateway`.

A provider on the other hand is a service vendor that offers a payment gateway and multiple payment methods (like Braintree).

Therefore we plan to introduce a provider class later on. This then holds commonalities for mulitple payment methods, like credentials. Also it will be an ActiveRecord model so that payment methods can be grouped under one provider, which is very useful for BI and reporting.
This corrects the documentation on the Spree::PaymentMethod class.
Moves all `Spree::PaymentMethod` class methods to top of class instead of having them distributed all over the file.
The `Spree::Gateway` is an implementation of a credit card payment method. The current name is confusing.

With moving this class into the `PaymentMethod` namespace and changing its name to `CreditCard` it is now more obvious what this class actually is.

Several hints inside the class prove that:

- It inherits from `Spree::PaymentMethod`
- The `source_class` is `Spree::CreditCard`
- In `supports?` it asks the gateway if it supports a certain credit card brand

Further actions are required. First on foremost `solidus_gateway` needs to be changed in a way that all credit card based payment methods inherit from `Spree::PaymentMethod::CreditCard` from now on and all non credit card payment methods inherit from `Spree::PaymentMethod` directly.
Use `Spree::PaymentMethod::CreditCard` instead.
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Great stuff!

@mamhoff mamhoff merged commit 7fbd577 into solidusio:master Jun 21, 2017
@tvdeyen tvdeyen deleted the rename-gateway branch June 21, 2017 16:04
@mtomov
Copy link
Contributor

mtomov commented Jun 22, 2017

Indeed! I very much admire your guts to make such a major change in the name of making it all easier for us to work with the platform! I guess a big role in having the courage to do the refactoring play the tests, so thanks all as well for writing tests so good!

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