Class: Plaid::Transaction

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/plaid/models/transaction.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(pending_transaction_id:, category_id:, category:, location:, payment_meta:, account_owner:, name:, account_id:, amount:, iso_currency_code:, unofficial_currency_code:, date:, pending:, transaction_id:, payment_channel:, merchant_name:, authorized_date:, authorized_datetime:, datetime:, check_number:, transaction_code:, transaction_type: SKIP, original_description: SKIP, personal_finance_category: SKIP, additional_properties: nil) ⇒ Transaction

Returns a new instance of Transaction.



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/plaid/models/transaction.rb', line 262

def initialize(pending_transaction_id:, category_id:, category:, location:,
               payment_meta:, account_owner:, name:, account_id:, amount:,
               iso_currency_code:, unofficial_currency_code:, date:,
               pending:, transaction_id:, payment_channel:, merchant_name:,
               authorized_date:, authorized_datetime:, datetime:,
               check_number:, transaction_code:, transaction_type: SKIP,
               original_description: SKIP, personal_finance_category: 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
  @category_id = category_id
  @category = category
  @location = location
  @payment_meta = payment_meta
  @account_owner = 
  @name = name
  @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
  @payment_channel = payment_channel
  @merchant_name = merchant_name
  @authorized_date = authorized_date
  @authorized_datetime = authorized_datetime
  @datetime = datetime
  @check_number = check_number
  @transaction_code = transaction_code
  unless personal_finance_category == SKIP
    @personal_finance_category =
      personal_finance_category
  end
  @additional_properties = additional_properties
end

Instance Attribute Details

#account_idString

The ID of the account in which this transaction occurred.

Returns:

  • (String)


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

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)


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

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)


90
91
92
# File 'lib/plaid/models/transaction.rb', line 90

def amount
  @amount
end

#authorized_dateDate

The date that the transaction was authorized. Dates are returned in an [ISO 8601](wikipedia.org/wiki/ISO_8601) format ( ‘YYYY-MM-DD` ).

Returns:

  • (Date)


140
141
142
# File 'lib/plaid/models/transaction.rb', line 140

def authorized_date
  @authorized_date
end

#authorized_datetimeDateTime

Date and time when a transaction was authorized in [ISO 8601](wikipedia.org/wiki/ISO_8601) format ( ‘YYYY-MM-DDTHH:mm:ssZ` ). This field is only populated for UK institutions. For institutions in other countries, will be `null`.

Returns:

  • (DateTime)


148
149
150
# File 'lib/plaid/models/transaction.rb', line 148

def authorized_datetime
  @authorized_datetime
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])


41
42
43
# File 'lib/plaid/models/transaction.rb', line 41

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)


33
34
35
# File 'lib/plaid/models/transaction.rb', line 33

def category_id
  @category_id
end

#check_numberString

The check number of the transaction. This field is only populated for check transactions.

Returns:

  • (String)


161
162
163
# File 'lib/plaid/models/transaction.rb', line 161

def check_number
  @check_number
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)


112
113
114
# File 'lib/plaid/models/transaction.rb', line 112

def date
  @date
end

#datetimeDateTime

Date and time when a transaction was posted in [ISO 8601](wikipedia.org/wiki/ISO_8601) format ( ‘YYYY-MM-DDTHH:mm:ssZ` ). This field is only populated for UK institutions. For institutions in other countries, will be `null`.

Returns:

  • (DateTime)


156
157
158
# File 'lib/plaid/models/transaction.rb', line 156

def datetime
  @datetime
end

#iso_currency_codeString

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

Returns:

  • (String)


95
96
97
# File 'lib/plaid/models/transaction.rb', line 95

def iso_currency_code
  @iso_currency_code
end

#locationTransactionLocation

A representation of where a transaction took place

Returns:



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

def location
  @location
end

#merchant_nameString

The merchant name, as extracted by Plaid from the ‘name` field.

Returns:

  • (String)


135
136
137
# File 'lib/plaid/models/transaction.rb', line 135

def merchant_name
  @merchant_name
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)


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

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)


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

