Skip to content

Billing 0.13.0: Price rounding per currency and out-of-date rate warnings

Billing 0.13.0 lets each currency round its converted prices, such as to X.99, warns on the Currencies page when an exchange rate has not been updated for a while, and adds a way to switch a shop’s base currency.

A rounding rule per currency

The currency form gets a Rounding rule with four choices: exact, with no rounding (the default); charm .99, which rounds down to X.99; charm .90, to the nearest X.90; and whole units, with no minor units. The rule is applied once to a price converted from the base currency, the same way for live prices and for prices frozen on a cart or order, and never to the base currency itself. The charm rules need a currency with exactly two decimal places; the form refuses any other combination. The Currencies list shows each currency’s rule in a Rounding column.

Exchange rates that age

Every change of a rate now records when it happened, shown in an Updated column. A rate older than the fx_rate_max_age_days setting (30 days by default) gets an out of date badge, and the page shows a Some exchange rates are out of date banner. An old rate still converts prices; it only warns.

Live prices and a new base currency

Every change to a currency is now announced, so a storefront page can show the new converted prices without a reload. Developers also get a function that switches the base currency: it recalculates every rate against the new base inside one transaction and lets the caller reprice the catalogue in the same step. It has no button in the admin.

The transactions table on the invoice page now uses the same table and row menu as the other billing lists.

Upgrading

No migration and no configuration. Update the dependency. All currencies start on the exact rule, so prices do not change until you pick another.

Full release notes: Billing 0.13.0

0.13.0 · 7 September 2026

Per-domain currency, stages E2 and E3 (PR #33, #34).

Added

  • rounding_rule is now applied by Currency.present/3. Four rules — "exact" (default), "charm_99" (round down to X.99), "charm_90" (nearest X.90), "integer" (whole units) — applied once to the raw converted amount, identically on the live and frozen (order/cart snapshot) paths, never to the base currency. A charm rule requires a currency with exactly two decimal places; the changeset now rejects the combination.
  • {:currencies_changed, code} PubSub event (Events.subscribe_currencies/0) — broadcast by every currency writer (create/update/set_default/delete/ change_base_currency) after its cache invalidation is guaranteed applied, so a storefront tab can re-render converted prices live instead of on reload.
  • PhoenixKitBilling.change_base_currency/2 — switches the shop’s base currency: renormalizes every rate against the new base and promotes it to 1.0, inside one transaction with a caller-supplied opts[:reprice] callback (for recomputing catalog/shipping prices, which this package does not own) run strictly between those two steps. Requires an explicit opts[:catalog_size] so a non-empty catalog can’t be silently re-priced by omission.
  • Exchange-rate age tracking. rate_updated_at is now stamped by every currency write that actually changes the rate. Currency.stale?/2 and PhoenixKitBilling.currencies_with_stale_rates/0 flag rates older than the fx_rate_max_age_days setting (default 30 days) — a stale rate still converts, it only surfaces a one-time-per-process log warning and an admin banner/badge on the Currencies page.

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