Class: Spree::Payment
- 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
-
#request_env ⇒ Object
Returns the value of attribute request_env.
-
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
Instance Method Summary collapse
-
#actions ⇒ Array<String>
The actions available on this payment.
-
#amount=(amount) ⇒ Object
Sets the amount, parsing it based on i18n settings if it is a string.
-
#build_source ⇒ Object
When this is a new record without a source, builds a new source based on this payment’s payment method and associates it correctly.
-
#can_credit? ⇒ Boolean
True when this payment can be credited.
-
#captured_amount ⇒ BigDecimal
The total amount captured on this payment.
-
#credit_allowed ⇒ BigDecimal
The total amount this payment can be credited.
-
#currency ⇒ String
This payment’s currency.
-
#is_avs_risky? ⇒ Boolean
True when this payment is risky based on address.
-
#is_cvv_risky? ⇒ Boolean
True when this payment is risky based on cvv.
-
#money ⇒ Spree::Money
(also: #display_amount)
This amount of this payment as money object.
-
#offsets_total ⇒ BigDecimal
The total amount of the offsets (for old-style refunds) for this payment.
-
#payment_source ⇒ Object
The source of ths payment.
-
#store_credit? ⇒ Boolean
True when the payment method exists and is a store credit payment method.
-
#transaction_id ⇒ String
This payment’s response code.
-
#uncaptured_amount ⇒ BigDecimal
The total amount left uncaptured on this payment.
Methods included from Processing
#authorize!, #cancel!, #capture!, #gateway_options, #process!, #purchase!, #void_transaction!
Methods inherited from Base
Methods included from Spree::Preferences::Preferable
#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.
35 36 37 |
# File 'app/models/spree/payment.rb', line 35 def request_env @request_env end |
#source_attributes ⇒ Object
Returns the value of attribute source_attributes.
35 36 37 |
# File 'app/models/spree/payment.rb', line 35 def source_attributes @source_attributes end |
Instance Method Details
#actions ⇒ Array<String>
Returns the actions available on this payment.
161 162 163 164 165 |
# File 'app/models/spree/payment.rb', line 161 def actions sa = source_actions sa |= ["failure"] if processing? sa end |
#amount=(amount) ⇒ Object
Sets the amount, parsing it based on i18n settings if it is a string.
117 118 119 120 121 122 123 124 125 |
# File 'app/models/spree/payment.rb', line 117 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
When this is a new record without a source, builds a new source based on this payment’s payment method and associates it correctly.
151 152 153 154 155 156 157 158 |
# File 'app/models/spree/payment.rb', line 151 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
Returns true when this payment can be credited.
143 144 145 |
# File 'app/models/spree/payment.rb', line 143 def can_credit? credit_allowed > 0 end |
#captured_amount ⇒ BigDecimal
Returns the total amount captured on this payment.
188 189 190 |
# File 'app/models/spree/payment.rb', line 188 def captured_amount capture_events.sum(:amount) end |
#credit_allowed ⇒ BigDecimal
The total amount this payment can be credited.
138 139 140 |
# File 'app/models/spree/payment.rb', line 138 def credit_allowed amount - (offsets_total.abs + refunds.sum(:amount)) end |
#currency ⇒ String
Returns this payment’s currency.
106 |
# File 'app/models/spree/payment.rb', line 106 delegate :currency, to: :order |
#is_avs_risky? ⇒ Boolean
Returns true when this payment is risky based on address.
174 175 176 177 |
# File 'app/models/spree/payment.rb', line 174 def is_avs_risky? return false if avs_response.blank? || NON_RISKY_AVS_CODES.include?(avs_response) return true end |
#is_cvv_risky? ⇒ Boolean
Returns true when this payment is risky based on cvv.
180 181 182 183 184 185 |
# File 'app/models/spree/payment.rb', line 180 def is_cvv_risky? return false if cvv_response_code == "M" return false if cvv_response_code.nil? return false if .present? return true end |
#money ⇒ Spree::Money Also known as: display_amount
Returns this amount of this payment as money object.
109 110 111 |
# File 'app/models/spree/payment.rb', line 109 def money Spree::Money.new(amount, { currency: currency }) end |
#offsets_total ⇒ BigDecimal
The total amount of the offsets (for old-style refunds) for this payment.
130 131 132 |
# File 'app/models/spree/payment.rb', line 130 def offsets_total offsets.pluck(:amount).sum end |
#payment_source ⇒ Object
Returns the source of ths payment.
168 169 170 171 |
# File 'app/models/spree/payment.rb', line 168 def payment_source res = source.is_a?(Payment) ? source.source : source res || payment_method end |
#store_credit? ⇒ Boolean
Returns true when the payment method exists and is a store credit payment method.
198 199 200 |
# File 'app/models/spree/payment.rb', line 198 def store_credit? payment_method.try!(:store_credit?) end |
#transaction_id ⇒ String
Returns this payment’s response code.
101 102 103 |
# File 'app/models/spree/payment.rb', line 101 def transaction_id response_code end |
#uncaptured_amount ⇒ BigDecimal
Returns the total amount left uncaptured on this payment.
193 194 195 |
# File 'app/models/spree/payment.rb', line 193 def uncaptured_amount amount - captured_amount end |