Class: Spree::PaymentMethod

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/payment_method.rb

Direct Known Subclasses

Gateway, Check

Defined Under Namespace

Classes: Check

Constant Summary collapse

DISPLAY =
[:both, :front_end, :back_end]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

page

Methods included from Spree::Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/spree/payment_method.rb', line 34

def self.active?
  where(type: self.to_s, active: true).count > 0
end

.available(display_on = 'both') ⇒ Object



27
28
29
30
31
32
# File 'app/models/spree/payment_method.rb', line 27

def self.available(display_on = 'both')
  all.select do |p|
    p.active &&
    (p.display_on == display_on.to_s || p.display_on.blank?)
  end
end

.find_with_destroyed(*args) ⇒ Object



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

def self.find_with_destroyed *args
  unscoped { find(*args) }
end

.providersObject



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

def self.providers
  Rails.application.config.spree.payment_methods
end

Instance Method Details

#auto_capture?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/spree/payment_method.rb', line 60

def auto_capture?
  self.auto_capture.nil? ? Spree::Config[:auto_capture] : self.auto_capture
end

#cancel(response) ⇒ Object

Raises:

  • (::NotImplementedError)


68
69
70
# File 'app/models/spree/payment_method.rb', line 68

def cancel(response)
  raise ::NotImplementedError, 'You must implement cancel method for this payment method.'
end

#method_typeObject



38
39
40
# File 'app/models/spree/payment_method.rb', line 38

def method_type
  type.demodulize.downcase
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


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

def payment_profiles_supported?
  false
end

#payment_source_classObject

The class that will process payments for this payment type, used for @payment.source e.g. CreditCard in the case of a the Gateway payment type nil means the payment method doesn’t require a source e.g. check

Raises:

  • (::NotImplementedError)


23
24
25
# File 'app/models/spree/payment_method.rb', line 23

def payment_source_class
  raise ::NotImplementedError, 'You must implement payment_source_class method for this gateway.'
end

#provider_classObject

Raises:

  • (::NotImplementedError)


16
17
18
# File 'app/models/spree/payment_method.rb', line 16

def provider_class
  raise ::NotImplementedError, 'You must implement provider_class method for this gateway.'
end

#reusable_sources(order) ⇒ Object

Custom gateways should redefine this method. See Gateway implementation as an example



56
57
58
# File 'app/models/spree/payment_method.rb', line 56

def reusable_sources(order)
  []
end

#source_required?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/spree/payment_method.rb', line 50

def source_required?
  true
end

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/spree/payment_method.rb', line 64

def supports?(source)
  true
end