Class: Plaid::Transaction

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

Overview

Public: Representation of a transaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Transaction

Public: Initialize a Transaction instance.

fields - The Hash with fields.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/plaid/transaction.rb', line 88

def initialize(fields)
  @id = fields['_id']
  @account_id = fields['_account']

  @date = fields['date'] && Date.parse(fields['date'])
  @amount = fields['amount']
  @name = fields['name']
  @meta = Plaid.symbolize_hash(fields['meta'])
  @location = (@meta && @meta[:location]) || {}
  @pending = fields['pending']
  @reference_number = fields['_reference_number']
  @pending_transaction_id = fields['_pendingTransaction']
  @score = Plaid.symbolize_hash(fields['score'])

  @type = Plaid.symbolize_hash(fields['type'], values: true)
  @category_hierarchy = fields['category']
  @category_id = fields['category_id']
end

Instance Attribute Details

#account_idObject (readonly)

Public: The String ID of the account in which this transaction occurred. E.g. “XARE85EJqKsjxLp6XR8ocg8VakrkXpTXmRdOo”.



13
14
15
# File 'lib/plaid/transaction.rb', line 13

def 
  @account_id
end

#amountObject (readonly)

Public: The settled dollar value as Float. Positive values when money moves out of the account; negative values when money moves in. E.g. 0.10 (10 cents).



22
23
24
# File 'lib/plaid/transaction.rb', line 22

def amount
  @amount
end

#category_hierarchyObject (readonly)

Public: The Array of String category hierarchy.

E.g. [“Food and Drink”, “Restaurants”].



70
71
72
# File 'lib/plaid/transaction.rb', line 70

def category_hierarchy
  @category_hierarchy
end

#category_idObject (readonly)

Public: The String Category ID.

E.g. “13005000”.



75
76
77
# File 'lib/plaid/transaction.rb', line 75

def category_id
  @category_id
end

#dateObject (readonly)

Public: The Date that the transaction took place. E.g. #<Date: 2016-04-28 …>



17
18
19
# File 'lib/plaid/transaction.rb', line 17

def date
  @date
end

#idObject (readonly)

Public: The String unique ID of the transaction. E.g. “0AZ0De04KqsreDgVwM1RSRYjyd8yXxSDQ8Zxn”.



9
10
11
# File 'lib/plaid/transaction.rb', line 9

def id
  @id
end

#locationObject (readonly)

Public: The Hash with location information obtained from the meta field. The keys are Strings.

E.g. => “262 W 15th St”,

"city" => "New York",
"state" => "NY",
"zip" => "10011",
"coordinates" => {
  "lat" => 40.740352,
  "lon" => -74.001761
}


44
45
46
# File 'lib/plaid/transaction.rb', line 44

def location
  @location
end

#metaObject (readonly)

Public: The Hash with additional information regarding the transaction. The keys are Symbols. E.g. { location: { “city”: “San Francisco”, “state”: “CA” } }



31
32
33
# File 'lib/plaid/transaction.rb', line 31

def meta
  @meta
end

#nameObject (readonly)

Public: The String descriptive name of the transaction. E.g. “Golden Crepes”.



26
27
28
# File 'lib/plaid/transaction.rb', line 26

def name
  @name
end

#pendingObject (readonly)

Public: The Boolean flag which identifies the transaction as pending or unsettled.



48
49
50
# File 'lib/plaid/transaction.rb', line 48

def pending
  @pending
end

#pending_transaction_idObject (readonly)

Public: The String ID of a posted transaction’s associated pending transaction - where applicable.



83
84
85
# File 'lib/plaid/transaction.rb', line 83

def pending_transaction_id
  @pending_transaction_id
end

#reference_numberObject (readonly)

Public: A String attribute that is used by the bank/payment processor to identify transactions — where applicable.



79
80
81
# File 'lib/plaid/transaction.rb', line 79

def reference_number
  @reference_number
end

#scoreObject (readonly)

Public: The Hash with numeric representation of Plaid confidence in the meta data attached to the transaction. In the case of a score <.9 Plaid will default to guaranteed and known information. E.g.

{location: {

  "address" => 1,
  "city" => 1,
  "state" => 1
}, name: 0.9}.


60
61
62
# File 'lib/plaid/transaction.rb', line 60

def score
  @score
end

#typeObject (readonly)

Public: The Hash transaction type.

E.g. => :place.



65
66
67
# File 'lib/plaid/transaction.rb', line 65

def type
  @type
end

Instance Method Details

#inspectObject Also known as: to_s

Public: Get a String representation of the transaction.

Returns a String.



117
118
119
120
121
# File 'lib/plaid/transaction.rb', line 117

def inspect
  "#<Plaid::Transaction id=#{id.inspect}, account_id=#{.inspect}, " \
  "date=#{date}, amount=#{amount.inspect}, name=#{name.inspect}, " \
  "pending=#{pending.inspect}>"
end

#pending?Boolean

Public: Detect if the transaction is pending or unsettled.

Returns true if it is.

Returns:

  • (Boolean)


110
111
112
# File 'lib/plaid/transaction.rb', line 110

def pending?
  pending
end