Class: Spree::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Payment
show all
- Includes:
- Processing
- Defined in:
- app/models/spree/payment.rb,
app/models/spree/payment/processing.rb
Defined Under Namespace
Modules: Processing
Constant Summary
collapse
- IDENTIFIER_CHARS =
(('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Processing
#authorize!, #capture!, #credit!, #gateway_options, #partial_credit, #process!, #purchase!, #void_transaction!
Instance Attribute Details
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
25
26
27
|
# File 'app/models/spree/payment.rb', line 25
def source_attributes
@source_attributes
end
|
Instance Method Details
#actions ⇒ Object
99
100
101
102
|
# File 'app/models/spree/payment.rb', line 99
def actions
return [] unless payment_source and payment_source.respond_to? :actions
payment_source.actions.select { |action| !payment_source.respond_to?("can_#{action}?") or payment_source.send("can_#{action}?", self) }
end
|
#build_source ⇒ Object
92
93
94
95
96
97
|
# File 'app/models/spree/payment.rb', line 92
def build_source
return if source_attributes.nil?
if payment_method and payment_method.payment_source_class
self.source = payment_method.payment_source_class.new(source_attributes)
end
end
|
#can_credit? ⇒ Boolean
87
88
89
|
# File 'app/models/spree/payment.rb', line 87
def can_credit?
credit_allowed > 0
end
|
#credit_allowed ⇒ Object
83
84
85
|
# File 'app/models/spree/payment.rb', line 83
def credit_allowed
amount - offsets_total
end
|
#currency ⇒ Object
70
71
72
|
# File 'app/models/spree/payment.rb', line 70
def currency
order.currency
end
|
#money ⇒ Object
Also known as:
display_amount
74
75
76
|
# File 'app/models/spree/payment.rb', line 74
def money
Spree::Money.new(amount, { currency: currency })
end
|
#offsets_total ⇒ Object
79
80
81
|
# File 'app/models/spree/payment.rb', line 79
def offsets_total
offsets.pluck(:amount).sum
end
|
#payment_source ⇒ Object
104
105
106
107
|
# File 'app/models/spree/payment.rb', line 104
def payment_source
res = source.is_a?(Payment) ? source.source : source
res || payment_method
end
|
#persist_invalid ⇒ Object
37
38
39
40
41
|
# File 'app/models/spree/payment.rb', line 37
def persist_invalid
return unless ['failed', 'invalid'].include?(state)
state_will_change!
save
end
|