PhoenixKitBilling.Events (PhoenixKitBilling v0.13.0)

Copy Markdown View Source

PubSub events for PhoenixKit Billing system.

Broadcasts billing-related events for real-time updates in LiveViews. Uses PhoenixKit.PubSub.Manager for self-contained PubSub operations.

Topics

  • phoenix_kit:billing:orders - Order events (created, updated, confirmed, paid, cancelled)
  • phoenix_kit:billing:invoices - Invoice events (created, sent, paid, voided)
  • phoenix_kit:billing:profiles - Billing profile events (created, updated, deleted)
  • phoenix_kit:billing:transactions - Transaction events (created, refunded)
  • phoenix_kit:billing:credit_notes - Credit note events (sent, applied)
  • phoenix_kit:billing:currencies - Currency table events (rate, enabled, rounding rule, base changed)

Usage Examples

# Subscribe to order events
PhoenixKitBilling.Events.subscribe_orders()

# Handle in LiveView
def handle_info({:order_created, order}, socket) do
  # Update UI
  {:noreply, socket}
end

# Broadcast order created
PhoenixKitBilling.Events.broadcast_order_created(order)

Summary

Functions

Broadcasts credit note applied event.

Broadcasts credit note sent event.

Broadcasts {:currencies_changed, code} — sent by the context AFTER its currency cache is cleared, so a subscriber that re-reads on receipt sees the new table. code is the currency that was written (for set_default_currency/1, the new base — every rate was renormalized).

Broadcasts invoice created event.

Broadcasts invoice paid event.

Broadcasts invoice sent event.

Broadcasts invoice voided event.

Broadcasts order cancelled event.

Broadcasts order confirmed event.

Broadcasts order created event.

Broadcasts order paid event.

Broadcasts order updated event.

Broadcasts billing profile created event.

Broadcasts billing profile deleted event.

Broadcasts billing profile updated event.

Broadcasts subscription cancelled event.

Broadcasts subscription created event.

Broadcasts subscription renewed event.

Broadcasts transaction created event.

Broadcasts transaction refunded event.

Topic for currency-table changes.

Subscribes to credit note events.

Subscribes to currency-table changes. Storefront LiveViews use this to re-render converted prices the moment a rate, a rounding rule, an enabled flag or the base changes (per-domain-currency spec §4.2.1 п.5).

Subscribes to invoice events.

Subscribes to order events.

Subscribes to billing profile events.

Subscribes to subscription events.

Subscribes to transaction events.

Subscribes to invoice events for a specific user.

Subscribes to order events for a specific user.

Subscribes to subscription events for a specific user.

Subscribes to transaction events for a specific user.

Functions

broadcast_credit_note_applied(invoice, transaction, amount)

Broadcasts credit note applied event.

broadcast_credit_note_sent(invoice, transaction)

Broadcasts credit note sent event.

broadcast_currencies_changed(currency)

Broadcasts {:currencies_changed, code} — sent by the context AFTER its currency cache is cleared, so a subscriber that re-reads on receipt sees the new table. code is the currency that was written (for set_default_currency/1, the new base — every rate was renormalized).

The clear itself is a GenServer.cast (fire-and-forget), so the context follows it with a same-process GenServer.call to the cache (a barrier — Erlang orders messages from one sender to one receiver, so the call cannot return until the cast has been applied) before ever reaching this function. That is what makes the "sees the new table" promise above true, not just usual.

broadcast_invoice_created(invoice)

Broadcasts invoice created event.

broadcast_invoice_paid(invoice)

Broadcasts invoice paid event.

broadcast_invoice_sent(invoice)

Broadcasts invoice sent event.

broadcast_invoice_voided(invoice)

Broadcasts invoice voided event.

broadcast_order_cancelled(order)

Broadcasts order cancelled event.

broadcast_order_confirmed(order)

Broadcasts order confirmed event.

broadcast_order_created(order)

Broadcasts order created event.

broadcast_order_paid(order)

Broadcasts order paid event.

broadcast_order_updated(order)

Broadcasts order updated event.

broadcast_profile_created(profile)

Broadcasts billing profile created event.

broadcast_profile_deleted(profile)

Broadcasts billing profile deleted event.

broadcast_profile_updated(profile)

Broadcasts billing profile updated event.

broadcast_subscription_cancelled(subscription)

Broadcasts subscription cancelled event.

broadcast_subscription_created(subscription)

Broadcasts subscription created event.

broadcast_subscription_renewed(subscription)

Broadcasts subscription renewed event.

broadcast_subscription_status_changed(subscription, old_status, new_status)

Broadcasts subscription status changed event.

broadcast_subscription_type_changed(subscription, old_type_uuid, new_type_uuid)

Broadcasts subscription type changed event.

broadcast_transaction_created(transaction)

Broadcasts transaction created event.

broadcast_transaction_refunded(transaction)

Broadcasts transaction refunded event.

currencies_topic()

Topic for currency-table changes.

subscribe_credit_notes()

Subscribes to credit note events.

subscribe_currencies()

Subscribes to currency-table changes. Storefront LiveViews use this to re-render converted prices the moment a rate, a rounding rule, an enabled flag or the base changes (per-domain-currency spec §4.2.1 п.5).

subscribe_invoices()

Subscribes to invoice events.

subscribe_orders()

Subscribes to order events.

subscribe_profiles()

Subscribes to billing profile events.

subscribe_subscriptions()

Subscribes to subscription events.

subscribe_transactions()

Subscribes to transaction events.

subscribe_user_invoices(user_uuid)

Subscribes to invoice events for a specific user.

subscribe_user_orders(user_uuid)

Subscribes to order events for a specific user.

subscribe_user_subscriptions(user_uuid)

Subscribes to subscription events for a specific user.

subscribe_user_transactions(user_uuid)

Subscribes to transaction events for a specific user.