Class: Plaid::Transaction
- Inherits:
-
Object
- Object
- Plaid::Transaction
- Defined in:
- lib/plaid/transaction.rb
Overview
Public: Representation of a transaction.
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Public: The String ID of the account in which this transaction occurred.
-
#amount ⇒ Object
readonly
Public: The settled dollar value as Float.
-
#category_hierarchy ⇒ Object
readonly
Public: The Array of String category hierarchy.
-
#category_id ⇒ Object
readonly
Public: The String Category ID.
-
#date ⇒ Object
readonly
Public: The Date that the transaction took place.
-
#id ⇒ Object
readonly
Public: The String unique ID of the transaction.
-
#location ⇒ Object
readonly
Public: The Hash with location information obtained from the meta field.
-
#meta ⇒ Object
readonly
Public: The Hash with additional information regarding the transaction.
-
#name ⇒ Object
readonly
Public: The String descriptive name of the transaction.
-
#pending ⇒ Object
readonly
Public: The Boolean flag which identifies the transaction as pending or unsettled.
-
#pending_transaction_id ⇒ Object
readonly
Public: The String ID of a posted transaction’s associated pending transaction - where applicable.
-
#reference_number ⇒ Object
readonly
Public: A String attribute that is used by the bank/payment processor to identify transactions — where applicable.
-
#score ⇒ Object
readonly
Public: The Hash with numeric representation of Plaid confidence in the meta data attached to the transaction.
-
#type ⇒ Object
readonly
Public: The Hash transaction type.
Instance Method Summary collapse
-
#initialize(fields) ⇒ Transaction
constructor
Public: Initialize a Transaction instance.
-
#inspect ⇒ Object
(also: #to_s)
Public: Get a String representation of the transaction.
-
#pending? ⇒ Boolean
Public: Detect if the transaction is pending or unsettled.
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_id ⇒ Object (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 @account_id end |
#amount ⇒ Object (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_hierarchy ⇒ Object (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_id ⇒ Object (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 |
#date ⇒ Object (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 |
#id ⇒ Object (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 |
#location ⇒ Object (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 |
#meta ⇒ Object (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 end |
#name ⇒ Object (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 |
#pending ⇒ Object (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_id ⇒ Object (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_number ⇒ Object (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 |
#score ⇒ Object (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 |
#type ⇒ Object (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
#inspect ⇒ Object 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=#{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.
110 111 112 |
# File 'lib/plaid/transaction.rb', line 110 def pending? pending end |