Class: Spree::Payment
Defined Under Namespace
Modules: Processing
Classes: GatewayOptions
Constant Summary
collapse
- 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
- INVALID_STATES =
%w(failed invalid void).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Processing
#authorize!, #cancel!, #capture!, #gateway_options, #process!, #purchase!, #void_transaction!
#to_param
Methods inherited from Base
belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference
Instance Attribute Details
#capture_on_dispatch ⇒ Object
Returns the value of attribute capture_on_dispatch.
49
50
51
|
# File 'app/models/spree/payment.rb', line 49
def capture_on_dispatch
@capture_on_dispatch
end
|
#request_env ⇒ Object
Returns the value of attribute request_env.
49
50
51
|
# File 'app/models/spree/payment.rb', line 49
def request_env
@request_env
end
|
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
49
50
51
|
# File 'app/models/spree/payment.rb', line 49
def source_attributes
@source_attributes
end
|
Instance Method Details
#actions ⇒ Object
172
173
174
175
176
|
# File 'app/models/spree/payment.rb', line 172
def actions
return [] unless payment_source&.respond_to?(:actions)
payment_source.actions.select { |action| !payment_source.respond_to?("can_#{action}?") || payment_source.send("can_#{action}?", self) }
end
|
#amount=(amount) ⇒ Object
139
140
141
142
143
144
145
146
147
|
# File 'app/models/spree/payment.rb', line 139
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
162
163
164
165
166
167
168
169
170
|
# File 'app/models/spree/payment.rb', line 162
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)
source.payment_method_id = payment_method.id
source.user_id = order.user_id if order
end
end
|
#can_credit? ⇒ Boolean
157
158
159
|
# File 'app/models/spree/payment.rb', line 157
def can_credit?
credit_allowed > 0
end
|
#captured_amount ⇒ Object
197
198
199
|
# File 'app/models/spree/payment.rb', line 197
def captured_amount
capture_events.sum(:amount)
end
|
#credit_allowed ⇒ Object
153
154
155
|
# File 'app/models/spree/payment.rb', line 153
def credit_allowed
amount - (offsets_total.abs + refunds.sum(:amount))
end
|
#editable? ⇒ Boolean
205
206
207
|
# File 'app/models/spree/payment.rb', line 205
def editable?
checkout? || pending?
end
|
#is_avs_risky? ⇒ Boolean
183
184
185
186
187
|
# File 'app/models/spree/payment.rb', line 183
def is_avs_risky?
return false if avs_response.blank? || NON_RISKY_AVS_CODES.include?(avs_response)
true
end
|
#is_cvv_risky? ⇒ Boolean
189
190
191
192
193
194
195
|
# File 'app/models/spree/payment.rb', line 189
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?
true
end
|
#money ⇒ Object
Also known as:
display_amount
134
135
136
|
# File 'app/models/spree/payment.rb', line 134
def money
Spree::Money.new(amount, currency: currency)
end
|
#offsets_total ⇒ Object
149
150
151
|
# File 'app/models/spree/payment.rb', line 149
def offsets_total
offsets.sum(:amount)
end
|
#payment_source ⇒ Object
178
179
180
181
|
# File 'app/models/spree/payment.rb', line 178
def payment_source
res = source.is_a?(Payment) ? source.source : source
res || payment_method
end
|
#source ⇒ Object
127
128
129
130
131
132
|
# File 'app/models/spree/payment.rb', line 127
def source
return super if payment_method.nil?
return super unless payment_method.source_required?
payment_method.payment_source_class.unscoped { super }
end
|
#transaction_id ⇒ Object
transaction_id is much easier to understand
80
81
82
|
# File 'app/models/spree/payment.rb', line 80
def transaction_id
response_code
end
|
#uncaptured_amount ⇒ Object
201
202
203
|
# File 'app/models/spree/payment.rb', line 201
def uncaptured_amount
amount - captured_amount
end
|