Class: Spree::BankSlip

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/bank_slip.rb

Instance Method Summary collapse

Instance Method Details

#actionsArray

Displays what actions can be done according to payments method

Returns:

  • (Array)

Author:

  • Isabella Santos



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)

Returns:

  • (Boolean)

Author:

  • Isabella Santos



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)

Returns:

  • (Boolean)

Author:

  • Isabella Santos



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

Returns:

  • (Boolean)

Author:

  • Isabella Santos



104
105
106
# File 'app/models/spree/bank_slip.rb', line 104

def canceled?
  status == 'canceled'
end

#currencyObject

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

#moneyObject 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

Returns:

  • (Boolean)

Author:

  • Isabella Santos



84
85
86
# File 'app/models/spree/bank_slip.rb', line 84

def paid?
  status == 'paid'
end

#pending?Boolean

Returns if billet is pending

Returns:

  • (Boolean)

Author:

  • Isabella Santos



94
95
96
# File 'app/models/spree/bank_slip.rb', line 94

def pending?
  status == 'pending'
end