MishkaPay.Ash.Resource.Kinds (Mishka Pay v0.0.1)

Copy Markdown View Source

The shape of each kind of MishkaPay.Ash.Resource, in one place: its attributes, identities, calculations and actions (with their arguments, changes and options), the code interface name of each action, the listener that keeps it current and, for the inbox, its AshOban trigger. MishkaPay.Ash.Resource.ApplyKind adds them to a host's resource with Ash.Resource.Builder, skipping whatever the host defines itself.

Summary

Functions

The names of a kind's actions, in the order they are added.

The actions of a kind, with :resync for every provider object's kind. announce?: false builds their changes without the mishka_pay:<kind>:changed event; user: names the belongs_to_user attribute, which a sync writes from the owner and a customer's :register accepts.

The attributes of a kind, after its :id primary key and before its timestamps.

The calculations of a kind: its amounts as Money, and for a subscription :active? (gives access now, as MishkaPay.Ash.Subscribed counts it by default), :on_trial? and :canceling? (ends at the period's end), each usable in a filter or a sort.

The inbox's daily AshOban trigger that deletes processed events older than days.

The identity that keeps each provider object (or event) once.

The code interface name of an action. receive is an Elixir special form, so the inbox's :receive is receive_event.

Every kind.

The listener macro module that keeps a resource of the kind current from webhooks.

The hourly AshOban trigger that reads again, with :resync, the rows of kind still open at their provider and not read for hours; nil for a kind whose rows are never open.

The inbox's AshOban trigger, as oban do triggers do trigger :process ... end end writes it. Its worker and scheduler are named after the resource, so two inboxes never share them.

Types

action()

@type action() :: {atom(), Ash.Resource.Actions.action_type(), keyword()}

attribute()

@type attribute() :: {atom(), atom(), keyword()}

kind()

@type kind() ::
  :inbox
  | :payment
  | :subscription
  | :customer
  | :dispute
  | :product
  | :price
  | :coupon
  | :promotion_code
  | :payment_link
  | :invoice

Functions

action_names(kind)

@spec action_names(kind()) :: [atom()]

The names of a kind's actions, in the order they are added.

actions(kind, opts)

@spec actions(kind(), keyword()) :: [action()]

The actions of a kind, with :resync for every provider object's kind. announce?: false builds their changes without the mishka_pay:<kind>:changed event; user: names the belongs_to_user attribute, which a sync writes from the owner and a customer's :register accepts.

attributes(atom)

@spec attributes(kind()) :: [attribute()]

The attributes of a kind, after its :id primary key and before its timestamps.

calculations(arg1)

@spec calculations(kind()) :: [{atom(), atom(), term()}]

The calculations of a kind: its amounts as Money, and for a subscription :active? (gives access now, as MishkaPay.Ash.Subscribed counts it by default), :on_trial? and :canceling? (ends at the period's end), each usable in a filter or a sort.

forget_trigger(resource, days)

@spec forget_trigger(module(), pos_integer()) :: keyword()

The inbox's daily AshOban trigger that deletes processed events older than days.

identity(atom)

@spec identity(kind()) :: {atom(), [atom()]}

The identity that keeps each provider object (or event) once.

interface(action)

@spec interface(atom()) :: atom()

The code interface name of an action. receive is an Elixir special form, so the inbox's :receive is receive_event.

kinds()

@spec kinds() :: [kind()]

Every kind.

listener(kind)

@spec listener(kind()) :: module()

The listener macro module that keeps a resource of the kind current from webhooks.

resync_trigger(resource, kind, hours)

@spec resync_trigger(module(), kind(), pos_integer()) :: keyword() | nil

The hourly AshOban trigger that reads again, with :resync, the rows of kind still open at their provider and not read for hours; nil for a kind whose rows are never open.

trigger(resource)

@spec trigger(module()) :: keyword()

The inbox's AshOban trigger, as oban do triggers do trigger :process ... end end writes it. Its worker and scheduler are named after the resource, so two inboxes never share them.