AuroraMeter. Schema. CreditTransaction
(Aurora Meter v0.4.0)
View Source
One append-only entry in a tenant's credit ledger, in micro-dollars.
kind says what happened and amount is the signed delta it applied to the
balance (grant positive; settle, debit and expire negative or zero;
hold and release zero, moving held_delta instead). balance_after and
held_after snapshot the row after the entry, so the log alone reproduces
every balance.
balance_after, held_after and promotional_after snapshot the row after
the entry, so the log alone reproduces every figure.
reference is the caller's idempotency key: unique per kind, so a retried
grant is returned instead of credited twice and a retried hold or debit is
refused. A hold carries status (:pending, :settled, :released) and,
once settled, settled_amount; a promotional grant may carry expires_at
and gets expired_at when AuroraMeter.Credits.expire_due/1 consumes it.
category names where a grant's money came from (:paid, :promotional,
:adjustment) and, on a debit, marks :reversal — a refund or chargeback
taking a paid grant back. A reversal never consumes promotional credit and is
reported against grants rather than as spend.
Summary
Types
@type category() :: :paid | :promotional | :adjustment | :reversal
@type kind() :: :grant | :hold | :settle | :release | :debit | :expire
@type status() :: :pending | :settled | :released
@type t() :: %AuroraMeter.Schema.CreditTransaction{ __meta__: term(), amount: term(), balance_after: term(), category: term(), expired_at: term(), expires_at: term(), held_after: term(), held_delta: term(), id: term(), inserted_at: term(), kind: term(), metadata: term(), promotional_after: term(), reference: term(), settled_amount: term(), status: term(), tenant_key: term() }
Functions
@spec categories() :: [category()]
The grant categories.
Examples
iex> AuroraMeter.Schema.CreditTransaction.categories()
[:paid, :promotional, :adjustment]
@spec changeset(t(), map()) :: Ecto.Changeset.t()
Builds a changeset for a ledger entry.
@spec kinds() :: [kind()]
The transaction kinds.
Examples
iex> :hold in AuroraMeter.Schema.CreditTransaction.kinds()
true