Skip to content

fix(revenue): attribute unsettled revenue to API owners and paginate settlements (#1232) - #1470

Open
lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:fix/1232-attribute-developer-revenue-to-api-owners
Open

lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:fix/1232-attribute-developer-revenue-to-api-owners

Conversation

@lienhoatienphung-svg

Copy link
Copy Markdown

Closes #1232

Summary

Fixes GET /api/developers/revenue so unsettled usage revenue is attributed to the API owner rather than the API caller (keyRecord.userId), computes revenue sums using exact decimal strings / SQL numeric aggregates, and paginates developer settlements with LIMIT / OFFSET in settlementStore so only a single page of settlements is loaded per request.

Acceptance Criteria Mapping

  • Revenue for developer D includes calls to D's APIs made by other users: PostgresUsageStore joins usage_events to apis on a.id = ue.api_id and filters by a.developer_id = $1; InMemoryUsageStore and developerRoutes resolve apiId ownership via ApiRegistry.
  • Calls D makes to other developers' APIs are excluded: Filtered out because a.developer_id / apiRegistry.resolve(e.apiId).developerId belongs to the other developer, not D.
  • Only one page of settlements is loaded per request: settlementStore.getDeveloperSettlementsPage(developerId, { limit, offset }) uses LIMIT $2 OFFSET $3 in SQL and slices only the requested page.
  • Totals match a fixture computed independently in src/__tests__/developerRevenue.test.ts: Verified in src/__tests__/developerRevenue.test.ts and src/routes/developerRoutes.test.ts.

Validation

  • npx jest src/__tests__/developerRevenue.test.ts src/routes/developerRoutes.test.ts src/services/settlementStore.test.ts --no-cache (67 passed, 0 failed).

Payout Wallet (Base Mainnet USDC / EVM): 0x3806cd592a508d1992Ed007C2F53de251C2E7452

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.

Attribute developer revenue to API owners, not callers

1 participant