Skip to content

Billing 0.23.0: Working payment confirmation links and safer order status changes

Billing 0.23.0 fixes the payment confirmation links on the invoice page and in the email, stops a payment and a cancellation from both succeeding on the same order, and gives other systems a way to track which orders they have synced.

Payment confirmation links

Print Payment Confirmation in a payment’s menu on the invoice page, and the “View payment confirmation online” link in the payment confirmation email, led to a page that does not exist. Both now open the payment confirmation. The payment confirmation and credit note print pages also refuse a transaction from another invoice, where they used to print one invoice’s customer next to another’s payment, and say Transaction is not a payment or Transaction is not a refund instead of claiming billing is disabled.

Order status changes that cannot race

Confirming, paying, refunding and cancelling an order now lock the order and check the change against its stored status, so a payment and a cancellation arriving together can no longer both succeed. A refund larger than what the invoice holds returns an error instead of crashing. A refund applied while another change was in flight no longer leaves the invoice’s paid amount out of step with its transactions.

The admin order list and order page now refresh when an order is refunded, including by a refund that empties its invoice. Order events from a payment or refund are announced only after the change is saved, so a payment that fails announces nothing.

Syncing orders to other systems

An order now carries a revision that grows when its status, amounts, number, buyer or key dates change. An outside system, such as accounting, can store a mark on the order saying which revision it synced, with its own id, number and status, and find the orders that changed since. This is for developers; nothing in the admin uses it yet.

Upgrading

No migration and no configuration. Update the dependency. Code that called the order status functions and expected them to raise on a refused change now gets an error value back.

Full release notes: Billing 0.23.0

0.23.0 · 24 October 2026

An order revision and sync mark for external systems (PR #54), locked order transitions and refund bounds (PR #56), an :order_refunded event (PR #57) and working payment confirmation links (PR #58).

Added

  • Order revision and external sync mark. PhoenixKitBilling.Order.revision/1 counts the changes an external system cares about (status, amounts, order number, buyer, the confirmation/payment/cancellation times), bumped under the order row lock. PhoenixKitBilling.put_order_sync/2 records an external system’s mark (state: "synced" | "failed", the revision it took, and optional external_id, external_number, external_status, error) in metadata["sync"] without touching the order or broadcasting; it returns {:error, :stale_revision} when the order changed since that revision, and refuses a mark with no revision. Order.sync/1 reports the mark, or "pending" once the order changes again, and Order.where_sync/2 narrows a query to :pending, :synced or :any orders. (PR #54)
  • :order_refunded event on phoenix_kit:billing:orders and the per-user orders topic (Events.broadcast_order_refunded/1), sent when an order is marked refunded, including by the refund that zeroes its invoice. The admin order list and detail pages refresh on it. (PR #57)

Changed

  • confirm_order/1, mark_order_paid/2, mark_order_refunded/1 and cancel_order/2 lock the order row and check the transition against the stored status, so a payment and a cancellation racing on the same order can no longer both succeed. Refusals are returned, not raised. The lock is FOR NO KEY UPDATE, so it does not block an invoice being created for the order. (PR #56)
  • A refund larger than the invoice’s locked paid_amount returns {:error, :exceeds_paid_amount} instead of raising Ecto.InvalidChangesetError. (PR #56)
  • Order events raised by a payment or refund (:order_confirmed, :order_paid, :order_refunded) are broadcast after the transaction commits, alongside the invoice and transaction events, so a listener that re-reads the order sees the new state and a rolled-back payment announces nothing. The standalone order functions still broadcast as before.
  • The Gettext backend compiles one module per locale and domain, so the catalogues compile in parallel instead of holding up dependent apps. Lookups are unchanged. (PR #53)
  • Dependencies refreshed to phoenix_kit 2.64.1. The phoenix_kit requirement is unchanged.

Fixed

  • “Print Payment Confirmation” on the invoice page and “View payment confirmation online” in the email led to a 404; both now link to the payment-confirmation route. (PR #58)
  • The payment confirmation and credit note print pages refuse a transaction that belongs to another invoice (it used to print one invoice’s customer next to another’s payment), report “Transaction is not a payment” / “is not a refund” instead of claiming billing is disabled, and re-validate when navigated to another invoice.
  • A refund applied to an invoice whose paid_amount the caller held stale could leave the column out of step with the ledger; it is now applied to the locked invoice.

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