def original_description
  @original_description
end

#payment_channelPaymentChannel

The channel used to make a payment. ‘online:` transactions that took place online. `in store:` transactions that were made at a physical location. `other:` transactions that relate to banks, e.g. fees or deposits. This field replaces the `transaction_type` field.

Returns:



131
132
133
# File 'lib/plaid/models/transaction.rb', line 131

def payment_channel
  @payment_channel
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:



56
57
58
# File 'lib/plaid/models/transaction.rb', line 56

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)


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

def pending
  @pending
end

#pending_transaction_idString

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

Returns:

  • (String)


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

def pending_transaction_id
  @pending_transaction_id
end

#personal_finance_categoryPersonalFinanceCategory2

An identifier classifying the transaction type. This field is only populated for European institutions. For institutions in the US and Canada, this field is set to ‘null`. `adjustment:` Bank adjustment `atm:` Cash deposit or withdrawal via an automated teller machine `bank charge:` Charge or fee levied by the institution `bill payment`: Payment of a bill `cash:` Cash deposit or withdrawal `cashback:` Cash withdrawal while making a debit card purchase `cheque:` Document ordering the payment of money to another person or organization `direct debit:` Automatic withdrawal of funds initiated by a third party at a regular interval `interest:` Interest earned or incurred `purchase:` Purchase made with a debit or credit card `standing order:` Payment instructed by the account holder to a third party at a regular interval `transfer:` Transfer of money between accounts



203
204
205
# File 'lib/plaid/models/transaction.rb', line 203

def personal_finance_category
  @personal_finance_category
end

#transaction_codeTransactionCode

