class StarkBank::Transaction

# Transaction object

A Transaction is a transfer of funds between workspaces inside Stark Bank. Transactions created by the user are only for internal transactions. Other operations (such as transfer or charge-payment) will automatically create a transaction for the user which can be retrieved for the statement. When you initialize a Transaction, the entity will not be automatically created in the Stark Bank API. The 'create' function sends the objects to the Stark Bank API and returns the list of created objects.

## Parameters (required):

## Parameters (optional):

## Attributes (return-only):

Attributes

amount[R]
created[R]
description[R]
external_id[R]
fee[R]
id[R]
receiver_id[R]
sender_id[R]
source[R]
tags[R]

Public Class Methods

create(transactions, user: nil) click to toggle source

# Create Transactions

Send a list of Transaction objects for creation in the Stark Bank API

## Parameters (required):

## Parameters (optional):

## Return:

# File lib/transaction/transaction.rb, line 62
def self.create(transactions, user: nil)
  StarkBank::Utils::Rest.post(entities: transactions, user: user, **resource)
end
get(id, user: nil) click to toggle source

# Retrieve a specific Transaction

Receive a single Transaction object previously created in the Stark Bank API by passing its id

## Parameters (required):

  • id [string]: object unique id. ex: '5656565656565656'

## Parameters (optional):

## Return:

# File lib/transaction/transaction.rb, line 78
def self.get(id, user: nil)
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
end
new(amount:, description:, external_id:, receiver_id:, sender_id: nil, tags: nil, id: nil, fee: nil, source: nil, balance: nil, created: nil) click to toggle source
Calls superclass method StarkBank::Utils::Resource::new
# File lib/transaction/transaction.rb, line 36
def initialize(amount:, description:, external_id:, receiver_id:, sender_id: nil, tags: nil, id: nil, fee: nil, source: nil, balance: nil, created: nil)
  super(id)
  @amount = amount
  @description = description
  @external_id = external_id
  @receiver_id = receiver_id
  @sender_id = sender_id
  @tags = tags
  @fee = fee
  @source = source
  @balance = balance
  @created = StarkBank::Utils::Checks.check_datetime(created)
end
page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil) click to toggle source

# Retrieve paged Transactions

Receive a list of up to 100 Transaction objects previously created in the Stark Bank API and the cursor to the next page. Use this function instead of query if you want to manually page your requests.

## Parameters (optional):

  • cursor [string, default nil]: cursor returned on the previous page function call

  • limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35

  • after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)

  • before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)

  • status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']

  • ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • list of Transaction objects with updated attributes and cursor to retrieve the next page of Transaction objects

# File lib/transaction/transaction.rb, line 129
def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  return StarkBank::Utils::Rest.get_page(
    cursor: cursor,
    limit: limit,
    after: after,
    before: before,
    tags: tags,
    external_ids: external_ids,
    ids: ids,
    user: user,
    **resource
  )
end
query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil) click to toggle source

# Retrieve Transactions

Receive a generator of Transaction objects previously created in the Stark Bank API

## Parameters (optional):

  • limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35

  • after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)

  • before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']

  • external_ids [list of strings, default nil]: list of external ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']

  • ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • generator of Transaction objects with updated attributes

# File lib/transaction/transaction.rb, line 97
def self.query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_stream(
    limit: limit,
    after: after,
    before: before,
    tags: tags,
    external_ids: external_ids,
    ids: ids,
    user: user,
    **resource
  )
end
resource() click to toggle source
# File lib/transaction/transaction.rb, line 145
def self.resource
  {
    resource_name: 'Transaction',
    resource_maker: proc { |json|
      Transaction.new(
        amount: json['amount'],
        description: json['description'],
        external_id: json['external_id'],
        receiver_id: json['receiver_id'],
        sender_id: json['sender_id'],
        tags: json['tags'],
        id: json['id'],
        fee: json['fee'],
        source: json['source'],
        balance: json['balance'],
        created: json['created']
      )
    }
  }
end