Make invoice payment activation idempotent and auditable #2

Closed
opened 2026-03-10 14:40:53 +03:00 by sirily · 0 comments
Owner

Problem
packages/db/src/billing-store.ts re-applies subscription activation every time markInvoicePaid is called, even when the invoice is already paid, and it does not write an admin audit-log entry.

Why this matters
Repeated admin calls can rewrite billing periods, create duplicate cycle_reset ledger rows, and leave no audit trail for a high-impact billing action.

Acceptance criteria

  • markInvoicePaid becomes idempotent for already-paid invoices.
  • Expired/canceled/invalid transitions are handled deliberately instead of silently mutating state.
  • Admin-triggered invoice activation writes an audit-log entry with actor metadata.
  • Add tests for replayed mark-paid calls.
Problem `packages/db/src/billing-store.ts` re-applies subscription activation every time `markInvoicePaid` is called, even when the invoice is already `paid`, and it does not write an admin audit-log entry. Why this matters Repeated admin calls can rewrite billing periods, create duplicate `cycle_reset` ledger rows, and leave no audit trail for a high-impact billing action. Acceptance criteria - `markInvoicePaid` becomes idempotent for already-paid invoices. - Expired/canceled/invalid transitions are handled deliberately instead of silently mutating state. - Admin-triggered invoice activation writes an audit-log entry with actor metadata. - Add tests for replayed `mark-paid` calls.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sirily/nroxy#2