Class: InvestecOpenApi::Models::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/investec_open_api/models/transaction.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_api(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/investec_open_api/models/transaction.rb', line 27

def self.from_api(params)
  if params['amount'].present?
    adjusted_amount = params['amount'] * 100
    adjusted_amount = -adjusted_amount if params['type'] == 'DEBIT'

    Money.rounding_mode = BigDecimal::ROUND_HALF_UP
    Money.locale_backend = :i18n
    params['amount'] = Money.from_cents(adjusted_amount, "ZAR")
  end

  if params['transactionDate']
    params['date'] = params['transactionDate']
  end

  super
end

Instance Method Details

#idObject

At this point, there is no unique identifier being returned from Investec’s API. This method serves to create a stable unique identifier based on the transaction details.



19
20
21
22
23
24
25
# File 'lib/investec_open_api/models/transaction.rb', line 19

def id
  [
    amount.to_i,
    description,
    date.to_s
  ].map(&:to_s).join('-')
end