Class: Spree::Gateway
Defined Under Namespace
Classes: Bogus, CustomPaymentSourceMethod
Constant Summary
collapse
- FROM_DOLLAR_TO_CENT_RATE =
100.0
Constants included
from DisplayOn
DisplayOn::DISPLAY
Instance Method Summary
collapse
#auto_capture?, #available_for_order?, #available_for_store?, #cancel, #complete_payment_session, #complete_payment_setup_session, #confirmation_required?, #create_payment_session, #create_payment_setup_session, #default_name, find_with_destroyed, #parse_webhook_event, #payment_icon_name, #payment_session_class, #payment_setup_session_class, #provider_class, providers, #public_preferences, #session_required?, #setup_session_supported?, #show_in_admin?, #source_required?, #store_credit?, #update_payment_session, #webhook_url
Methods included from Metadata
#metadata, #metadata=, #public_metadata=
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
30
31
32
33
34
35
36
|
# File 'app/models/spree/gateway.rb', line 30
def method_missing(method, *args)
if @provider.nil? || !@provider.respond_to?(method)
super
else
provider.send(method, *args)
end
end
|
Instance Method Details
#disable_customer_profile(source) ⇒ Object
57
58
59
60
61
62
63
|
# File 'app/models/spree/gateway.rb', line 57
def disable_customer_profile(source)
if source.is_a? CreditCard
source.update_column :gateway_customer_profile_id, nil
else
raise 'You must implement disable_customer_profile method for this gateway.'
end
end
|
#exchange_multiplier ⇒ Object
#gateway_dashboard_payment_url(_payment) ⇒ Object
Override in the gateway to provide a payment url eg. for Stripe, this would be the payment intent url dashboard.stripe.com/payments/#Spree::Gateway.paymentpayment.transaction_id
16
17
18
|
# File 'app/models/spree/gateway.rb', line 16
def gateway_dashboard_payment_url(_payment)
nil
end
|
#method_type ⇒ Object
42
43
44
|
# File 'app/models/spree/gateway.rb', line 42
def method_type
'gateway'
end
|
#options ⇒ Object
26
27
28
|
# File 'app/models/spree/gateway.rb', line 26
def options
preferences.each_with_object({}) { |(key, value), memo| memo[key.to_sym] = value; }
end
|
#payment_profiles_supported? ⇒ Boolean
38
39
40
|
# File 'app/models/spree/gateway.rb', line 38
def payment_profiles_supported?
false
end
|
#payment_source_class ⇒ Object
9
10
11
|
# File 'app/models/spree/gateway.rb', line 9
def payment_source_class
CreditCard
end
|
#provider ⇒ Object
20
21
22
23
24
|
# File 'app/models/spree/gateway.rb', line 20
def provider
gateway_options = options
gateway_options.delete :login if gateway_options.key?(:login) && gateway_options[:login].nil?
@provider ||= provider_class.new(gateway_options)
end
|
#reusable_sources(order) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/models/spree/gateway.rb', line 70
def reusable_sources(order)
if order.completed?
sources_by_order order
else
if order.user_id
credit_cards.where(user_id: order.user_id).capturable
else
[]
end
end
end
|
#sources_by_order(order) ⇒ Object
65
66
67
68
|
# File 'app/models/spree/gateway.rb', line 65
def sources_by_order(order)
source_ids = order.payments.where(source_type: payment_source_class.to_s, payment_method_id: id).pluck(:source_id).uniq
payment_source_class.where(id: source_ids).capturable
end
|
#supports?(source) ⇒ Boolean
50
51
52
53
54
55
|
# File 'app/models/spree/gateway.rb', line 50
def supports?(source)
return true unless provider_class.respond_to? :supports?
return false unless source.brand
provider_class.supports?(source.brand)
end
|