Sha256: 0946259122724b5c0fc2e11ad2d90b7cbd4ef252806886e6784e7ac7d7a3462a
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
module Transactionable class BankAccount < ActiveRecord::Base belongs_to :bank_accountable, polymorphic: true has_one :remote_bank_account, as: :local_entity, dependent: :destroy has_many :transactions, as: :transactionable has_many :credits, as: :transactionable has_many :reversals, as: :transactionable TYPES = ["checking", "savings"] def remote if remote_bank_account && remote_bank_account.synced? remote_bank_account.fetch end end def sync balanced_bank_account = remote self.bank_name = balanced_bank_account.bank_name self.description = balanced_bank_account.account_number self.name = balanced_bank_account.name self.can_debit = balanced_bank_account.can_debit self.account_type = balanced_bank_account.type save end def credit!(amount) remote_credit = remote.credit(amount: amount_in_cents(amount)) transaction = Transactionable::Credit.create_from_remote(remote_credit) credits << transaction end def amount_in_cents(amount) (amount * 100).to_i end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
transactionable-0.3.1 | app/models/transactionable/bank_account.rb |