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

Raises:

  • (ArgumentError)


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
46
47
48
49
50
51
52
53
# File 'lib/afterbanks_psd2/resources/transaction.rb', line 12

def self.list(token:, products:, start_date:)
  raise ArgumentError, "Token is missing" if token.nil? || token.empty?
  raise ArgumentError, "Products must be a string" unless products.is_a?(String)
  raise ArgumentError, "Products is missing" if products.nil? || products.empty?
  raise ArgumentError, "Start date is missing" if start_date.nil? || products.empty?
  raise ArgumentError, "Start date must be a Date" unless start_date.is_a?(Date)

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

  options = {}

  # 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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/afterbanks_psd2/resources/transaction.rb', line 55

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

  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