Class: PbAPI::Resources::TransactionResource

Inherits:
PbAPI::Resource show all
Defined in:
lib/pb_api/resources/transaction_resource.rb

Overview

TransactionResource is responsible for fetching transaction data from the API. It supports three endpoints:

  1. Standard transactions endpoint (with a date interval).
  2. Interim transactions endpoint (for data from the last day up to today).
  3. Final transactions endpoint (for final transactions on the last day).

Each endpoint is paginated. The methods in this class return an Enumerator that lazily fetches and yields transactions page by page.

Constant Summary

Constants inherited from PbAPI::Resource

PbAPI::Resource::DATE_FORMAT_STRING

Instance Attribute Summary

Attributes inherited from PbAPI::Resource

#client

Instance Method Summary collapse

Methods inherited from PbAPI::Resource

#form_query, #initialize

Constructor Details

This class inherits a constructor from PbAPI::Resource

Instance Method Details

#common(uri:, query_params:) ⇒ Enumerator

Executes a paginated request for transactions.

Parameters:

  • uri (String)

    the API endpoint URI (e.g., "statements/transactions", "statements/transactions/interim", or "statements/transactions/final").

  • query_params (Hash)

    the query parameters generated by form_query.

Returns:

  • (Enumerator)

    an enumerator that yields each transaction as it is fetched.



27
28
29
30
31
32
# File 'lib/pb_api/resources/transaction_resource.rb', line 27

def common(uri:, query_params:)
  PbAPI::PaginationHelper
    .paginate(params_hash: query_params, key: "transactions", type: PbAPI::Models::Transaction) do |params|
    get_request(uri, params: params)
  end
end

#list(start_date:, end_date: nil, account: nil, next_page_id: nil, results_per_page: 20) ⇒ Enumerator

Retrieves transactions for a specified date range.

This method is used when you need to filter transactions by a start (and optional end) date. )

Examples:

transactions = PbAPI::Client.transactions.list(
 start_date: Date.new(2025, 2, 1),
 end_date:   Date.new(2025, 2, 28),
 account:    "UA1234567890",
 results_per_page: 50

Parameters:

  • start_date (Date)

    the starting date (required).

  • end_date (Date, nil) (defaults to: nil)

    the ending date (optional).

  • account (String, nil) (defaults to: nil)

    the account IBAN (optional). If omitted, data for all active accounts are returned.

  • next_page_id (String, nil) (defaults to: nil)

    an identifier for the next page (pagination).

  • results_per_page (Integer) (defaults to: 20)

    number of records per page (default: 20; maximum recommended: 100).

Returns:

  • (Enumerator)

    an enumerator that yields transaction objects.



53
54
55
56
57
58
59
60
61
62
# File 'lib/pb_api/resources/transaction_resource.rb', line 53

def list(start_date:, end_date: nil, account: nil, next_page_id: nil, results_per_page: 20)
  query_params = form_query(
    start_date:,
    end_date:,
    account:,
    follow_id: next_page_id,
    limit: results_per_page
  )
  common(uri: "statements/transactions", query_params: query_params)
end

#list_final(account: nil, next_page_id: nil, results_per_page: 20) ⇒ Enumerator

Retrieves final transactions.

Final endpoints return transactions for the final (last) day. Like the interim endpoint, date parameters are not required.

Parameters:

  • account (String, nil) (defaults to: nil)

    the account IBAN (optional).

  • next_page_id (String, nil) (defaults to: nil)

    an identifier for the next page (pagination).

  • results_per_page (Integer) (defaults to: 20)

    number of records per page (default: 20).

Returns:

  • (Enumerator)

    an enumerator that yields final transaction objects.



95
96
97
98
99
100
101
102
# File 'lib/pb_api/resources/transaction_resource.rb', line 95

def list_final(account: nil, next_page_id: nil, results_per_page: 20)
  query_params = form_query(
    account: ,
    follow_id: next_page_id,
    limit: results_per_page
  )
  common(uri: "statements/transactions/final", query_params: query_params)
end

#list_interim(account: nil, next_page_id: nil, results_per_page: 20) ⇒ Enumerator

Retrieves interim transactions.

Interim endpoints do not require date parameters; they return transactions for the period from the last day to today.

Parameters:

  • account (String, nil) (defaults to: nil)

    the account IBAN (optional).

  • next_page_id (String, nil) (defaults to: nil)

    an identifier for the next page (pagination).

  • results_per_page (Integer) (defaults to: 20)

    number of records per page (default: 20).

Returns:

  • (Enumerator)

    an enumerator that yields interim transaction objects.



75
76
77
78
79
80
81
82
# File 'lib/pb_api/resources/transaction_resource.rb', line 75

def list_interim(account: nil, next_page_id: nil, results_per_page: 20)
  query_params = form_query(
    account: ,
    follow_id: next_page_id,
    limit: results_per_page
  )
  common(uri: "statements/transactions/interim", query_params: query_params)
end