Skip to content

Billing 0.4.0: Webhooks and Stripe that work, readable errors and an activity log

Billing 0.4.0 makes payment webhooks and Stripe work at all: webhooks failed on every event, and Stripe could never be reached from the admin. Admin errors now read as sentences, and every admin change is written to the activity log.

Webhooks and Stripe

Every incoming provider webhook crashed before it was processed, so the endpoint answered 400 and no event was ever handled. Webhooks are now processed. An event that keeps failing is given up after five attempts and acknowledged, so the provider stops sending it. A repeated delivery is recognised as a duplicate instead of failing. Receipts are now sent after a webhook payment; before, the send always failed.

Stripe read its key from a different setting than the one the admin saved, so it always looked unavailable and checkout failed. It now reads the saved secret key, and still falls back to the old setting name.

Readable errors

Flash messages in the billing admin no longer show raw error codes such as :has_active_subscriptions. Each error has a translatable message, and form errors are shown in words.

Activity logging

Every admin change to orders, invoices, currencies, subscriptions, subscription types and billing profiles, and every payment, refund and send action, is written to PhoenixKit’s activity log. Only ids, statuses, amounts, currency codes and counts are recorded, no personal data, and a logging failure never breaks the action.

Subscriptions and forms

Extending a subscription now adds its own billing period instead of a fixed 30 days, and no longer crashes when the subscription has no period end. Status actions on a subscription update the page in place. The subscription type, billing profile and order forms show their errors inline while typing.

Upgrading

No migration and no configuration. Update the dependency. If your Stripe key only works today because it is saved as billing_stripe_api_key, it keeps working; a key saved from the admin now takes effect.

Full release notes: Billing 0.4.0

0.4.0 · 4 June 2026

Added

  • Activity logging (PhoenixKitBilling.Activity) — a guarded LiveView-layer wrapper around PhoenixKit.Activity.log/1, invoked on every admin mutation (orders, invoices, currencies, subscriptions, subscription types, billing profiles, and payment/refund/send actions). Logging failures never crash the caller, and only PII-safe metadata (uuids, status strings, amounts, currency codes, counts) is recorded.
  • Centralized error messages (PhoenixKitBilling.Errors) — maps the error atoms returned by contexts, providers, and webhook handlers to gettext-backed, extractable human-readable strings. All admin flash/error messages now route through Errors.message/1 instead of inspect/1, so users no longer see raw atoms like :has_active_subscriptions. Also formats %Ecto.Changeset{} reasons.
  • Webhook retry cap — WebhookProcessor now stops reprocessing an event once WebhookEvent.max_retries_exceeded?/1 is true (≥5 attempts) and the controller acknowledges it with HTTP 200 so providers stop redelivering an intentionally-abandoned event.
  • Full DB + LiveView test harness (DataCase/LiveCase, test endpoint/router/layouts) and ~230 new tests across schemas, contexts, regressions, activity logging, and LiveView smoke/validation.

Fixed

  • Webhook processing crashed on every event. upsert_webhook_event/1 used Access bracket syntax on a %Providers.Types.WebhookEventData{} struct (no Access), raising UndefinedFunctionError so the controller returned 400 and no event was ever processed. Now reads the field via Map.get/2.
  • Stripe was unreachable from the admin UI. The UI saves the secret to billing_stripe_secret_key but Stripe.get_config/0 read billing_stripe_api_key, so available?/0 was always false and checkout returned :provider_not_available. Now reads billing_stripe_secret_key with a fallback to the legacy key, and available?/0 always returns a boolean.
  • unique_constraint names didn’t match the DB indexes for webhook_events, currencies, subscription_types, and payment_methods, so duplicate inserts raised Ecto.ConstraintError instead of returning {:error, changeset}. For WebhookEvent this broke idempotency (a duplicate delivery surfaced as :processing_error instead of :duplicate_event). Names pinned to the actual indexes.
  • Receipts were never sent after a webhook payment. The webhook path called send_receipt/2 on an invoice without a receipt_number (the number is stamped only on the struct returned by generate_receipt/1), so it always returned {:error, :receipt_not_generated}. The processor now sends from the receipt-bearing struct.
  • extend_subscription crashed (FunctionClauseError) when current_period_end was nil; it now reports a friendly error instead.
  • extend_subscription now derives the extension from the subscription type’s billing period rather than a hardcoded 30 days; update_subscription/2 filters to a non-lifecycle field allowlist (status changes go through cancel/pause/resume); subscription status actions update in place instead of redirecting.

Changed

  • Subscription-type, billing-profile, and order forms migrated to core <.input>/<.select>/<.textarea> components with assign_form/2 so inline errors render on validate.
  • SubscriptionType.billing_period_days/1 and next_billing_date/2 gained catch-all clauses (fall back to a monthly cadence) instead of raising on an unexpected interval.
  • Stripe provider moduledoc corrected to document the real PhoenixKit.Settings-based configuration; the provider talks to the Stripe REST API over Req.
  • Upgraded locked dependencies; added a test-only lazy_html dependency for Phoenix.LiveViewTest.

Billing 0.4.0. Install or update: {:phoenix_kit_billing, "~> 0.4"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.