Class: Monzo::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/monzo/transaction.rb

Overview

Public: Transactions are movements of funds into or out of an account.

Negative transactions represent debits (ie. spending money) and
positive transactions represent credits (ie. receiving money).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Transaction

Public: Initialize a Transaction.

params - A Hash of transaction parameters.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/monzo/transaction.rb', line 17

def initialize(params)
  @id = params[:id]
  @created = params[:created]
  @description = params[:description]
  @amount = params[:amount]
  @currency = params[:currency]
  @merchant = params[:merchant]
  @notes = params[:notes]
  @metadata = params[:metadata]
  @account_balance = params[:account_balance]
  @attachments = params[:attachments]
  @category = params[:category]
  @is_load = params[:is_load]
  @settled = params[:settled]
  @local_amount = params[:local_amount]
  @local_currency = params[:local_currency]
  @updated = params[:updated]
  @account_id = params[:account_id]
  @counterparty = params[:counterparty]
  @scheme = params[:scheme]
  @dedupe_id = params[:dedupe_id]
  @originator = params[:originator]
  @include_in_spending = params[:include_in_spending]
end

Instance Attribute Details

#account_balanceObject (readonly)

Returns the value of attribute account_balance.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def 
  @account_balance
end

#account_idObject (readonly)

Returns the value of attribute account_id.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def 
  @account_id
end

#amountObject (readonly)

Returns the value of attribute amount.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def amount
  @amount
end

#attachmentsObject (readonly)

Returns the value of attribute attachments.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def attachments
  @attachments
end

#categoryObject (readonly)

Returns the value of attribute category.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def category
  @category
end

#counterpartyObject (readonly)

Returns the value of attribute counterparty.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def counterparty
  @counterparty
end

#createdObject (readonly)

Returns the value of attribute created.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def created
  @created
end

#currencyObject (readonly)

Returns the value of attribute currency.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def currency
  @currency
end

#dedupe_idObject (readonly)

Returns the value of attribute dedupe_id.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def dedupe_id
  @dedupe_id
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def id
  @id
end

#include_in_spendingObject (readonly)

Returns the value of attribute include_in_spending.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def include_in_spending
  @include_in_spending
end

#is_loadObject (readonly)

Returns the value of attribute is_load.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def is_load
  @is_load
end

#local_amountObject (readonly)

Returns the value of attribute local_amount.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def local_amount
  @local_amount
end

#local_currencyObject (readonly)

Returns the value of attribute local_currency.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def local_currency
  @local_currency
end

#merchantObject (readonly)

Returns the value of attribute merchant.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def merchant
  @merchant
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def 
  @metadata
end

#notesObject (readonly)

Returns the value of attribute notes.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def notes
  @notes
end

#originatorObject (readonly)

Returns the value of attribute originator.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def originator
  @originator
end

#schemeObject (readonly)

Returns the value of attribute scheme.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def scheme
  @scheme
end

#settledObject (readonly)

Returns the value of attribute settled.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def settled
  @settled
end

#updatedObject (readonly)

Returns the value of attribute updated.



8
9
10
# File 'lib/monzo/transaction.rb', line 8

def updated
  @updated
end

Class Method Details

.all(account_id) ⇒ Object

Public: Find all the transactions for a given account id.

account_id - The account id to retrieve transactions from.

Returns an Array of Monzo::Transaction.



61
62
63
64
65
66
67
68
# File 'lib/monzo/transaction.rb', line 61

def self.all()
  response = Monzo.client.get("/transactions", :account_id => )
  parsed_response = JSON.parse(response.body, :symbolize_names => true)

  parsed_response[:transactions].map do |item|
    Monzo::Transaction.new(item)
  end
end

.create_annotation(transaction_id, metadata) ⇒ Object

Public: Create an annotation for a given transaction id. You may store your own key-value annotations against a transaction in its metadata.

transaction_id - The transaction id to annotate. metadata - a hash of annotations to add.

Returns an instance of Monzo::Transaction with the annotations.



77
78
79
80
81
82
83
84
85
86
# File 'lib/monzo/transaction.rb', line 77

def self.create_annotation(transaction_id, )
  data = {}
  .each do |k, v|
    data["metadata[#{k.to_s}]"] = v
  end
  response = Monzo.client.patch("/transactions/#{transaction_id}", data, {})
  parsed_response = JSON.parse(response.body, :symbolize_names => true)

  Monzo::Transaction.new(parsed_response[:transaction])
end

.find(transaction_id, options = {}) ⇒ Object

Public: Find a transaction with the given transaction id.

transaction_id - The id to find. options - a Hash of options to request further information such as the

merchant information (optional)

Returns an instance of Monzo::Transaction.



49
50
51
52
53
54
# File 'lib/monzo/transaction.rb', line 49

def self.find(transaction_id, options = {})
  response = Monzo.client.get("/transactions/#{transaction_id}", options)
  parsed_response = JSON.parse(response.body, :symbolize_names => true)

  Monzo::Transaction.new(parsed_response[:transaction])
end