Skip to content

[ING-49] feat(payment-requests): filter by entity#5562

Open
mariohd wants to merge 1 commit into
mainfrom
ING-49-payment-requests-by-be
Open

[ING-49] feat(payment-requests): filter by entity#5562
mariohd wants to merge 1 commit into
mainfrom
ING-49-payment-requests-by-be

Conversation

@mariohd
Copy link
Copy Markdown
Contributor

@mariohd mariohd commented May 21, 2026

Context

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

Description

Adds an optional billing_entity_codes array filter to:

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

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, /invoices, and /wallets.
  • The query filters through customers.billing_entity_id. PaymentRequest delegates billing_entity to its customer (delegate :billing_entity, to: :customer), so no direct column lookup is needed.
  • Backwards compatible: the filter is optional and existing callers see no change.

How to test

Manual:

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

Automated:

lago exec api bundle exec rspec \
  spec/queries/payment_requests_query_spec.rb \
  spec/requests/api/v1/payment_requests_controller_spec.rb \
  spec/requests/api/v1/customers/payment_requests_controller_spec.rb

## Context

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

## Description

Adds an optional `billing_entity_codes` array filter to
GET /api/v1/payment_requests 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 filters
through `customers.billing_entity_id` — PaymentRequest delegates
its billing_entity to its customer, so no direct column lookup is
needed. The filter is optional and existing callers see no change.
@mariohd mariohd requested review from a team, lovrocolic and murparreira May 21, 2026 20:03
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