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!, #cancel!, #capture!, #credit!, #gateway_options, #partial_credit, #process!, #purchase!, #void_transaction!
Instance Attribute Details
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
24
25
26
|
# File 'app/models/spree/payment.rb', line 24
def source_attributes
@source_attributes
end
|
Instance Method Details
#actions ⇒ Object
112
113
114
115
|
# File 'app/models/spree/payment.rb', line 112
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
|
#amount=(amount) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'app/models/spree/payment.rb', line 82
def amount=(amount)
self[:amount] =
case amount
when String
separator = I18n.t('number.currency.format.separator')
number = amount.delete("^0-9-#{separator}").tr(separator, '.')
number.to_d if number.present?
end || amount
end
|
#build_source ⇒ Object
105
106
107
108
109
110
|
# File 'app/models/spree/payment.rb', line 105
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
100
101
102
|
# File 'app/models/spree/payment.rb', line 100
def can_credit?
credit_allowed > 0
end
|
#credit_allowed ⇒ Object
96
97
98
|
# File 'app/models/spree/payment.rb', line 96
def credit_allowed
amount - offsets_total.abs
end
|
#currency ⇒ Object
73
74
75
|
# File 'app/models/spree/payment.rb', line 73
def currency
order.currency
end
|
#money ⇒ Object
Also known as:
display_amount
77
78
79
|
# File 'app/models/spree/payment.rb', line 77
def money
Spree::Money.new(amount, { currency: currency })
end
|
#offsets_total ⇒ Object
92
93
94
|
# File 'app/models/spree/payment.rb', line 92
def offsets_total
offsets.pluck(:amount).sum
end
|
#payment_source ⇒ Object
117
118
119
120
|
# File 'app/models/spree/payment.rb', line 117
def payment_source
res = source.is_a?(Payment) ? source.source : source
res || payment_method
end
|
#persist_invalid ⇒ Object
40
41
42
43
44
|
# File 'app/models/spree/payment.rb', line 40
def persist_invalid
return unless ['failed', 'invalid'].include?(state)
state_will_change!
save
end
|