Class: Spree::PaymentMethod

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

Direct Known Subclasses

BillingIntegration, Gateway, Check, StoreCredit

Defined Under Namespace

Classes: Check, StoreCredit

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Spree::Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

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

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


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

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

.available(display_on = 'both', store: nil) ⇒ Object



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

def self.available(display_on = 'both', store: nil)
  all.select do |p|
    p.active &&
      (p.display_on == display_on.to_s || p.display_on.blank?) &&
      (store.nil? || store.payment_methods.empty? || store.payment_methods.include?(p))
  end
end

.find_with_destroyed(*args) ⇒ Object



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

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

.providersObject



18
19
20
# File 'app/models/spree/payment_method.rb', line 18

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

Instance Method Details

#auto_capture?Boolean

Returns:

  • (Boolean)


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

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

#cancel(_response) ⇒ Object

Raises:

  • (::NotImplementedError)


75
76
77
# File 'app/models/spree/payment_method.rb', line 75

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

#method_typeObject



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

def method_type
  type.demodulize.downcase
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/spree/payment_method.rb', line 53

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)


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

def payment_source_class
  raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
end

#provider_classObject

Raises:

  • (::NotImplementedError)


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

def provider_class
  raise ::NotImplementedError, "You must implement provider_class method for #{self.class}."
end

#reusable_sources(_order) ⇒ Object

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



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

def reusable_sources(_order)
  []
end

#source_required?Boolean

Returns:

  • (Boolean)


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

def source_required?
  true
end

#store_credit?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/spree/payment_method.rb', line 79

def store_credit?
  is_a? Spree::PaymentMethod::StoreCredit
end

#supports?(_source) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/spree/payment_method.rb', line 71

def supports?(_source)
  true
end