Class: Spree::Payment
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- 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!
Methods inherited from Base
page
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Attribute Details
#request_env ⇒ Object
Returns the value of attribute request_env.
30
31
32
|
# File 'app/models/spree/payment.rb', line 30
def request_env
@request_env
end
|
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
30
31
32
|
# File 'app/models/spree/payment.rb', line 30
def source_attributes
@source_attributes
end
|
Instance Method Details
#actions ⇒ Object
134
135
136
137
|
# File 'app/models/spree/payment.rb', line 134
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
102
103
104
105
106
107
108
109
110
|
# File 'app/models/spree/payment.rb', line 102
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
125
126
127
128
129
130
131
132
|
# File 'app/models/spree/payment.rb', line 125
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
120
121
122
|
# File 'app/models/spree/payment.rb', line 120
def can_credit?
credit_allowed > 0
end
|
#credit_allowed ⇒ Object
116
117
118
|
# File 'app/models/spree/payment.rb', line 116
def credit_allowed
amount - offsets_total.abs
end
|
#currency ⇒ Object
93
94
95
|
# File 'app/models/spree/payment.rb', line 93
def currency
order.currency
end
|
#is_avs_risky? ⇒ Boolean
144
145
146
147
|
# File 'app/models/spree/payment.rb', line 144
def is_avs_risky?
return false if avs_response.blank? || NON_RISKY_AVS_CODES.include?(avs_response)
return true
end
|
#is_cvv_risky? ⇒ Boolean
149
150
151
152
153
154
|
# File 'app/models/spree/payment.rb', line 149
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
97
98
99
|
# File 'app/models/spree/payment.rb', line 97
def money
Spree::Money.new(amount, { currency: currency })
end
|
#offsets_total ⇒ Object
112
113
114
|
# File 'app/models/spree/payment.rb', line 112
def offsets_total
offsets.pluck(:amount).sum
end
|
#payment_source ⇒ Object
139
140
141
142
|
# File 'app/models/spree/payment.rb', line 139
def payment_source
res = source.is_a?(Payment) ? source.source : source
res || payment_method
end
|
#persist_invalid ⇒ Object
48
49
50
51
52
|
# File 'app/models/spree/payment.rb', line 48
def persist_invalid
return unless ['failed', 'invalid'].include?(state)
state_will_change!
save
end
|
#uncaptured_amount ⇒ Object
156
157
158
|
# File 'app/models/spree/payment.rb', line 156
def uncaptured_amount
amount - capture_events.sum(:amount)
end
|