Skip to content

[ING-48] feat(wallets): filter by billing entity#5559

Open
mariohd wants to merge 1 commit into
mainfrom
ING-48-wallets-by-be
Open

[ING-48] feat(wallets): filter by billing entity#5559
mariohd wants to merge 1 commit into
mainfrom
ING-48-wallets-by-be

Conversation

@mariohd
Copy link
Copy Markdown
Contributor

@mariohd mariohd commented May 21, 2026

Context

Multi-entity customers need to scope the wallets list to a specific
billing entity. The /customers and /invoices list endpoints already
support a billing_entity_codes filter; this brings /wallets in line.

Description

Adds an optional billing_entity_codes array filter to:

  • GET /api/v1/wallets
  • GET /api/v1/customers/:external_id/wallets

Behavior:

  • Codes are resolved to IDs against current_organization.all_billing_entities. Unknown codes return 404 billing_entity_not_found — matching the pattern used by /customers and /invoices.
  • The query matches wallets directly stamped with a billing_entity_id and wallets that inherit it from their customer, preserving Wallet#billing_entity's fallback semantics.
  • Backwards compatible: the filter is optional and existing callers see no change.
  • Side effect: wallet filters are now compacted before being passed to WalletsQuery, so calling /api/v1/wallets without external_customer_id no longer trips the customer_not_found validation.

How to test

GET /api/v1/wallets?billing_entity_codes[]=EU
GET /api/v1/wallets?billing_entity_codes[]=EU&billing_entity_codes[]=US
GET /api/v1/wallets?billing_entity_codes[]=BOGUS   # → 404 billing_entity_not_found

Automated:

lago exec api bundle exec rspec \
  spec/queries/wallets_query_spec.rb \
  spec/requests/api/v1/wallets_controller_spec.rb \
  spec/requests/api/v1/customers/wallets_controller_spec.rb

## Context

Multi-entity customers need to scope the wallets list to a specific
billing entity. The /customers and /invoices list endpoints already
support a `billing_entity_codes` filter; this brings /wallets in line.

## Description

Adds an optional `billing_entity_codes` array filter to
GET /api/v1/wallets and its customer-scoped variant. Codes are
resolved to IDs against the current organization, and unknown codes
return a 404 (billing_entity_not_found). The query matches wallets
directly stamped with a billing_entity_id as well as wallets that
inherit it from their customer, preserving Wallet#billing_entity's
fallback semantics. Wallet filters are also compacted to skip the
customer_not_found check when no external_customer_id is provided.
@mariohd mariohd requested review from a team, rinasergeeva and vincent-pochet May 21, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant