Allow apps to extend the default transaction categories with custom ones
via `config.additional_categories`. This enables using the gem for
marketplace wallets, seller payouts, and other money-handling systems
beyond traditional API credits.
Changes:
- Add `additional_categories` config option (array of strings)
- Add `Transaction.categories` class method combining defaults + custom
- Update validation to use dynamic category lookup
- Add comprehensive tests for the new functionality
- Document "Beyond credits" use cases in README with marketplace example
Backwards compatible: CATEGORIES constant still works, defaults unchanged.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Why this matters
While building a marketplace app, I realized
usage_creditshas all the infrastructure needed for a proper wallet system — double-entry ledger, row-level locking, FIFO allocation, audit trails — but the hardcoded transaction categories (signup_bonus,operation_charge, etc.) are specific to the "API credits" use case.Many apps need the same ledger infrastructure but for different domains:
Rather than building a separate wallet system from scratch, it makes sense to extend this gem to support these use cases.
What this PR does
Adds
config.additional_categoriesto let apps define their own transaction categories:These work exactly like built-in categories — validated, tracked in history, available for filtering.
Changes
additional_categoriesoption (defaults to empty array)Transaction.categoriesclass method that combinesDEFAULT_CATEGORIES+ custom onesBackwards compatible
CATEGORIESconstant still exists (points toDEFAULT_CATEGORIES)Example use case (from README)
Test plan
additional_categoriespass (5 tests, 17 assertions)Transaction.categoriesincludes both default + customCATEGORIESconstant unchanged🤖 Generated with Claude Code