A meter counts what customers use, for prices billed by usage (mtr_... at Stripe). A
guarded_struct.
Made with MishkaPay.create_meter/1, listed with MishkaPay.list_meters/3, turned off with
MishkaPay.deactivate_meter/3 (a provider never deletes one). Usage reaches it with
MishkaPay.report_usage/1 under its :event_name, and a price bills it with :meter_id and an
:interval (MishkaPay.create_price/1).
What the caller gives:
:provider,:tenant: which provider, with whose keys.:name: the meter's name, for the seller only.:event_name: the name usage is reported under, such as"api_call".:aggregation: how a period's usage adds up::sum(the default) of the values,:countof the reports, or the:lastvalue reported.
What the provider fills in: :id, :status (:active or :inactive) and :created_at.
Summary
Functions
A sample %MishkaPay.Meter{} populated from defaults + type-based fallbacks.
Types
@type t() :: %MishkaPay.Meter{ aggregation: (:sum | :count | :last) | nil, created_at: DateTime.t() | nil, event_name: String.t() | nil, id: String.t() | nil, name: String.t() | nil, provider: String.t() | nil, status: (:active | :inactive) | nil, tenant: term() | nil }
The struct that builder/1 returns.
| Field | Type | Required | Default | Description | Derives |
|---|---|---|---|---|---|
:provider | String.t() | nil | no | sanitize(trim) validate(string, not_empty) | ||
:tenant | term() | nil | no | |||
:id | String.t() | nil | no | validate(string) | ||
:name | String.t() | nil | no | sanitize(trim) validate(string, not_empty, max_len=250) | ||
:event_name | String.t() | nil | no | sanitize(trim) validate(string, not_empty, max_len=100) | ||
:aggregation | :sum | :count | :last | nil | no | :sum | validate(not_nil_value, enum=Atom[sum::count::last])<br>validator {MishkaPay.Meter, :aggregation} | |
:status | :active | :inactive | nil | no | validate(enum=Atom[active::inactive]) | ||
:created_at | DateTime.t() | nil | no | validate(struct) |