Billing 0.5.2: Billing permissions, notifications and payment fixes
Billing 0.5.2 splits billing access into four permissions, adds billing notifications, and fixes provider payments, which could charge a subscriber up to three times.
Billing now has Manage orders, Manage invoices, Manage subscriptions and Manage billing settings under the base Billing permission. The base permission still opens the admin pages; each action checks its own permission. Admins and customers are notified when an invoice is issued, a payment arrives or a payment fails.
Fixed:
- A failed subscription renewal crashed after the card was charged, and each retry charged it again, up to three times.
- Every successful webhook payment ended in an error, so no receipt was made and the provider sent it again.
- A payment for a draft invoice passed the webhook check and was then dropped.
- A partial payment was announced as the invoice total.
- Back on the orders, invoices and transactions lists no longer steps back through the search a few letters at a time.
Upgrading
Only the Admin role gets the new permissions automatically. A custom role with Billing keeps read access but cannot change anything until you grant it the new permissions.
Full release notes: Billing 0.5.2
0.5.2 · 5 August 2026
Post-merge review of PR #15 (permissions, notifications, provider payments) and PR #16 (live subscriptions search). PR #15 fixed record_payment/3 so provider-driven payments finally insert — which meant both of its production callers executed their success paths for the first time, and neither survived it. Full findings in dev_docs/pull_requests/2026/15-permissions-notifications-payment-fixes/CLAUDE_REVIEW.md and .../16-subscriptions-live-search/CLAUDE_REVIEW.md.
Fixed
- Subscription renewals could charge a customer up to three times.
SubscriptionRenewalWorkerpasses the provider’s%ChargeResult{}struct asprovider_data, and Ecto lets a struct through bothcastanddumpon a:mapcolumn — the failure only surfaces in the JSON encoder, as a raise from inside the repo transaction, i.e. after the card has been charged. The exception escapedattempt_renewal/2‘swith(anelseclause does not match exceptions), so the Oban job crashed instead of moving the subscription topast_due, and each retry created another invoice and charged the card again.provider_datais now sanitized to a plain, JSON-safe map at the context boundary, where providers’ result structs arrive. - Every successful provider webhook payment raised
KeyError.WebhookProcessorread.statusoffrecord_payment/3‘s return value, which is a%Transaction{}— a schema with no:statusfield. The payment committed, the webhook then 500’d, no receipt was generated, and the provider retried a charge that had already been recorded. Unreachable until provider payments started inserting at all. - The webhook status gate and
Invoice.payable?/1disagreed.validate_invoice_status/1admitted"draft", whichrecord_payment/3now rejects as:not_payable, so a draft invoice passed the processor’s gate only to have its payment dropped downstream. It now delegates toInvoice.payable?/1so the two cannot drift. mark_invoice_paid/2could commit a paid status without its ledger row. A failed settlement insert was discarded with_ =rather than rolling the transaction back — the exact inconsistency that transaction exists to close. It now also takes the sameFOR UPDATErow lockrecord_payment/3relies on, without which a concurrent mark-paid and payment could together record more than the invoice bills.- Every customer notification linked to a route that does not exist.
/dashboard/invoices/<uuid>is registered nowhere;user_dashboard_tabs/0exposesordersandbilling-profiles. Customer invoice and payment notices now link viaPaths.user_orders/0. billing.payment_failedwas a registered notification nothing could emit. Notification sends stopped at the admin LiveView, so the provider paths recorded payments and failures silently.payment_received/2andpayment_failed/2are now emitted from the webhook processor and the renewal worker.- A partial payment was announced as the invoice total —
payment_receivedformattedinvoice.total, so 50-of-500 read as “Payment received — 500.00 EUR”. It now reports the amount actually recorded. - A decline reason could be truncated mid-codepoint.
binary_part/3cuts at a byte offset; a localized provider message split that way is invalid UTF-8 and is rejected by both Postgres and the JSON encoder, so the notification reporting a failed payment failed itself. - Back-button behaviour on the orders, invoices and transactions lists. All three have debounced live search but pushed a history entry per typing pause, so Back walked the query backwards a few characters at a time. They now use the
replace: truethat PR #16 applied to subscriptions.
Changed
Web.Authz’s moduledoc described the e-commerce module ("shop"key, “carts carry customer contact details”); it now describes billing.snapshot_refreshable?/1‘s doc claimed an in-place billing-profile edit refreshes a draft order’s snapshot. It does not — only a profile switch is reconsidered, at any status or policy. The doc now states the actual scope.mix.lockpruned of eight unused entries (igniter,sourceror,spitfireand friends) left behind by the dependency refresh in19525d0, which hadmix precommitfailing ondeps.unlock --check-unused.
Added
- Regression coverage for the two defects above that a DB-backed test could reach: a provider result struct recorded as
provider_data, and mark-paid keeping status and ledger row in one transaction. test/phoenix_kit_billing/notification_contracts_test.exs— DB-free contract tests: every registered notification action has a producer, every customer link resolves to a tabuser_dashboard_tabs/0registers, and decline reasons truncate on a character boundary.Paths.user_orders/0andPaths.user_billing_profiles/0for the customer-facing routes this module registers.
Billing 0.5.2. Install or update: {:phoenix_kit_billing, "~> 0.5"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.