Skip to content

Releases

v0.7.0

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 20 Nov 19:48
ed7179b

AshBilling v0.7.0

Highlights

  • Subscription Quantity & Item Synchronization: Added protected nullable quantity (:integer, min: 0) and provider_subscription_item_id (:string) attributes to AshBilling.Subscription. WebhookSync and AshBilling.reconcile_subscription/2 extract, persist, compare, and CAS-guard both attributes for single-item subscriptions with fail-closed validation (nil preserved when absent/null, 0 preserved as zero seats, negative/malformed values fail closed with {:error, :invalid_quantity}).
  • Diagnostics Engine & Doctor CLI (AshBilling.Diagnostics, mix ash_billing.doctor): Extended AshBilling.check_configuration/1 (backwards-compatible) with layered structural, read-only PostgreSQL schema/migration/index checks (0.6.0 & 0.7.0), WebhookEvent privacy verification, multitenancy/Repo checks, HTTP timeout guidance, optional read-only Stripe probes, and explicit configuration_valid vs production_ready reporting in text and --json.
  • Reconciliation CLI (AshBilling.Reconciler, mix ash_billing.reconcile): Read-only --dry-run default, mandatory --execute --confirm for writes, fail-closed selection filter validation, stable keyset streaming batch pagination, bounded concurrency, global cross-worker rate limiting, and strict Ash actor/policy, multitenant, and database-level Stripe Connect isolation.
  • Low-Cardinality Telemetry & Dashboard Guide: Instrumented [:ash_billing, :reconcile, ...], [:ash_billing, :reverify, ...], [:ash_billing, :deduplication, :acquire | :complete | :release], [:ash_billing, :postgres, :contention], and [:ash_billing, :reconciler, :batch] with low-cardinality metadata and drift detection, plus a Telemetry.Metrics dashboard guide.
  • Runnable SaaS Reference Application (examples/saas_example): Full runnable Phoenix + Ash + AshPostgres SaaS app with Docker Compose (PostgreSQL 16), migrations, guarded demo seeds, PBKDF2 auth + actor freshness, Stripe Checkout/Portal/plan swap/quantity update/cancel/resume/reconciliation, transactional FOR UPDATE seat enforcement, Subscribed & HasPrice policies, HMAC-verified webhooks with PostgreSQL deduplication, mix ash_billing.doctor / mix ash_billing.reconcile, and CI test coverage.

Upgrading from 0.6.0

Requires adding nullable quantity and provider_subscription_item_id columns to your subscription table. See Upgrading to 0.7 and Diagnostics, Recovery CLI & Observability.

v0.6.0

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 19 Nov 07:32
4df7792

Added & Changed

  • Durable Reconciliation Checkpoints (last_reconciled_at): Added nullable protected attribute last_reconciled_at (:utc_datetime_usec) to AshBilling.Subscription. See Upgrading to 0.6 for the required database migration.
  • PostgreSQL Shared-Clock Checkpointing: AshBilling.reconcile_subscription/2 queries PostgreSQL clock_timestamp() under canonical Customer -> Subscription FOR UPDATE locks, omits fabricated local timestamps ("created" => nil), and persists last_reconciled_at monotonically and atomically in the same transaction as reconciled state.
  • Post-Reconciliation Financial Verification: When last_reconciled_at is present, AshBilling.WebhookSync evaluates critical synchronized financial attributes (status, price_id, current_period_end, trial_ends_at, cancel_at_period_end, cancel_at) before applying non-terminal or delayed terminal webhooks. Safe fast paths (duplicates, event.created < last_event_created_at, or identical snapshots with no financial diff) skip provider calls, while any financial difference triggers live provider re-verification under FOR UPDATE regardless of event.created age, failing closed on provider or PostgreSQL errors with no ETS state.
  • 0.5.x Upgrade Cursor Healing & Operational Guidance: AshBilling.reconcile_subscription/2 now automatically clears ahead/future last_event_created_at values (> PostgreSQL clock_timestamp()) to nil atomically alongside persisting last_reconciled_at (and supports reset_event_cursor?: true for shared app+DB forward clock skew), preventing synthetic 0.5.x reconciliation timestamps from causing existing_event_newer?/2 to ignore legitimate Stripe webhooks. Documented explicit quantity persistence scope and HTTP timeout / FOR UPDATE lock hold / PostgreSQL pool sizing recommendations in Upgrading to 0.6.

v0.5.3

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 16 Nov 04:03
bc6a2ec

What's Changed

  • Reconciliation Concurrency & Lock Error Propagation: AshBilling.reconcile_subscription/2 enters the transaction lock boundary and acquires canonical Customer -> Subscription FOR UPDATE row locks before calling AshBilling.get_subscription/2, propagating lookup and lock-acquisition errors cleanly without invoking the provider while preserving v0.5.2 synthetic timestamp semantics and zero breaking API or schema changes.
  • Billing Invariants Documentation: Added Billing invariants section to documentation/topics/webhooks-and-resilience.md.
  • Canary CI: Added PostgreSQL 16 service and failure classification (INFRASTRUCTURE_FAILURE vs COMPATIBILITY_FAILURE) to .github/workflows/canary.yml.

Full Changelog: v0.5.2...v0.5.3

AshBilling 0.5.2

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 07 Nov 01:11
fed6821

Security & Reliability Hardening

  • Subscription Quantity Updates (AB-01, AB-02): Added optional update_quantity/3 callback to AshBilling.Provider behaviour and implemented it in AshBilling.Providers.Stripe. Quantity updates now POST only items[0][id] and items[0][quantity], omitting items[0][price]. This prevents unintended plan switches, avoids race conditions where a concurrent plan change would be clobbered by a quantity update, and avoids unnecessary GET requests when subscription_item_id is supplied without price_id. An optional :price_id can be passed as an optimistic assertion against the active plan, returning {:error, {:price_mismatch, actual}} if stale. Emits [:ash_billing, :update_quantity] telemetry span.
  • Subscription Reconciliation API (AB-09): Added AshBilling.reconcile_subscription/2 to safely fetch live provider state and synchronize updates directly into PostgreSQL inside advisory locks and transaction boundaries. Inactive and canceled subscriptions are updated to prevent stale entitlements when webhooks are lost.
  • URL Path Sanitization & Traversal Prevention (AB-03): Added percent-encoding via URI.encode(..., &URI.char_unreserved?/1) for all dynamic subscription_id path segments in AshBilling.Providers.Stripe (get_subscription, cancel_subscription, resume_subscription, swap_plan, update_quantity). Validates subscription IDs early and returns {:error, :invalid_subscription_id} on blank, whitespace-only, or non-binary input without making remote requests.
  • Webhook Error Normalization (AB-04): Normalized verification error handling in AshBilling.Plug. Signed non-JSON payloads now return a clean 400 response with {"error": "invalid_payload"} instead of raising Protocol.UndefinedError on Jason.DecodeError.
  • Pre-Authentication Information Disclosure Prevention (AB-05): Redacted internal repository module names from the 503 response body when the pre-authentication transaction boundary fails in AshBilling.Plug. Details are logged via Logger.error/1 while external callers receive a sanitized {"error": "transaction_boundary", "message": "Service temporarily unavailable"}.
  • Public API Contract Robustness (AB-06): Added fallback clause to AshBilling.create_customer/2 returning {:error, :invalid_customer} for non-map / non-struct inputs (nil, "", numbers, lists), replacing FunctionClauseError.
  • Documentation & Telemetry Consistency (AB-07): Documented [:ash_billing, :swap_plan] and [:ash_billing, :update_quantity] telemetry spans in README.md. Updated SECURITY.md supported versions to explicitly list 0.5.x.

AshBilling 0.5.1

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 07 Nov 01:11
f8137be

Security

  • Resolved Hex advisory on retired ash_sql 0.8.4 (Ecto query cache issue) by upgrading ash_sql to 0.8.7 (and nimble_options to 1.2.0). Verified with mix hex.audit (0 advisories).

Added

  • AshBilling.Checks.HasPrice: added support for specifying multiple allowed price IDs as a list (e.g. price: ["price_monthly", "price_annual"]). Authorizes when the active subscription's price_id matches any element in the list. Enforces fail-closed semantics on empty lists, blank strings, or invalid non-binary elements.

Fixed

  • Public error contracts in AshBilling:
    • AshBilling.create_portal_session/2: Returns {:error, :missing_return_url} when :return_url is missing, blank, or non-binary, avoiding KeyError.
    • AshBilling.get_subscription/2, cancel_subscription/2, resume_subscription/2: Return {:error, :invalid_subscription_id} when given nil, "", or unsupported structures, preventing FunctionClauseError and unneeded Stripe API requests.

AshBilling 0.5.0

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 03 Nov 06:46
002c786

AshBilling 0.5.0 hardens Stripe subscription mutations, Customer identity and PostgreSQL webhook consistency.

Changes

  • Preserve seat quantities when changing plans; reject ambiguous or incomplete item selection.
  • Require an established Customer before recurring Checkout and protect resource ownership references.
  • Validate required persistence and retain the remote Customer ID when a later local write fails.
  • Reject unsupported nonterminal multi-item subscriptions instead of storing a partial entitlement model.
  • Roll back supported shared-Repo PostgreSQL processing on sync/handler failures and keep leases retryable.

Upgrading

This release changes public contracts from 0.4.x. Recurring Checkout requires a Customer, handlers must return explicit success/error tuples, and raw lease errors propagate directly. No new schema migration is introduced.

Read the 0.5 upgrade guide. Unsupported snapshots retain the last supported entitlements pending application remediation. External effects still require consumer idempotency or an outbox.

{:ash_billing, "~> 0.5.0"}

Validation

