MishkaPay.Meter (Mishka Pay v0.0.1)

Copy Markdown View Source

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, :count of the reports, or the :last value reported.

What the provider fills in: :id, :status (:active or :inactive) and :created_at.

Summary

Types

t()

The struct that builder/1 returns.

Functions

A sample %MishkaPay.Meter{} populated from defaults + type-based fallbacks.

Types

t()

@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.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t() | nilnosanitize(trim) validate(string, not_empty)
:tenantterm() | nilno
:idString.t() | nilnovalidate(string)
:nameString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=250)
:event_nameString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=100)
:aggregation:sum | :count | :last | nilno:sumvalidate(not_nil_value, enum=Atom[sum::count::last])<br>validator {MishkaPay.Meter, :aggregation}
:status:active | :inactive | nilnovalidate(enum=Atom[active::inactive])
:created_atDateTime.t() | nilnovalidate(struct)

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

A sample %MishkaPay.Meter{} populated from defaults + type-based fallbacks.

keys()

keys(field)