Class: Transactionable::CreditCard

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/transactionable/credit_card.rb

Instance Method Summary collapse

Instance Method Details

#amount_in_cents(amount) ⇒ Object



23
24
25
# File 'app/models/transactionable/credit_card.rb', line 23

def amount_in_cents(amount)
  (amount*100).to_i
end

#debit!(amount) ⇒ Object



15
16
17
18
19
20
21
# File 'app/models/transactionable/credit_card.rb', line 15

def debit!(amount)
  # TODO: Consider whether to assume that this method takes
  # decimal/float dollar values
  remote_debit = remote.debit(amount: amount_in_cents(amount))
  transaction = Transactionable::Debit.create_from_remote(remote_debit)
  debits << transaction
end

#remoteObject



9
10
11
12
13
# File 'app/models/transactionable/credit_card.rb', line 9

def remote
  if remote_credit_card && remote_credit_card.synced?
    remote_credit_card.fetch
  end
end

#syncObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/transactionable/credit_card.rb', line 27

def sync
  remote_cc = self.remote
  self.name = remote_cc.name
  self.description = "#{remote_cc.brand} (#{remote_cc.last_four})"
  self.last_four = remote_cc.last_four
  self.brand = remote_cc.brand
  self.expiration_month = remote_cc.expiration_month
  self.expiration_year = remote_cc.expiration_year
  self.expiration_date = Date.parse("#{expiration_month}/#{expiration_year}")
  save
end