Class: Pluggy::Services::TransactionService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/pluggy/services/transaction_service.rb

Constant Summary collapse

V2_PATH =
"/v2/transactions"
V1_PATH =
"/transactions"
V1_ONLY_PARAMS =

Filters that only exist on the deprecated v1 endpoint. Passing any of them routes there automatically.

%i[bill_id page page_size].freeze

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Pluggy::Services::BaseService

Instance Method Details

#list(account_id:, version: nil, **filters) ⇒ Object

List an account's transactions.

Defaults to GET /v2/transactions (cursor-paginated, current). Routes to the deprecated GET /transactions when a v1-only filter is given, or when version: :v1 is explicit.

v2 filters: date_from, date_to, created_at_from, ids, after v1 filters: from, to, created_at_from, ids, bill_id, page, page_size



21
22
23
24
25
26
# File 'lib/pluggy/services/transaction_service.rb', line 21

def list(account_id:, version: nil, **filters)
  require_args!(account_id: )

  resolved = version || implied_version(filters)
  resolved == :v1 ? list_v1(, **filters) : list_v2(, **filters)
end

#resume(next_token) ⇒ Object

Resume cursor pagination from a persisted CursorList#next_token.

The token is the whole "?..." query string the API handed back, filters included -- not a bare after value. See Lists::CursorList.



32
33
34
35
36
37
38
39
40
# File 'lib/pluggy/services/transaction_service.rb', line 32

def resume(next_token)
  token = next_token.to_s
  unless token.start_with?("?")
    raise ArgumentError,
      "expected a cursor token starting with '?' (use CursorList#next_token), got #{token.inspect}"
  end

  @requestor.list_raw("#{V2_PATH}#{token}", klass: Resources::Transaction, client: @client)
end

#retrieve(id) ⇒ Object



42
43
44
45
# File 'lib/pluggy/services/transaction_service.rb', line 42

def retrieve(id)
  require_args!(id: id)
  object_request(:get, "#{V1_PATH}/#{id}", klass: Resources::Transaction)
end

#update(id, category_id:) ⇒ Object

PATCH /transactions/id. Recategorizing is the only supported edit.



48
49
50
51
52
53
# File 'lib/pluggy/services/transaction_service.rb', line 48

def update(id, category_id:)
  require_args!(id: id, category_id: category_id)
  object_request(:patch, "#{V1_PATH}/#{id}",
    klass: Resources::Transaction,
    body: { category_id: category_id })
end