389 library tests pass with 91.98% coverage, plus 13 offline convergence tests and seven launcher safety tests. The release tree passes the three supported CI combinations. Real Stripe Test Mode checks cover paid Checkout, quantity preservation, lifecycle operations and signed webhooks, including official HTTPS resends. Fault injection and arranged event reordering are separately classified local simulations.

Hex package · Documentation

v0.4.1

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 31 Oct 09:37

AshBilling v0.4.1

Fixed

  • AshBilling.Checks.HasPrice now fails closed when :price is missing, nil, empty, or whitespace-only.
  • Invalid or missing :price options are rejected at compile time during Ash policy definition via init/1 with a descriptive Spark.Error.DslError.
  • Added dynamic policy compilation regression tests and comprehensive authorization policy tests.

Documentation

  • Clarified that AshBilling.WebhookEvent is an internal deduplication resource and its actions must not be exposed to untrusted clients via public APIs (AshJsonApi, AshGraphql, etc.).
  • Documented explicit AshPostgres.DataLayer setup and shared Repo pool requirements for distributed webhook deduplication.
  • Clarified that distributed cross-node concurrency guarantees (pg_try_advisory_xact_lock and FOR UPDATE NOWAIT) apply to PostgreSQL. Non-Postgres data layers rely on local node locks.
  • Updated installation, upgrade, and security documentation for the published 0.4.x series.

Upgrade Notes

  • Applications using HasPrice without a valid :price must supply an explicit price or switch to AshBilling.Checks.Subscribed for general active subscription checks.
  • No database migrations are required when upgrading from v0.4.0.

v0.4.0 - Enterprise Security, Webhook Deduplication & Multi-Tenant Isolation

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 30 Oct 10:50

Highlights in v0.4.0 (2026-10-30)

Security & Hardening

  • Strict Attribute Protection: Explicit protection against mass assignment on billing attributes (stripe_customer_id, stripe_subscription_id, stripe_price_id, billing_deleted_at). Wildcard accepts like accept: :* no longer expose billing identifiers to untrusted callers.
  • Stripe Serialization (Ash.CiString): Fixed form parameter serializer to properly convert case-insensitive string values (Ash.CiString) to binary strings instead of failing or treating them as map structures.
  • Connect Scope & Account Validation: Enforces exact match of account ID and Stripe mode (live vs. test) across all provider operations.

Resilience & Concurrency

  • PostgreSQL Webhook Deduplication: Atomic lease acquisition with TTL and commit lifecycle. Concurrent duplicate deliveries safely converge: the winning process executes inside a shared transaction while parallel arrivals receive HTTP 503 for controlled Stripe retries.
  • Transaction Rollback Protection: Unpersisted or failed local database operations release webhook leases cleanly, preventing ghost subscriptions and ensuring Stripe delivers retries.
  • Out-of-Order Delivery Protection: Webhooks arriving out-of-order for terminated or transitioned subscriptions are safely ignored.

Developer Experience & Upgrading

  • Added comprehensive upgrade guide: documentation/topics/upgrading-to-0.4.md.
  • Updated DSL references and regenerated documentation.
  • CI pipeline enriched with dependency auditing, strict documentation checks (--warnings-as-errors), and packaging validation (mix hex.build).

Upgrade Guide: Please consult Upgrading to 0.4.0 for breaking changes and schema migrations.

v0.3.1 - Support Ash.CiString and Custom Structs in Stripe Payloads

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 28 Oct 17:25

Highlights in v0.3.1

Fixed

  • Support Ash.CiString and Custom Structs in Stripe Payloads:
    • Automatically coerces Ash.CiString values (commonly used by AshAuthentication for :email fields) to binary strings in AshBilling.Providers.Stripe.to_form_params/2.
    • Safely serializes structs implementing String.Chars or unwraps them to maps, preventing Protocol.UndefinedError when invoking AshBilling.create_customer/2 or AshBilling.create_checkout_session/2.

For full details, see CHANGELOG.md.

v0.3.0 - Tenant-Scoped Uniqueness, Atomic Terminal Guards, and Integrity Hardening

Choose a tag to compare

@sfelixalejandro sfelixalejandro released this 28 Oct 00:35

Highlights in v0.3.0

Database Uniqueness & Concurrency Protection

  • Tenant-Scoped Unique Index: Uniqueness constraint on provider_subscription_id scoped by resource and tenant (tenant_id), backed by a PostgreSQL unique index.
  • Atomic Terminal State Guards: Prevents obsolete webhook events from modifying or resurrecting terminal subscriptions (:canceled, :incomplete_expired).

Security & Developer Experience

  • Customer Identity Association: Enforced atomic customer identity checks. Contradictory customer mappings produce safe retryable errors.
  • Credential Redaction: Automatic redaction of API keys and webhook secrets from diagnostics and exceptions.
  • Igniter Installer Improvements: Automated domain/resource registration and endpoint raw-body preservation.
  • Plug Raw Body Preservation: AshBilling.Plug.read_body/2 captures raw webhook payload bytes for signature verification.

For full migration instructions and diagnostic SQL, refer to CHANGELOG.md.