An identifier classifying the transaction type. This field is only populated for European institutions. For institutions in the US and Canada, this field is set to ‘null`. `adjustment:` Bank adjustment `atm:` Cash deposit or withdrawal via an automated teller machine `bank charge:` Charge or fee levied by the institution `bill payment`: Payment of a bill `cash:` Cash deposit or withdrawal `cashback:` Cash withdrawal while making a debit card purchase `cheque:` Document ordering the payment of money to another person or organization `direct debit:` Automatic withdrawal of funds initiated by a third party at a regular interval `interest:` Interest earned or incurred `purchase:` Purchase made with a debit or credit card `standing order:` Payment instructed by the account holder to a third party at a regular interval `transfer:` Transfer of money between accounts

Returns:



182
183
184
# File 'lib/plaid/models/transaction.rb', line 182

def transaction_code
  @transaction_code
end

#transaction_idString

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

Returns:

  • (String)


123
124
125
# File 'lib/plaid/models/transaction.rb', line 123

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:



20
21
22
# File 'lib/plaid/models/transaction.rb', line 20

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)


105
106
107
# File 'lib/plaid/models/transaction.rb', line 105

def unofficial_currency_code
  @unofficial_currency_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/plaid/models/transaction.rb', line 304

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  pending_transaction_id =
    hash.key?('pending_transaction_id') ? hash['pending_transaction_id'] : nil
  category_id = hash.key?('category_id') ? hash['category_id'] : nil
  category = hash.key?('category') ? hash['category'] : nil
  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'] : nil
  name = hash.key?('name') ? hash['name'] : nil
   = 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
  payment_channel =
    hash.key?('payment_channel') ? hash['payment_channel'] : nil
  merchant_name = hash.key?('merchant_name') ? hash['merchant_name'] : nil
  authorized_date =
    hash.key?('authorized_date') ? hash['authorized_date'] : nil
  authorized_datetime = if hash.key?('authorized_datetime')
                          (DateTimeHelper.from_rfc3339(hash['authorized_datetime']) if hash['authorized_datetime'])
                        end
  datetime = if hash.key?('datetime')
               (DateTimeHelper.from_rfc3339(hash['datetime']) if hash['datetime'])
             end
  check_number = hash.key?('check_number') ? hash['check_number'] : nil
  transaction_code =
    hash.key?('transaction_code') ? hash['transaction_code'] : nil
  transaction_type =
    hash.key?('transaction_type') ? hash['transaction_type'] : SKIP
  original_description =
    hash.key?('original_description') ? hash['original_description'] : SKIP
  if hash['personal_finance_category']
    personal_finance_category = PersonalFinanceCategory2.from_hash(hash['personal_finance_category'])
  end

  # 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.
  Transaction.new(pending_transaction_id: pending_transaction_id,
                  category_id: category_id,
                  category: category,
                  location: location,
                  payment_meta: payment_meta,
                  account_owner: ,
                  name: name,
                  account_id: ,
                  amount: amount,
                  iso_currency_code: iso_currency_code,
                  unofficial_currency_code: unofficial_currency_code,
                  date: date,
                  pending: pending,
                  transaction_id: transaction_id,
                  payment_channel: payment_channel,
                  merchant_name: merchant_name,
                  authorized_date: authorized_date,
                  authorized_datetime: authorized_datetime,
                  datetime: datetime,
                  check_number: check_number,
                  transaction_code: transaction_code,
                  transaction_type: transaction_type,
                  original_description: original_description,
                  personal_finance_category: personal_finance_category,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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
# File 'lib/plaid/models/transaction.rb', line 206

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['payment_channel'] = 'payment_channel'
  @_hash['merchant_name'] = 'merchant_name'
  @_hash['authorized_date'] = 'authorized_date'
  @_hash['authorized_datetime'] = 'authorized_datetime'
  @_hash['datetime'] = 'datetime'
  @_hash['check_number'] = 'check_number'
  @_hash['transaction_code'] = 'transaction_code'
  @_hash['personal_finance_category'] = 'personal_finance_category'
  @_hash
end

.nullablesObject

An array for nullable fields



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/plaid/models/transaction.rb', line 245

def self.nullables
  %w[
    pending_transaction_id
    category_id
    category
    account_owner
    original_description
    iso_currency_code
    unofficial_currency_code
    merchant_name
    authorized_date
    authorized_datetime
    datetime
    check_number
  ]
end

.optionalsObject

An array for optional fields



236
237
238
239
240
241
242
# File 'lib/plaid/models/transaction.rb', line 236

def self.optionals
  %w[
    transaction_type
    original_description
    personal_finance_category
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/plaid/models/transaction.rb', line 408

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}, payment_channel:"\
  " #{@payment_channel.inspect}, merchant_name: #{@merchant_name.inspect}, authorized_date:"\
  " #{@authorized_date.inspect}, authorized_datetime: #{@authorized_datetime.inspect},"\
  " datetime: #{@datetime.inspect}, check_number: #{@check_number.inspect}, transaction_code:"\
  " #{@transaction_code.inspect}, personal_finance_category:"\
  " #{@personal_finance_category.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_authorized_datetimeObject



383
384
385
# File 'lib/plaid/models/transaction.rb', line 383

def to_custom_authorized_datetime
  DateTimeHelper.to_rfc3339(authorized_datetime)
end

#to_custom_datetimeObject



387
388
389
# File 'lib/plaid/models/transaction.rb', line 387

def to_custom_datetime
  DateTimeHelper.to_rfc3339(datetime)
end

#to_sObject

Provides a human-readable string representation of the object.



392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/plaid/models/transaction.rb', line 392

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}, payment_channel: #{@payment_channel},"\
  " merchant_name: #{@merchant_name}, authorized_date: #{@authorized_date},"\
  " authorized_datetime: #{@authorized_datetime}, datetime: #{@datetime}, check_number:"\
  " #{@check_number}, transaction_code: #{@transaction_code}, personal_finance_category:"\
  " #{@personal_finance_category}, additional_properties: #{@additional_properties}>"
end