Class: Spree::BankSlip
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::BankSlip
- Defined in:
- app/models/spree/bank_slip.rb
Instance Method Summary collapse
-
#actions ⇒ Array
Displays what actions can be done according to payments method.
-
#amount=(amount) ⇒ Object
Save the amount of the billet if amount is a string, convert to a BigDecimal.
-
#can_capture?(payment) ⇒ Boolean
Determines whether can capture the payments (only can capture when the state is checkout or pending).
-
#can_void?(payment) ⇒ Boolean
Determines whether can void the payments (only can void when the state is different of void, failure or invalid).
-
#canceled? ⇒ Boolean
Returns if slip is canceled.
-
#currency ⇒ Object
Defines the currency of the billet based in te currency of the order.
-
#money ⇒ Object
(also: #display_amount)
Return the amount converted to Money according to currency.
-
#paid? ⇒ Boolean
Returns if billet is paid.
-
#pending? ⇒ Boolean
Returns if billet is pending.
Instance Method Details
#actions ⇒ Array
Displays what actions can be done according to payments method
15 16 17 18 19 20 |
# File 'app/models/spree/bank_slip.rb', line 15 def actions act = [] act << 'capture' if can_capture? payment act << 'void' if can_void? payment act end |
#amount=(amount) ⇒ Object
Save the amount of the billet if amount is a string, convert to a BigDecimal
copy of Spree::Payment.amount
27 28 29 30 31 32 33 34 35 |
# File 'app/models/spree/bank_slip.rb', line 27 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_capture?(payment) ⇒ Boolean
Determines whether can capture the payments (only can capture when the state is checkout or pending)
44 45 46 |
# File 'app/models/spree/bank_slip.rb', line 44 def can_capture?(payment) payment.pending? || payment.checkout? end |
#can_void?(payment) ⇒ Boolean
Determines whether can void the payments (only can void when the state is different of void, failure or invalid)
55 56 57 |
# File 'app/models/spree/bank_slip.rb', line 55 def can_void?(payment) !%w(void failure invalid canceled).include?(payment.state) end |
#canceled? ⇒ Boolean
Returns if slip is canceled
104 105 106 |
# File 'app/models/spree/bank_slip.rb', line 104 def canceled? status == 'canceled' end |
#currency ⇒ Object
Defines the currency of the billet based in te currency of the order
copy of Spree::Payment.currency
64 65 66 |
# File 'app/models/spree/bank_slip.rb', line 64 def currency order.currency end |
#money ⇒ Object Also known as: display_amount
Return the amount converted to Money according to currency
copy of Spree::Payment.money
73 74 75 |
# File 'app/models/spree/bank_slip.rb', line 73 def money Spree::Money.new(amount, { currency: currency }) end |
#paid? ⇒ Boolean
Returns if billet is paid
84 85 86 |
# File 'app/models/spree/bank_slip.rb', line 84 def paid? status == 'paid' end |
#pending? ⇒ Boolean
Returns if billet is pending
94 95 96 |
# File 'app/models/spree/bank_slip.rb', line 94 def pending? status == 'pending' end |