Class: Opensteam::Payment::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
StateMachine
Defined in:
lib/opensteam/payment.rb

Overview

Base Class for all Payment Implementations

Constant Summary collapse

@@payment_types =
[]

Class Method Summary collapse

Methods included from StateMachine

included

Class Method Details

.[](payment_id) ⇒ Object

retrieve a payment-implementation class using the :payment_id Ex:

class CreditCardPayment < Opensteam::Payment::Base
  self.payment_id = :credit_card
end

Opensteam::Payment::Base[ :credit_card ] # => CreditCardPayment


179
180
181
# File 'lib/opensteam/payment.rb', line 179

def [](payment_id)
  @@payment_types.find { |t| t.payment_id.to_sym == payment_id.to_sym }
end

.inherited(sub) ⇒ Object

:nodoc:



167
168
169
# File 'lib/opensteam/payment.rb', line 167

def inherited(sub) #:nodoc:
  @@payment_types << sub
end

.new_with_type(*attr, &block) ⇒ Object



185
186
187
188
189
190
191
# File 'lib/opensteam/payment.rb', line 185

def new_with_type( *attr, &block )
  if( h = attr.first).is_a? Hash and (type = h["type"] || h[:type] ) and ( klass = type.constantize ) != self
    raise "#{klass} is not a subclass of #{self}" unless klass < self
    return klass.new( *attr, &block )
  end
  new_without_type( *attr, &block )
end