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
- NON_RISKY_AVS_CODES =
['B', 'D', 'H', 'J', 'M', 'Q', 'T', 'V', 'X', 'Y'].freeze
- RISKY_AVS_CODES =
['A', 'C', 'E', 'F', 'G', 'I', 'K', 'L', 'N', 'O', 'P', 'R', 'S', 'U', 'W', 'Z'].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.
29
30
31
|
# File 'app/models/spree/payment.rb', line 29
def source_attributes
@source_attributes
end
|
Instance Method Details
#actions ⇒ Object
126
127
128
129
|
# File 'app/models/spree/payment.rb', line 126
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
94
95
96
97
98
99
100
101
102
|
# File 'app/models/spree/payment.rb', line 94
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
117
118
119
120
121
122
123
124
|
# File 'app/models/spree/payment.rb', line 117
def build_source
return unless new_record?
if source_attributes.present? && source.blank? && payment_method.try(:payment_source_class)
self.source = payment_method.payment_source_class.new(source_attributes)
self.source.payment_method_id = payment_method.id
self.source.user_id = self.order.user_id if self.order
end
end
|
#can_credit? ⇒ Boolean
112
113
114
|
# File 'app/models/spree/payment.rb', line 112
def can_credit?
credit_allowed > 0
end
|
#credit_allowed ⇒ Object
108
109
110
|
# File 'app/models/spree/payment.rb', line 108
def credit_allowed
amount - offsets_total.abs
end
|
#currency ⇒ Object
85
86
87
|
# File 'app/models/spree/payment.rb', line 85
def currency
order.currency
end
|
#is_avs_risky? ⇒ Boolean
136
137
138
139
|
# File 'app/models/spree/payment.rb', line 136
def is_avs_risky?
return false if avs_response.blank? || NON_RISKY_AVS_CODES.include?(avs_response)
return true
end
|
#is_cvv_risky? ⇒ Boolean
141
142
143
144
145
146
|
# File 'app/models/spree/payment.rb', line 141
def is_cvv_risky?
return false if cvv_response_code == "M"
return false if cvv_response_code.nil?
return false if cvv_response_message.present?
return true
end
|
#money ⇒ Object
Also known as:
display_amount
89
90
91
|
# File 'app/models/spree/payment.rb', line 89
def money
Spree::Money.new(amount, { currency: currency })
end
|
#offsets_total ⇒ Object
104
105
106
|
# File 'app/models/spree/payment.rb', line 104
def offsets_total
offsets.pluck(:amount).sum
end
|
#payment_source ⇒ Object
131
132
133
134
|
# File 'app/models/spree/payment.rb', line 131
def payment_source
res = source.is_a?(Payment) ? source.source : source
res || payment_method
end
|
#persist_invalid ⇒ Object
44
45
46
47
48
|
# File 'app/models/spree/payment.rb', line 44
def persist_invalid
return unless ['failed', 'invalid'].include?(state)
state_will_change!
save
end
|
#uncaptured_amount ⇒ Object
148
149
150
|
# File 'app/models/spree/payment.rb', line 148
def uncaptured_amount
amount - capture_events.sum(:amount)
end
|