Sha256: 01700d264dae26d90f03f1f082d2c5b5f144fc3d5077b856f83d91c488c40c7b

Contents?: true

Size: 606 Bytes

Versions: 5

Compression:

Stored size: 606 Bytes

Contents

require 'aasm'

module PuntoPagosRails
  class Transaction < ActiveRecord::Base
    include AASM

    belongs_to :payable, polymorphic: true

    delegate :amount, to: :payable

    aasm column: :state do
      state :pending, initial: true
      state :completed
      state :rejected

      event :complete do
        transitions from: :pending, to: :completed
      end

      event :reject do
        transitions from: :pending, to: :rejected
      end
    end

    def reject_with(error)
      self.error = error
      reject
    end

    def amount_to_s
      "%0.2f" % amount.to_i
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
punto_pagos_rails-1.2.0 app/models/punto_pagos_rails/transaction.rb
punto_pagos_rails-1.1.0 app/models/punto_pagos_rails/transaction.rb
punto_pagos_rails-1.0.2 app/models/punto_pagos_rails/transaction.rb
punto_pagos_rails-1.0.1 app/models/punto_pagos_rails/transaction.rb
punto_pagos_rails-1.0.0 app/models/punto_pagos_rails/transaction.rb