Class: AfterbanksPSD2::Transaction

Inherits:
Resource
  • Object
show all
Defined in:
lib/afterbanks_psd2/resources/transaction.rb

Class Method Summary collapse

Methods inherited from Resource

fields_information, #fields_information, has_fields, #initialize

Constructor Details

This class inherits a constructor from AfterbanksPSD2::Resource

Class Method Details

.list(token:, products:, start_date:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/afterbanks_psd2/resources/transaction.rb', line 12

def self.list(token:, products:, start_date:)
  params = {
    servicekey: AfterbanksPSD2.configuration.servicekey,
    token:      token,
    products:   products,
    startDate:  start_date.strftime("%d-%m-%Y")
  }

  # if the start_date is older than 90 days, we need to increase timeout to 2 hours
  if start_date < Date.today << 3
    options = {
      timeout: 7200
    }
  end

  response, debug_id = AfterbanksPSD2.api_call(
    method:  :post,
    path:    '/transactions/',
    params:  params,
    options: options
  )

  Response.new(
    result:   Collection.new(
      transactions_information_for(
        response: response,
        products: products
      ),
      self
    ),
    body:     response,
    debug_id: debug_id
  )
end

.transactions_information_for(response:, products:) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/afterbanks_psd2/resources/transaction.rb', line 47

def self.transactions_information_for(response:, products:)
  transactions_information = []
  products_array = products.split(",")

  response.each do ||
    product = ['product']

    next unless products_array.include?(product)

    transactions = ['transactions']
    next if transactions.nil? || transactions.empty?

     = AfterbanksPSD2::Account.new()

    transactions.each do |transaction|
      transaction['account'] = 
    end

    transactions_information += transactions
  end

  transactions_information
end