MishkaPay.Events (Mishka Pay v0.0.1)

Copy Markdown View Source

Every mishka_installer event Mishka Pay fires, in one place. Code and use macros call these functions and never write an event name by hand.

EventWho listensWhat it is for
mishka_pay:providerseach providersays which providers are installed
mishka_pay:credentialsthe hostgives the keys of a provider for one site
mishka_pay:checkout:beforethe hostchanges or refuses a checkout before the provider sees it
mishka_pay:webhook:receivedthe Ash inbox, or the hosta provider event whose signature was checked
mishka_pay:event:processthe host, or a payment resourceworks one event the Ash inbox stored
mishka_pay:payment:changedthe hosta payment's state after it was synced from the provider
mishka_pay:subscription:changedthe hosta subscription's state after it was synced, cancelled or resumed
mishka_pay:customer:changedthe hosta customer after it was registered, synced or edited
mishka_pay:dispute:changedthe hosta dispute after it was synced, answered or accepted

Summary

Functions

The event fired after a resource of kind wrote what its provider answered: "mishka_pay:<kind>:changed", with %{<kind> => struct, record: record}. For the payment, subscription, customer and dispute kinds it is the event of their own function above; for the catalog, coupons, promotion codes, payment links and bills (MishkaPay.Ash.Object.Spec) it is the only one.

Hosts listen here to change or refuse a checkout before the provider sees it. A plugin gets %{checkout: %MishkaPay.Checkout{}, refused: nil} and answers it with a changed :checkout, or with :refused set to a reason. See MishkaPay.checkout/1.

The host listens here and answers a provider's keys for one site.

Fired after a customer resource (the :customer kind of MishkaPay.Ash.Resource) registered, synced or edited a customer, with %{customer: %MishkaPay.Customer{}, record: record}. A host listens here to link the customer to its user, or to push the change to the screens that show it.

Fired after a dispute resource (the :dispute kind of MishkaPay.Ash.Resource) synced, answered or accepted a dispute, with %{dispute: %MishkaPay.Dispute{}, record: record}. A host listens here to take back what the payment gave while it is open, and give it again when it is won.

The inbox (the :inbox kind of MishkaPay.Ash.Resource) fires this to work one stored event, once per try. Listeners get %{event: %MishkaPay.Event{}, failed: nil} and answer it with :failed set to a reason when the work did not finish, so the inbox tries again later.

Fired after a payment resource (the :payment kind of MishkaPay.Ash.Resource) synced a payment from its provider, with %{payment: %MishkaPay.Payment{}, record: record}. A host listens here to act on a paid or refunded payment, or to push the change to the screens that show it.

Every provider listens here and adds itself to the providers list the event carries.

Fired after a subscription resource (the :subscription kind of MishkaPay.Ash.Resource) synced, cancelled or resumed a subscription, with %{subscription: %MishkaPay.Subscription{}, record: record}. A host listens here to give or take access, or to push the change to the screens that show it.

Listeners get every provider event whose signature was checked, as %{event: %MishkaPay.Event{}, failed: nil}, and answer it with :failed set to a reason when they could not take it, so the provider sends it again. See MishkaPay.Webhook.

Functions

changed(kind)

@spec changed(atom()) :: String.t()

The event fired after a resource of kind wrote what its provider answered: "mishka_pay:<kind>:changed", with %{<kind> => struct, record: record}. For the payment, subscription, customer and dispute kinds it is the event of their own function above; for the catalog, coupons, promotion codes, payment links and bills (MishkaPay.Ash.Object.Spec) it is the only one.

checkout_before()

@spec checkout_before() :: String.t()

Hosts listen here to change or refuse a checkout before the provider sees it. A plugin gets %{checkout: %MishkaPay.Checkout{}, refused: nil} and answers it with a changed :checkout, or with :refused set to a reason. See MishkaPay.checkout/1.

credentials()

@spec credentials() :: String.t()

The host listens here and answers a provider's keys for one site.

customer_changed()

@spec customer_changed() :: String.t()

Fired after a customer resource (the :customer kind of MishkaPay.Ash.Resource) registered, synced or edited a customer, with %{customer: %MishkaPay.Customer{}, record: record}. A host listens here to link the customer to its user, or to push the change to the screens that show it.

dispute_changed()

@spec dispute_changed() :: String.t()

Fired after a dispute resource (the :dispute kind of MishkaPay.Ash.Resource) synced, answered or accepted a dispute, with %{dispute: %MishkaPay.Dispute{}, record: record}. A host listens here to take back what the payment gave while it is open, and give it again when it is won.

event_process()

@spec event_process() :: String.t()

The inbox (the :inbox kind of MishkaPay.Ash.Resource) fires this to work one stored event, once per try. Listeners get %{event: %MishkaPay.Event{}, failed: nil} and answer it with :failed set to a reason when the work did not finish, so the inbox tries again later.

payment_changed()

@spec payment_changed() :: String.t()

Fired after a payment resource (the :payment kind of MishkaPay.Ash.Resource) synced a payment from its provider, with %{payment: %MishkaPay.Payment{}, record: record}. A host listens here to act on a paid or refunded payment, or to push the change to the screens that show it.

providers()

@spec providers() :: String.t()

Every provider listens here and adds itself to the providers list the event carries.

subscription_changed()

@spec subscription_changed() :: String.t()

Fired after a subscription resource (the :subscription kind of MishkaPay.Ash.Resource) synced, cancelled or resumed a subscription, with %{subscription: %MishkaPay.Subscription{}, record: record}. A host listens here to give or take access, or to push the change to the screens that show it.

webhook_received()

@spec webhook_received() :: String.t()

Listeners get every provider event whose signature was checked, as %{event: %MishkaPay.Event{}, failed: nil}, and answer it with :failed set to a reason when they could not take it, so the provider sends it again. See MishkaPay.Webhook.