Class: Spree::Gateway

Inherits:
PaymentMethod show all
Defined in:
app/models/spree/gateway.rb

Direct Known Subclasses

Bogus

Defined Under Namespace

Classes: Bogus, BogusSimple

Constant Summary

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PaymentMethod

active?, #auto_capture?, available, #destroy, find_with_destroyed, #provider_class, providers, #source_required?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



34
35
36
37
38
39
40
# File 'app/models/spree/gateway.rb', line 34

def method_missing(method, *args)
  if @provider.nil? || !@provider.respond_to?(method)
    super
  else
    provider.send(method, *args)
  end
end

Class Method Details

.currentObject

instantiates the selected gateway and configures with the options stored in the database



17
18
19
# File 'app/models/spree/gateway.rb', line 17

def self.current
  super
end

Instance Method Details

#method_typeObject



46
47
48
# File 'app/models/spree/gateway.rb', line 46

def method_type
  'gateway'
end

#optionsObject



30
31
32
# File 'app/models/spree/gateway.rb', line 30

def options
  self.preferences.inject({}){ |memo, (key, value)| memo[key.to_sym] = value; memo }
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/spree/gateway.rb', line 42

def payment_profiles_supported?
  false
end

#payment_source_classObject



12
13
14
# File 'app/models/spree/gateway.rb', line 12

def payment_source_class
  CreditCard
end

#providerObject



21
22
23
24
25
26
27
28
# File 'app/models/spree/gateway.rb', line 21

def provider
  gateway_options = options
  gateway_options.delete :login if gateway_options.has_key?(:login) and gateway_options[:login].nil?
  if gateway_options[:server]
    ActiveMerchant::Billing::Base.gateway_mode = gateway_options[:server].to_sym
  end
  @provider ||= provider_class.new(gateway_options)
end

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'app/models/spree/gateway.rb', line 50

def supports?(source)
  return true unless provider_class.respond_to? :supports?
  return false unless source.brand
  provider_class.supports?(source.brand)
end