Skip to content
This repository

Create abstract method definitions for the gateway methods #157

Closed
wants to merge 1 commit into from

3 participants

Daniel Schierbeck Nathaniel Talbott Michael Noack
Daniel Schierbeck
dasch commented

The abstract implementations simply raise NotImplementedError.

The primary purpose of this is to have a default place for documentation. Furthermore, I find it better that gateway implementations that do not support some features raise NotImplementedError instead of NoMethodError.

There is one downside though -- since the methods are public, #respond_to? returns true for the methods, causing a few tests to fail.

A custom #respond_to? implementation would solve this. Gateway subclasses would register which functionality they supported through a class method call, e.g. supports :authorize, :capture, :purchase, :credit, and #respond_to? would respond accordingly.

If this plan is accepted, I'll add extensive documentation to all the abstract methods. This will be inherited to the concrete implementations.

Daniel Schierbeck dasch Create abstract method definitions for the gateway methods
The abstract implementations simply raise NotImplementedError.
f9d5349
Nathaniel Talbott
Collaborator

Any opinions from other committers on this approach? I wonder if a markdown file documenting the API would be simpler, in conjunction with a lint as proposed in #116.

In general, I'm totally agreed we need something better around both documentation, just not sure if I like the abstract class approach.

Michael Noack

I haven't tried this but could you override method_missing so that you can deal with undefined methods, and hopefully this would still have the desired respond_to? affects.

Daniel Schierbeck
dasch commented

@mnoack: you need to manually edit respond_to? if you change method_missing.

Nathaniel Talbott
Collaborator

Closing as I'm not a fan of using an abstract class for this; I think a lint approach combined with better docs will be a better approach.

Nathaniel Talbott ntalbott closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 17, 2011
Daniel Schierbeck dasch Create abstract method definitions for the gateway methods
The abstract implementations simply raise NotImplementedError.
f9d5349
This page is out of date. Refresh to see the latest.
32 lib/active_merchant/billing/gateway.rb
@@ -99,6 +99,38 @@ def self.inherited(subclass)
99 99 self.application_id = 'ActiveMerchant'
100 100
101 101 attr_reader :options
  102 +
  103 + def purchase(money, creditcard, options = {})
  104 + raise NotImplementedError
  105 + end
  106 +
  107 + def authorize(money, creditcard, options = {})
  108 + raise NotImplementedError
  109 + end
  110 +
  111 + def capture(money, authorization, options = {})
  112 + raise NotImplementedError
  113 + end
  114 +
  115 + def void(identification, options = {})
  116 + raise NotImplementedError
  117 + end
  118 +
  119 + def credit(money, identification, options = {})
  120 + raise NotImplementedError
  121 + end
  122 +
  123 + def recurring(money, creditcard, options = {})
  124 + raise NotImplementedError
  125 + end
  126 +
  127 + def store(creditcard, options = {})
  128 + raise NotImplementedError
  129 + end
  130 +
  131 + def unstore(identification, options = {})
  132 + raise NotImplementedError
  133 + end
102 134
103 135 # Use this method to check if your gateway of interest supports a credit card of some type
104 136 def self.supports?(card_type)
9 test/unit/gateways/gateway_test.rb
@@ -45,4 +45,11 @@ def test_setting_application_id_outside_the_class_definition
45 45
46 46 assert_equal SimpleTestGateway.application_id, SubclassGateway.application_id
47 47 end
48   -end
  48 +
  49 + def test_defines_abstract_methods
  50 + methods = %w[purchase authorize capture void credit recurring store unstore]
  51 + methods.each do |method|
  52 + assert_raise(NotImplementedError) { Gateway.new.__send__(method, nil, nil) }
  53 + end
  54 + end
  55 +end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.