Class: Belvo::Transaction

Inherits:
Resource show all
Defined in:
lib/belvo/resources.rb

Overview

A Transaction contains the detailed information of each movement inside an Account.

Instance Attribute Summary

Attributes inherited from Resource

#endpoint

Instance Method Summary collapse

Methods inherited from Resource

#clean, #delete, #detail, #resume

Constructor Details

#initialize(session) ⇒ Transaction

Returns a new instance of Transaction.



177
178
179
180
# File 'lib/belvo/resources.rb', line 177

def initialize(session)
  super(session)
  @endpoint = 'api/transactions/'
end

Instance Method Details

#list(params: nil) {|Hash| ... } ⇒ Array

List all transactions for specific link id

Parameters:

  • id (String)

    Resource ID

  • params (Hash) (defaults to: nil)

    Extra parameters sent as query strings.

Yields:

  • (Hash)

    Each result to be processed individually.

Returns:

  • (Array)

    List of results when no block is passed.

Raises:



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/belvo/resources.rb', line 188

def list(params: nil)
  params = {} if params.nil?
  unless params.key?(:link)
    raise RequestError.new(
      'Link id required',
      400,
      'A link ID is required to list transactions'
    )
  end
  @session.list(@endpoint, params: params)
end

#retrieve(link:, date_from:, options: nil) ⇒ Hash

Retrieve transactions from an existing link

Parameters:

  • link (String)

    Link UUID

  • date_from (String)

    Date string (YYYY-MM-DD)

  • options (TransactionOptions) (defaults to: nil)

    Configurable properties

Returns:

  • (Hash)

    created transactions details

Raises:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/belvo/resources.rb', line 206

def retrieve(link:, date_from:, options: nil)
  options = TransactionOptions.from(options)
  date_to = options.date_to || Date.today.to_s
  body = {
    link: link,
    date_from: date_from,
    date_to: date_to,
    token: options.token,
    account: options.,
    save_data: options.save_data || true
  }.merge(options)
  body = clean body: body
  @session.post(@endpoint, body)
end