Class: Pluggy::Resources::Transaction

Inherits:
APIResource show all
Defined in:
lib/pluggy/resources/transaction.rb

Constant Summary

Constants inherited from PluggyObject

PluggyObject::ISO8601, PluggyObject::RESERVED, PluggyObject::TEMPORAL_KEYS

Instance Attribute Summary

Attributes inherited from PluggyObject

#client

Instance Method Summary collapse

Methods inherited from PluggyObject

#==, #[], #as_json, declared_fields, define_field, #each_pair, fields, #hash, #initialize, #inspect, #key?, #keys, #method_missing, nested, nested_types, #read, #respond_to_missing?, #to_h, #to_json, #values

Constructor Details

This class inherits a constructor from Pluggy::PluggyObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pluggy::PluggyObject

Instance Method Details

#accountObject



100
# File 'lib/pluggy/resources/transaction.rb', line 100

def  = ensure_client!.accounts.retrieve(self["accountId"])

#billObject



81
82
83
84
# File 'lib/pluggy/resources/transaction.rb', line 81

def bill
  id = bill_id
  id && ensure_client!.bills.retrieve(id)
end

#bill_idObject

The bill this transaction belongs to. Since GET /v2/transactions dropped the billId filter, this is the authoritative way to group card transactions into statements.



79
# File 'lib/pluggy/resources/transaction.rb', line 79

def bill_id = &.[]("billId")

#boleto?Boolean

Returns:

  • (Boolean)


88
# File 'lib/pluggy/resources/transaction.rb', line 88

def boleto? = payment_method == "BOLETO"

#counterpartyObject

Whoever was on the other side: the receiver of an outflow, the payer of an inflow.



93
94
95
96
97
98
# File 'lib/pluggy/resources/transaction.rb', line 93

def counterparty
  data = payment_data
  return nil unless data

  debit? ? data.receiver : data.payer
end

#credit?Boolean Also known as: inflow?

Returns:

  • (Boolean)


57
# File 'lib/pluggy/resources/transaction.rb', line 57

def credit? = self["type"] == "CREDIT"

#credit_card?Boolean

Returns:

  • (Boolean)


66
# File 'lib/pluggy/resources/transaction.rb', line 66

def credit_card? = !self["creditCardMetadata"].nil?

#debit?Boolean Also known as: outflow?

Direction, from the account holder's point of view. Pluggy normalizes the credit-card convention, so a card purchase is always DEBIT and a payment towards the statement is always CREDIT.

Returns:

  • (Boolean)


56
# File 'lib/pluggy/resources/transaction.rb', line 56

def debit? = self["type"] == "DEBIT"

#installment?Boolean

Returns:

  • (Boolean)


68
# File 'lib/pluggy/resources/transaction.rb', line 68

def installment? = &.installment? || false

#installment_labelObject



70
71
72
73
74
# File 'lib/pluggy/resources/transaction.rb', line 70

def installment_label
  return nil unless installment?

  "#{["installmentNumber"]}/#{["totalInstallments"]}"
end

#payment_methodObject



86
# File 'lib/pluggy/resources/transaction.rb', line 86

def payment_method = payment_data&.[]("paymentMethod")

#pending?Boolean

Typical of card purchases not yet on a closed bill.

Returns:

  • (Boolean)


64
# File 'lib/pluggy/resources/transaction.rb', line 64

def pending? = self["status"] == "PENDING"

#pix?Boolean

Returns:

  • (Boolean)


87
# File 'lib/pluggy/resources/transaction.rb', line 87

def pix? = payment_method == "PIX"

#posted?Boolean

Returns:

  • (Boolean)


61
# File 'lib/pluggy/resources/transaction.rb', line 61

def posted? = self["status"] == "POSTED"

#recategorize(category_id) ⇒ Object

PATCH /transactions/id -- the only field Pluggy lets you change.



103
104
105
# File 'lib/pluggy/resources/transaction.rb', line 103

def recategorize(category_id)
  ensure_client!.transactions.update(self["id"], category_id: category_id)
end

#transfer?Boolean

Returns:

  • (Boolean)


89
# File 'lib/pluggy/resources/transaction.rb', line 89

def transfer? = %w[TED DOC TEV].include?(payment_method)