Class: Plaid::TransactionBase

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/plaid/models/transaction_base.rb

Overview

A representation of a transaction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(account_id:, amount:, iso_currency_code:, unofficial_currency_code:, date:, pending:, transaction_id:, transaction_type: SKIP, pending_transaction_id: SKIP, category_id: SKIP, category: SKIP, location: SKIP, payment_meta: SKIP, account_owner: SKIP, name: SKIP, original_description: SKIP, additional_properties: nil) ⇒ TransactionBase

Returns a new instance of TransactionBase.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/plaid/models/transaction_base.rb', line 174

def initialize(account_id:, amount:, iso_currency_code:,
               unofficial_currency_code:, date:, pending:, transaction_id:,
               transaction_type: SKIP, pending_transaction_id: SKIP,
               category_id: SKIP, category: SKIP, location: SKIP,
               payment_meta: SKIP, account_owner: SKIP, name: SKIP,
               original_description: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @transaction_type = transaction_type unless transaction_type == SKIP
  @pending_transaction_id = pending_transaction_id unless pending_transaction_id == SKIP
  @category_id = category_id unless category_id == SKIP
  @category = category unless category == SKIP
  @location = location unless location == SKIP
  @payment_meta = payment_meta unless payment_meta == SKIP
  @account_owner =  unless  == SKIP
  @name = name unless name == SKIP
  @original_description = original_description unless original_description == SKIP
  @account_id = 
  @amount = amount
  @iso_currency_code = iso_currency_code
  @unofficial_currency_code = unofficial_currency_code
  @date = date
  @pending = pending
  @transaction_id = transaction_id
  @additional_properties = additional_properties
end

Instance Attribute Details

#account_idString

The ID of the account in which this transaction occurred.

Returns:

  • (String)


81
82
83
# File 'lib/plaid/models/transaction_base.rb', line 81

def 
  @account_id
end

#account_ownerString

The name of the account owner. This field is not typically populated and only relevant when dealing with sub-accounts.

Returns:

  • (String)


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

def 
  @account_owner
end

#amountFloat

The settled value of the transaction, denominated in the account’s currency, as stated in ‘iso_currency_code` or `unofficial_currency_code`. Positive values when money moves out of the account; negative values when money moves in. For example, debit card purchases are positive; credit card payments, direct deposits, and refunds are negative.

Returns:

  • (Float)


89
90
91
# File 'lib/plaid/models/transaction_base.rb', line 89

def amount
  @amount
end

#categoryArray[String]

A hierarchical array of the categories to which this transaction belongs. See [Categories](plaid.com/docs/#category-overview). If the ‘transactions` object was returned by an Assets endpoint such as `/asset_report/get/` or `/asset_report/pdf/get`, this field will only appear in an Asset Report with Insights.

Returns:

  • (Array[String])


40
41
42
# File 'lib/plaid/models/transaction_base.rb', line 40

def category
  @category
end

#category_idString

The ID of the category to which this transaction belongs. See [Categories](plaid.com/docs/#category-overview). If the ‘transactions` object was returned by an Assets endpoint such as `/asset_report/get/` or `/asset_report/pdf/get`, this field will only appear in an Asset Report with Insights.

Returns:

  • (String)


32
33
34
# File 'lib/plaid/models/transaction_base.rb', line 32

def category_id
  @category_id
end

#dateDate

For pending transactions, the date that the transaction occurred; for posted transactions, the date that the transaction posted. Both dates are returned in an [ISO 8601](wikipedia.org/wiki/ISO_8601) format ( ‘YYYY-MM-DD` ).

Returns:

  • (Date)


111
112
113
# File 'lib/plaid/models/transaction_base.rb', line 111

def date
  @date
end

#iso_currency_codeString

The ISO-4217 currency code of the transaction. Always ‘null` if `unofficial_currency_code` is non-null.

Returns:

  • (String)


94
95
96
# File 'lib/plaid/models/transaction_base.rb', line 94

def iso_currency_code
  @iso_currency_code
end

#locationTransactionLocation

A representation of where a transaction took place

Returns:



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

def location
  @location
end

#nameString

The merchant name or transaction description. If the ‘transactions` object was returned by a Transactions endpoint such as `/transactions/get`, this field will always appear. If the `transactions` object was returned by an Assets endpoint such as `/asset_report/get/` or `/asset_report/pdf/get`, this field will only appear in an Asset Report with Insights.

Returns:

  • (String)


69
70
71
# File 'lib/plaid/models/transaction_base.rb', line 69

def name
  @name
end

#original_descriptionString

The string returned by the financial institution to describe the transaction. For transactions returned by ‘/transactions/get`, this field is in beta and will be omitted unless the client is both enrolled in the closed beta program and has set `options.include_original_description` to `true`.

Returns:

  • (String)


77
78
79
# File 'lib/plaid/models/transaction_base.rb', line 77

def original_description
  @original_description
end

#payment_metaPaymentMeta

Transaction information specific to inter-bank transfers. If the transaction was not an inter-bank transfer, all fields will be ‘null`. If the `transactions` object was returned by a Transactions endpoint such as `/transactions/get`, the `payment_meta` key will always appear, but no data elements are guaranteed. If the `transactions` object was returned by an Assets endpoint such as `/asset_report/get/` or `/asset_report/pdf/get`, this field will only appear in an Asset Report with Insights.

Returns:



55
56
57
# File 'lib/plaid/models/transaction_base.rb', line 55

def payment_meta
  @payment_meta
end

#pendingTrueClass | FalseClass

When ‘true`, identifies the transaction as pending or unsettled. Pending transaction details (name, type, amount, category ID) may change before they are settled.

Returns:

  • (TrueClass | FalseClass)


117
118
119
# File 'lib/plaid/models/transaction_base.rb', line 117

def pending
  @pending
end

#pending_transaction_idString

The ID of a posted transaction’s associated pending transaction, where applicable.

Returns:

  • (String)


24
25
26
# File 'lib/plaid/models/transaction_base.rb', line 24

def pending_transaction_id
  @pending_transaction_id
end

#transaction_idString

The unique ID of the transaction. Like all Plaid identifiers, the ‘transaction_id` is case sensitive.

Returns:

  • (String)


122
123
124
# File 'lib/plaid/models/transaction_base.rb', line 122

def transaction_id
  @transaction_id
end

#transaction_typeTransactionType

Please use the ‘payment_channel` field, `transaction_type` will be deprecated in the future. `digital:` transactions that took place online. `place:` transactions that were made at a physical location. `special:` transactions that relate to banks, e.g. fees or deposits. `unresolved:` transactions that do not fit into the other three types.

Returns:



19
20
21
# File 'lib/plaid/models/transaction_base.rb', line 19

def transaction_type
  @transaction_type
end

#unofficial_currency_codeString

The unofficial currency code associated with the transaction. Always ‘null` if `iso_currency_code` is non-`null`. Unofficial currency codes are used for currencies that do not have official ISO currency codes, such as cryptocurrencies and the currencies of certain countries. See the [currency code schema](plaid.com/docs/api/accounts#currency-code-schema) for a full listing of supported `iso_currency_code`s.

Returns:

  • (String)


104
105
106
# File 'lib/plaid/models/transaction_base.rb', line 104

def unofficial_currency_code
  @unofficial_currency_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/plaid/models/transaction_base.rb', line 203

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
   = hash.key?('account_id') ? hash['account_id'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  iso_currency_code =
    hash.key?('iso_currency_code') ? hash['iso_currency_code'] : nil
  unofficial_currency_code =
    hash.key?('unofficial_currency_code') ? hash['unofficial_currency_code'] : nil
  date = hash.key?('date') ? hash['date'] : nil
  pending = hash.key?('pending') ? hash['pending'] : nil
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : nil
  transaction_type =
    hash.key?('transaction_type') ? hash['transaction_type'] : SKIP
  pending_transaction_id =
    hash.key?('pending_transaction_id') ? hash['pending_transaction_id'] : SKIP
  category_id = hash.key?('category_id') ? hash['category_id'] : SKIP
  category = hash.key?('category') ? hash['category'] : SKIP
  location = TransactionLocation.from_hash(hash['location']) if hash['location']
  payment_meta = PaymentMeta.from_hash(hash['payment_meta']) if hash['payment_meta']
   = hash.key?('account_owner') ? hash['account_owner'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  original_description =
    hash.key?('original_description') ? hash['original_description'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  TransactionBase.new(account_id: ,
                      amount: amount,
                      iso_currency_code: iso_currency_code,
                      unofficial_currency_code: unofficial_currency_code,
                      date: date,
                      pending: pending,
                      transaction_id: transaction_id,
                      transaction_type: transaction_type,
                      pending_transaction_id: pending_transaction_id,
                      category_id: category_id,
                      category: category,
                      location: location,
                      payment_meta: payment_meta,
                      account_owner: ,
                      name: name,
                      original_description: original_description,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/plaid/models/transaction_base.rb', line 125

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['transaction_type'] = 'transaction_type'
  @_hash['pending_transaction_id'] = 'pending_transaction_id'
  @_hash['category_id'] = 'category_id'
  @_hash['category'] = 'category'
  @_hash['location'] = 'location'
  @_hash['payment_meta'] = 'payment_meta'
  @_hash['account_owner'] = 'account_owner'
  @_hash['name'] = 'name'
  @_hash['original_description'] = 'original_description'
  @_hash['account_id'] = 'account_id'
  @_hash['amount'] = 'amount'
  @_hash['iso_currency_code'] = 'iso_currency_code'
  @_hash['unofficial_currency_code'] = 'unofficial_currency_code'
  @_hash['date'] = 'date'
  @_hash['pending'] = 'pending'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash
end

.nullablesObject

An array for nullable fields



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/plaid/models/transaction_base.rb', line 162

def self.nullables
  %w[
    pending_transaction_id
    category_id
    category
    account_owner
    original_description
    iso_currency_code
    unofficial_currency_code
  ]
end

.optionalsObject

An array for optional fields



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/plaid/models/transaction_base.rb', line 147

def self.optionals
  %w[
    transaction_type
    pending_transaction_id
    category_id
    category
    location
    payment_meta
    account_owner
    name
    original_description
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/plaid/models/transaction_base.rb', line 271

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} transaction_type: #{@transaction_type.inspect}, pending_transaction_id:"\
  " #{@pending_transaction_id.inspect}, category_id: #{@category_id.inspect}, category:"\
  " #{@category.inspect}, location: #{@location.inspect}, payment_meta:"\
  " #{@payment_meta.inspect}, account_owner: #{@account_owner.inspect}, name:"\
  " #{@name.inspect}, original_description: #{@original_description.inspect}, account_id:"\
  " #{@account_id.inspect}, amount: #{@amount.inspect}, iso_currency_code:"\
  " #{@iso_currency_code.inspect}, unofficial_currency_code:"\
  " #{@unofficial_currency_code.inspect}, date: #{@date.inspect}, pending:"\
  " #{@pending.inspect}, transaction_id: #{@transaction_id.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/plaid/models/transaction_base.rb', line 258

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} transaction_type: #{@transaction_type}, pending_transaction_id:"\
  " #{@pending_transaction_id}, category_id: #{@category_id}, category: #{@category},"\
  " location: #{@location}, payment_meta: #{@payment_meta}, account_owner: #{@account_owner},"\
  " name: #{@name}, original_description: #{@original_description}, account_id:"\
  " #{@account_id}, amount: #{@amount}, iso_currency_code: #{@iso_currency_code},"\
  " unofficial_currency_code: #{@unofficial_currency_code}, date: #{@date}, pending:"\
  " #{@pending}, transaction_id: #{@transaction_id}, additional_properties:"\
  " #{@additional_properties}>"
end