MishkaPay.Ash.Tenant (Mishka Pay v0.0.1)

Copy Markdown View Source

How the Ash layer finds the tenant a provider call is for (MishkaPay.Credentials), so it works the same in a single-site project and in a multi-tenant one like Mishka CMS.

A Mishka Pay resource may carry Ash multitenancy on the host's own attribute:

multitenancy do
  strategy :attribute
  attribute :site_id
end

Its actions then run with the site as Ash's tenant (tenant: site.id), and that tenant is the one the provider's keys are read for; the listeners sync each webhook's row inside the webhook's own tenant (/pay/webhooks/stripe/<site id>). Without multitenancy the :tenant argument says it. The row keeps it in its :tenant attribute either way, so later actions (refund, cancel, edit) use the same keys. The webhook inbox stays global: a webhook arrives before any tenant is chosen.

Summary

Functions

attrs (a call's map) with tenant when they name none, so an action run in a site's Ash tenant calls the provider with that site's keys.

The tenant of an action: a create's :tenant argument, else Ash's tenant; a generic action's (:start_checkout) is Ash's tenant.

The Ash options a listener syncs resource with, for an event of tenant.

Functions

into(attrs, tenant)

@spec into(map(), String.t() | nil) :: map()

attrs (a call's map) with tenant when they name none, so an action run in a site's Ash tenant calls the provider with that site's keys.

of(changeset)

@spec of(Ash.Changeset.t() | Ash.ActionInput.t()) :: String.t() | nil

The tenant of an action: a create's :tenant argument, else Ash's tenant; a generic action's (:start_checkout) is Ash's tenant.

opts(resource, tenant)

@spec opts(module(), term()) :: keyword()

The Ash options a listener syncs resource with, for an event of tenant.