All problems

Tenant Invoice Summary Mixes Payments From Another Organization

Level 2 · node · Data · Multi-tenant aggregation scope error

Scenario

A B2B billing service calculates payment totals for each organization invoice and displays them on a dashboard. When different organizations happen to use the same invoice identifier, payments from one organization are added to another organization’s summary. The summary service passes tenantId and invoiceId to the repository, but the repository aggregate selects rows using invoiceId alone.

Requirements

- Include only rows matching both the requested tenantId and invoiceId in the payment total - Exclude payments for the same invoiceId that belong to another tenant - Exclude payments for another invoiceId in the same tenant - Return a total of 0 when no matching payments exist - Include only rows whose payment status is paid

Acceptance criteria

  • Sum paid payment amounts for the requested tenant and invoice
  • Do not include the same invoice identifier from another tenant
  • Do not include another invoice from the same tenant
  • Exclude payments whose status is not paid
  • Return 0 when there are no matching payments