Class: Spree::PaymentMethod

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

Overview

An abstract class which is implemented most commonly as a `Spree::Gateway`.

Direct Known Subclasses

BillingIntegration, Gateway, Check, StoreCredit

Defined Under Namespace

Classes: Check, StoreCredit

Constant Summary

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

+ (Boolean) active?

Returns:

  • (Boolean)


84
85
86
# File 'app/models/spree/payment_method.rb', line 84

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

+ (Object) available(display_on = nil, store: nil)



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/spree/payment_method.rb', line 62

def self.available(display_on=nil, store: nil)
  Spree::Deprecation.warn "Spree::PaymentMethod.available is deprecated."\
    "Please use .active, .available_to_users, and .available_to_admin scopes instead."\
    "For payment methods associated with a specific store, use Spree::PaymentMethod.available_to_store(your_store)"\
    " as the base applying any further filtering"

  display_on = display_on.to_s

  available_payment_methods =
    case display_on
    when 'front_end'
      active.available_to_users
    when 'back_end'
      active.available_to_admin
    else
      active.available_to_users.available_to_admin
    end
  available_payment_methods.select do |p|
    store.nil? || store.payment_methods.empty? || store.payment_methods.include?(p)
  end
end

+ (Object) find_with_destroyed(*args)



92
93
94
# File 'app/models/spree/payment_method.rb', line 92

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

+ (Object) providers



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

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

Instance Method Details

- (Boolean) auto_capture?

Returns:

  • (Boolean)


110
111
112
# File 'app/models/spree/payment_method.rb', line 110

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

- (Object) cancel(_response)

Raises:

  • (::NotImplementedError)


118
119
120
# File 'app/models/spree/payment_method.rb', line 118

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

- (Object) display_on

Deprecated.

Use #available_to_users and #available_to_admin instead



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/spree/payment_method.rb', line 48

def display_on
  Spree::Deprecation.warn "Spree::PaymentMethod#display_on is deprecated."\
    "Please use #available_to_users and #available_to_admin instead."
  if available_to_users? && available_to_admin?
    ''
  elsif available_to_users?
    'front_end'
  elsif available_to_admin?
    'back_end'
  else
    'none'
  end
end

- (Object) display_on=(value)

Deprecated.

Use #available_to_users= and #available_to_admin= instead



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

def display_on=(value)
  Spree::Deprecation.warn "Spree::PaymentMethod#display_on= is deprecated."\
    "Please use #available_to_users= and #available_to_admin= instead."
  self.available_to_users = value.blank? || value == 'front_end'
  self.available_to_admin = value.blank? || value == 'back_end'
end

- (Object) method_type



88
89
90
# File 'app/models/spree/payment_method.rb', line 88

def method_type
  type.demodulize.downcase
end

- (Boolean) payment_profiles_supported?

Returns:

  • (Boolean)


96
97
98
# File 'app/models/spree/payment_method.rb', line 96

def payment_profiles_supported?
  false
end

- (Object) payment_source_class

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)


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

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

- (Object) provider_class

Raises:

  • (::NotImplementedError)


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

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

- (Object) reusable_sources(_order)

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



106
107
108
# File 'app/models/spree/payment_method.rb', line 106

def reusable_sources(_order)
  []
end

- (Boolean) source_required?

Returns:

  • (Boolean)


100
101
102
# File 'app/models/spree/payment_method.rb', line 100

def source_required?
  true
end

- (Boolean) store_credit?

Returns:

  • (Boolean)


122
123
124
# File 'app/models/spree/payment_method.rb', line 122

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

- (Boolean) supports?(_source)

Returns:

  • (Boolean)


114
115
116
# File 'app/models/spree/payment_method.rb', line 114

def supports?(_source)
  true
end