Skip to content

0.30.0 - 2026-11-29

Latest

Choose a tag to compare

@ddon ddon released this 29 Nov 09:23
· 7 commits to main since this release

Refunds now move money at the payment provider, a refund the provider fails later is put back,
voiding an invoice closes its open checkout first, and an invoice can be sent to a payer without
an account, who pays it through a signed link (PR #76). The module works under a nonce-based
Content-Security-Policy (issue #75). The status badges are translated (PR #74). The core
requirement is unchanged (>= 3.5.0 and < 4.0.0).

Upgrading.

  • The module now ships JavaScript. The Print button of the printable documents and the Copy
    buttons of the webhook URLs work only when the host loads phoenix_kit_modules.js, which
    PhoenixKit's :phoenix_kit_js_sources compiler builds and the installer adds to the root
    layout. A host that never set that up has to (mix phoenix_kit.update).
  • The renewal cron is declared by billing (oban_crons/0), and mix phoenix_kit.update
    writes it into the host's crontab. A host that copied the entry into its Oban config by hand
    should remove its copy: two entries run the batch twice (harmless, but pointless).
  • void_invoice/3 can now be refused while the invoice has an open checkout session:
    {:error, :checkout_completed} when the customer paid through it,
    {:error, {:checkout_not_closed, reason}} when the provider cannot be reached, and
    {:error, :checkout_reopened} after three rounds of new sessions. Pass
    close_checkout: false for the old behaviour.
  • A currency with more than two decimal places (BHD, KWD, ...) is refused for new invoices,
    for a draft moved to it and for provider refunds (:currency_too_precise): the ledger's
    amounts are numeric(15,2).
  • Invoice event handlers need a catch-all clause. Events are added over time, and one with
    no clause fails its job.
  • The payment link's token is in its URL. Add "token" to the host's
    :filter_parameters to keep it out of the request log (README, "Guest invoices").

Added

  • Refunds at the provider. refund_at_provider/3 refunds the invoice's provider payments
    (newest first) through Providers.create_refund/4 with an idempotency key, then books each
    refund under its own id. The webhook's running total and this path never book the same money
    twice. The admin refund dialog uses it for a provider payment, with one idempotency key per
    opening and amount, and "Already refunded at the provider - only record it" (with an optional
    provider refund id) to book a refund made elsewhere.
  • Failed refunds are put back. A refund the provider reports as failed later is reversed by
    reverse_failed_refund/2: a reversal row, the refund row marked, a void it caused undone,
    and the failure listed on the admin invoice page. On Stripe the ledger is then booked to the
    charge's refunded total, read back through the new optional provider callback
    refunded_total/1.
  • Guest invoices and payment links. create_guest_invoice/2 makes an invoice with no user
    (details in billing_details). invoice_pay_url/1 signs a link to the public payment page
    /billing/pay/:token, which shows the invoice, opens the provider's hosted checkout and
    follows the payment live. revoke_invoice_pay_links/1 (the admin page's New link) stops
    one invoice's links. A guest's invoice email links to the page.
  • Closing checkout sessions. A void closes the invoice's open checkout session first
    (optional provider callback expire_checkout_session/1), and "Void anyway" on the admin page
    voids when the provider cannot be reached. A new session closes the one it replaces, and a
    refund that voids a part-paid invoice closes its session.
  • A per-invoice PubSub topic (Events.subscribe_invoice/1,
    phoenix_kit:billing:invoices:invoice:<uuid>) and the optional InvoiceEventHandler
    behaviour for durable invoice-event handlers.
  • oban_crons/0 declares the daily subscription renewal run.
  • test/phoenix_kit_billing/web/csp_inline_tags_test.exs fails on an inline <script>/<style>
    without the nonce and on an inline event handler in lib/ or the JS file. The JS file's own
    tests (test/js/) run under mix test.

Changed

  • No inline event handlers. The Print button (onclick="window.print()") and the four
    webhook-URL copy buttons of Settings → Billing → Providers now carry data-pkb-print and
    data-pkb-copy, handled by one delegated click listener in the new
    priv/static/assets/phoenix_kit_billing.js (js_sources/0, global PhoenixKitBillingHooks,
    no hooks). The copy button no longer builds JavaScript from the URL.
  • The five inline <style> tags of the printable documents carry the host's nonce
    (PhoenixKitBilling.Web.CSP.nonce/1, which reads core's PhoenixKitWeb.CSP when the installed
    core has it and renders no attribute otherwise).
  • A refund recorded by hand counts once, through paid_amount, not against every provider
    payment of its method, so an invoice paid in two Stripe payments can be refunded in full at
    the provider.
  • A refund amount finer than the invoice's currency (5.005 EUR) is refused.
  • The order and invoice status badges and the billing profile type are translated on the
    customer and admin pages, the order badge has its own msgid context, and the badges tolerate
    atoms, booleans and nil (PR #74).

Fixed

  • A Stripe refund retried after a lost answer, with the refund webhook booked between the
    attempts, was booked twice. A refund Stripe answers with Idempotent-Replayed is now booked
    up to the charge's running total.
  • PayPal refunds sent a new random PayPal-Request-Id on every request, so a retry after a lost
    answer refunded the payer twice. The idempotency key is now sent as the request id.
  • The public payment page showed what a provider answered when a checkout could not be started
    (API error messages, request log URLs) to anyone holding the link. It now shows a generic
    message and logs the reason. A link revoked or expired while the page is open now shows as
    invalid instead of keeping the invoice on screen.
  • The legacy PhoenixKit.Modules.Billing namespace did not delegate js_sources/0, so a host
    registered under it got no billing JavaScript.
  • Billing's own invoice metadata keys given as atoms (%{voided_by_refund: ...}) were kept on
    an edit, which could forge the refund-void trail on a new invoice.
  • Errors.message/1 has a message for :already_recorded, and a full refund with nothing left
    paid is refused (:already_refunded) instead of reporting success with no refund.
  • A refund already in the ledger is no longer logged a second time in the activity log.
  • An :invoice_link_secret shorter than 32 bytes was ignored without a word; a warning is now
    logged.