Class: Spree::Payment
- Includes:
- Processing
- Defined in:
- app/models/spree/payment.rb,
app/models/spree/payment/processing.rb,
app/models/spree/payment/cancellation.rb
Overview
Manage and process a payment for an order, from a specific source (e.g. ‘Spree::CreditCard`) using a specific payment method (e.g `Solidus::Gateway::Braintree`).
Defined Under Namespace
Modules: Processing Classes: Cancellation
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.
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.
-
#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.
-
#fully_refunded? ⇒ Boolean
True when this payment has been fully refunded.
-
#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.
-
#payment_source ⇒ Object
The source of ths payment.
-
#risky? ⇒ Boolean
True when this payment is risky.
-
#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, #gateway_order_id, #handle_void_response, #process!, #purchase!, #void_transaction!
Methods inherited from Base
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Attribute Details
#request_env ⇒ Object
Returns the value of attribute request_env.
37 38 39 |
# File 'app/models/spree/payment.rb', line 37 def request_env @request_env end |
Instance Method Details
#actions ⇒ Array<String>
Returns the actions available on this payment.
107 108 109 110 111 |
# File 'app/models/spree/payment.rb', line 107 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.
79 80 81 82 83 84 85 86 87 |
# File 'app/models/spree/payment.rb', line 79 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 |
#can_credit? ⇒ Boolean
Returns true when this payment can be credited.
97 98 99 |
# File 'app/models/spree/payment.rb', line 97 def can_credit? credit_allowed > 0 end |
#captured_amount ⇒ BigDecimal
Returns the total amount captured on this payment.
138 139 140 |
# File 'app/models/spree/payment.rb', line 138 def captured_amount capture_events.sum(:amount) end |
#credit_allowed ⇒ BigDecimal
The total amount this payment can be credited.
92 93 94 |
# File 'app/models/spree/payment.rb', line 92 def credit_allowed amount - refunds.sum(:amount) end |
#currency ⇒ String
Returns this payment’s currency.
68 |
# File 'app/models/spree/payment.rb', line 68 delegate :currency, to: :order |
#fully_refunded? ⇒ Boolean
Returns true when this payment has been fully refunded.
102 103 104 |
# File 'app/models/spree/payment.rb', line 102 def fully_refunded? refunds.map(&:amount).sum == amount end |
#is_avs_risky? ⇒ Boolean
Returns true when this payment is risky based on address.
125 126 127 128 |
# File 'app/models/spree/payment.rb', line 125 def is_avs_risky? return false if avs_response.blank? || NON_RISKY_AVS_CODES.include?(avs_response) true end |
#is_cvv_risky? ⇒ Boolean
Returns true when this payment is risky based on cvv.
131 132 133 134 135 |
# File 'app/models/spree/payment.rb', line 131 def is_cvv_risky? return false if cvv_response_code == "M" return false if cvv_response_code.nil? true end |
#money ⇒ Spree::Money Also known as: display_amount
Returns this amount of this payment as money object.
71 72 73 |
# File 'app/models/spree/payment.rb', line 71 def money Spree::Money.new(amount, { currency: }) end |
#payment_source ⇒ Object
Returns the source of ths payment.
114 115 116 117 |
# File 'app/models/spree/payment.rb', line 114 def payment_source res = source.is_a?(Payment) ? source.source : source res || payment_method end |
#risky? ⇒ Boolean
Returns true when this payment is risky.
120 121 122 |
# File 'app/models/spree/payment.rb', line 120 def risky? is_avs_risky? || is_cvv_risky? || state == 'failed' end |
#store_credit? ⇒ Boolean
Returns true when the payment method exists and is a store credit payment method.
148 149 150 |
# File 'app/models/spree/payment.rb', line 148 def store_credit? payment_method.try!(:store_credit?) end |
#transaction_id ⇒ String
Returns this payment’s response code.
63 64 65 |
# File 'app/models/spree/payment.rb', line 63 def transaction_id response_code end |
#uncaptured_amount ⇒ BigDecimal
Returns the total amount left uncaptured on this payment.
143 144 145 |
# File 'app/models/spree/payment.rb', line 143 def uncaptured_amount amount - captured_amount end |