Class: Spree::Gateway
Overview
A concrete implementation of ‘Spree::PaymentMethod` intended to provide a base for extension. See github.com/solidusio/solidus_gateway/ for offically supported payment gateway implementations.
Direct Known Subclasses
Bogus
Defined Under Namespace
Classes: Bogus, BogusSimple
Constant Summary
PaymentMethod::DISPLAY
Instance Method Summary
collapse
active?, #auto_capture?, available, #cancel, #display_on, #display_on=, find_with_destroyed, #provider_class, providers, #source_required?, #store_credit?
#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
Instance Method Details
#method_type ⇒ Object
35
36
37
|
# File 'app/models/spree/gateway.rb', line 35
def method_type
'gateway'
end
|
#options ⇒ Object
27
28
29
|
# File 'app/models/spree/gateway.rb', line 27
def options
preferences.to_hash
end
|
#payment_profiles_supported? ⇒ Boolean
31
32
33
|
# File 'app/models/spree/gateway.rb', line 31
def payment_profiles_supported?
false
end
|
#payment_source_class ⇒ Object
14
15
16
|
# File 'app/models/spree/gateway.rb', line 14
def payment_source_class
CreditCard
end
|
#provider ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'app/models/spree/gateway.rb', line 18
def provider
gateway_options = options
gateway_options.delete :login if gateway_options.key?(:login) && gateway_options[:login].nil?
if gateway_options[:server]
ActiveMerchant::Billing::Base.mode = gateway_options[:server].to_sym
end
@provider ||= provider_class.new(gateway_options)
end
|
#reusable_sources(order) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'app/models/spree/gateway.rb', line 52
def reusable_sources(order)
if order.completed?
reusable_sources_by_order(order)
elsif order.user_id
order.user.wallet.wallet_payment_sources.map(&:payment_source).select(&:reusable?)
else
[]
end
end
|
#reusable_sources_by_order(order) ⇒ Object
Also known as:
sources_by_order
45
46
47
48
|
# File 'app/models/spree/gateway.rb', line 45
def reusable_sources_by_order(order)
source_ids = order.payments.where(payment_method_id: id).pluck(:source_id).uniq
payment_source_class.where(id: source_ids).select(&:reusable?)
end
|
#supports?(source) ⇒ Boolean
39
40
41
42
43
|
# File 'app/models/spree/gateway.rb', line 39
def supports?(source)
return true unless provider_class.respond_to? :supports?
return true if source.brand && provider_class.supports?(source.brand)
source.has_payment_profile?
end
|