Class: Pluggy::Resources::Bill
- Inherits:
-
APIResource
- Object
- PluggyObject
- APIResource
- Pluggy::Resources::Bill
- Defined in:
- lib/pluggy/resources/bill.rb
Overview
A credit-card statement.
Bills carry no line items of their own -- see #transactions.
Constant Summary collapse
- FALLBACK_WINDOW_DAYS =
How far back to look when the previous cycle is unknown. Two months plus slack, so a 31-day cycle plus a late closing date still fits.
62
Constants inherited from PluggyObject
PluggyObject::ISO8601, PluggyObject::RESERVED, PluggyObject::TEMPORAL_KEYS
Instance Attribute Summary collapse
-
#previous_closing_date ⇒ Object
Stamped by BillService#list, which sees the whole cycle sequence and can therefore give #transactions an exact one-cycle window.
Attributes inherited from PluggyObject
Instance Method Summary collapse
- #account ⇒ Object
- #finance_charges_total ⇒ Object
- #paid? ⇒ Boolean
-
#transactions(strategy: :v2, date_from: nil, date_to: nil, **filters) ⇒ Object
The bill's line items.
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 Attribute Details
#previous_closing_date ⇒ Object
Stamped by BillService#list, which sees the whole cycle sequence and can therefore give #transactions an exact one-cycle window. Nil for a bill fetched on its own via bills.retrieve.
39 40 41 |
# File 'lib/pluggy/resources/bill.rb', line 39 def previous_closing_date @previous_closing_date end |
Instance Method Details
#account ⇒ Object
52 |
# File 'lib/pluggy/resources/bill.rb', line 52 def account = ensure_client!.accounts.retrieve(self["accountId"]) |
#finance_charges_total ⇒ Object
48 49 50 |
# File 'lib/pluggy/resources/bill.rb', line 48 def finance_charges_total (finance_charges || []).sum { |c| c["amount"] || 0 } end |
#paid? ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/pluggy/resources/bill.rb', line 41 def paid? list = payments return false if list.nil? || list.empty? list.sum { |p| p["amount"] || 0 } >= (self["totalAmount"] || 0) end |
#transactions(strategy: :v2, date_from: nil, date_to: nil, **filters) ⇒ Object
The bill's line items.
GET /v2/transactions has no billId filter (v1 had one, but v1 is deprecated with a 2026-12-31 sunset), so this lists the account's transactions over the statement cycle and filters on creditCardMetadata.billId.
The billId check is authoritative and always runs, so the date window only affects how many requests are made, never which transactions come back -- a wrong window yields a slower answer, never a wrong one.
Pass strategy: :legacy for a single server-side-filtered request
against the deprecated v1 endpoint.
Returns an Enumerator rather than a list object, because the count is
only knowable after filtering. Nothing is requested until you iterate,
and .map/.select behave normally (returning Arrays) -- unlike a
lazy enumerator, which would surprise callers. Chain .lazy yourself
if you want lazy semantics downstream.
With strategy: :legacy it returns a real list object instead, since the server did the filtering.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pluggy/resources/bill.rb', line 76 def transactions(strategy: :v2, date_from: nil, date_to: nil, **filters) # Validated up front rather than on first iteration: a missing client or # accountId is a programming error, and deferring it to somewhere deep in # an enumerator makes it much harder to place. ensure_client! require_account_id! if strategy == :legacy return @client.transactions.list( account_id: require_account_id!, bill_id: self["id"], **filters ) end unless block_given? return enum_for(:transactions, strategy: strategy, date_from: date_from, date_to: date_to, **filters) end bill_id = self["id"] @client.transactions .list(account_id: require_account_id!, date_from: date_from || window_start, date_to: date_to || window_end, **filters) .auto_paging_each { |t| yield t if t.bill_id == bill_id } end |