Class: Spree::PaymentMethod
Overview
An abstract class which is implemented most commonly as a ‘Spree::Gateway`.
Defined Under Namespace
Classes: Check, StoreCredit
Constant Summary
collapse
- DISPLAY =
[:both, :front_end, :back_end]
Class Method Summary
collapse
Instance Method Summary
collapse
#preference_source=, #preferences, #preferences=
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.active? ⇒ Boolean
87
88
89
|
# File 'app/models/spree/payment_method.rb', line 87
def self.active?
where(type: to_s, active: true).count > 0
end
|
.available(display_on = nil, store: nil) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/spree/payment_method.rb', line 65
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
|
.find_with_destroyed(*args) ⇒ Object
95
96
97
|
# File 'app/models/spree/payment_method.rb', line 95
def self.find_with_destroyed(*args)
unscoped { find(*args) }
end
|
.providers ⇒ Object
27
28
29
|
# File 'app/models/spree/payment_method.rb', line 27
def self.providers
Rails.application.config.spree.payment_methods
end
|
Instance Method Details
#auto_capture? ⇒ Boolean
113
114
115
|
# File 'app/models/spree/payment_method.rb', line 113
def auto_capture?
auto_capture.nil? ? Spree::Config[:auto_capture] : auto_capture
end
|
#cancel(_response) ⇒ Object
121
122
123
|
# File 'app/models/spree/payment_method.rb', line 121
def cancel(_response)
raise ::NotImplementedError, 'You must implement cancel method for this payment method.'
end
|
#display_on ⇒ Object
Deprecated.
Use #available_to_users and #available_to_admin instead
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/models/spree/payment_method.rb', line 51
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
|
#display_on=(value) ⇒ Object
Deprecated.
Use #available_to_users= and #available_to_admin= instead
43
44
45
46
47
48
|
# File 'app/models/spree/payment_method.rb', line 43
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
|
#method_type ⇒ Object
91
92
93
|
# File 'app/models/spree/payment_method.rb', line 91
def method_type
type.demodulize.downcase
end
|
#payment_profiles_supported? ⇒ Boolean
99
100
101
|
# File 'app/models/spree/payment_method.rb', line 99
def payment_profiles_supported?
false
end
|
#payment_source_class ⇒ Object
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
38
39
40
|
# File 'app/models/spree/payment_method.rb', line 38
def payment_source_class
raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
end
|
#provider_class ⇒ Object
31
32
33
|
# File 'app/models/spree/payment_method.rb', line 31
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
109
110
111
|
# File 'app/models/spree/payment_method.rb', line 109
def reusable_sources(_order)
[]
end
|
#source_required? ⇒ Boolean
103
104
105
|
# File 'app/models/spree/payment_method.rb', line 103
def source_required?
true
end
|
#supports?(_source) ⇒ Boolean
117
118
119
|
# File 'app/models/spree/payment_method.rb', line 117
def supports?(_source)
true
end
|