Skip to content

Conversation

@whoAbhishekSah
Copy link
Member

Summary

Simplify transaction and invoice RPCs by always inferring billing_id from org_id. Since each organization can have only one active billing account, passing billing_id separately
is redundant.

Changes

RPCs Updated

This PR updates 4 billing-related RPCs:

  • ListBillingTransactions
  • TotalDebitedTransactions
  • ListInvoices
  • GetUpcomingInvoice

Implementation Details

Proto Changes (raystack/proton#437)

  • Deprecated billing_id parameter in all 4 request messages
  • Made billing_id optional with ignore_empty: true validation (was required in TotalDebitedTransactions)
  • Updated PROTON_COMMIT in Makefile
  • ✅ Fully backwards compatible - old clients continue to work

Handler Changes

  • Handlers now always call customerService.GetByOrgID() to fetch billing account ID
  • The deprecated billing_id parameter is ignored if provided
  • Graceful error handling:
    • Returns empty list/response when billing account doesn't exist (ErrNotFound)
    • Returns bad request for invalid org_id (ErrInvalidUUID, ErrInvalidID)
  • Added org_id to error log lines for better debugging

Authorization Changes

  • Removed redundant ensureBillingAccountBelongToOrg checks from Connect authorization interceptors
  • Since billing_id is always inferred from org_id, separate validation is no longer needed

Migration Guide

For API Clients

  • You can now omit the billing_id parameter when calling these RPCs
  • If you still pass billing_id, it will be ignored and inferred from org_id instead
  • Ensure org_id is always provided

Testing

  • ✅ Build passes
  • ✅ All 4 RPCs tested with valid org_id
  • ✅ Tested empty responses when billing account doesn't exist
  • ✅ Tested error handling for invalid org_id

Related

@vercel
Copy link

vercel bot commented Nov 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
frontier Ready Ready Preview Comment Nov 28, 2025 9:11am

@whoAbhishekSah whoAbhishekSah requested a review from rsbh November 27, 2025 10:16
@whoAbhishekSah whoAbhishekSah changed the title Billing simplification transactions refactor(billing): always infer billing_id from org_id in transaction and invoice RPCs Nov 27, 2025
@coveralls
Copy link

coveralls commented Nov 28, 2025

Pull Request Test Coverage Report for Build 19759183894

Details

  • 58 of 82 (70.73%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 37.667%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/v1beta1connect/billing_invoice.go 28 40 70.0%
internal/api/v1beta1connect/billing_usage.go 30 42 71.43%
Totals Coverage Status
Change from base Build 19758818297: 0.05%
Covered Lines: 15691
Relevant Lines: 41657

💛 - Coveralls

whoAbhishekSah and others added 5 commits November 28, 2025 14:33
Deprecate billing_id parameter in 4 RPCs:
- ListBillingTransactionsRequest
- TotalDebitedTransactionsRequest (BREAKING: changed from required to optional)
- ListInvoicesRequest
- GetUpcomingInvoiceRequest

Backend will infer billing_id from org_id since each organization has only
one active billing account.

Updated PROTON_COMMIT to d40c501dac9958d86c945b02f0288fcaf6d6a4e3.
…nvoice RPCs

Update handlers for 4 RPCs to always infer billing_id from org_id:
- ListBillingTransactions
- TotalDebitedTransactions
- ListInvoices
- GetUpcomingInvoice

Changes:
- Use customerService.GetByOrgID() to fetch billing account ID
- Return empty list/response when billing account doesn't exist (ErrNotFound)
- Return bad request for invalid org_id (ErrInvalidUUID, ErrInvalidID)
- Deprecated billing_id parameter is ignored
- Add org_id to error log lines for better debugging
…oice RPCs

Remove ensureBillingAccountBelongToOrg checks from authorization interceptors
for 4 RPCs:
- ListBillingTransactions
- TotalDebitedTransactions
- ListInvoices
- GetUpcomingInvoice

Since billing_id is now always inferred from org_id by handlers, the separate
validation that billing_id belongs to org_id is redundant.
Update test cases for ListBillingTransactions, TotalDebitedTransactions,
ListInvoices, and GetUpcomingInvoice to mock customerService and test the
new behavior where billing_id is inferred from org_id.

Changes:
- Add customerService mock to all test cases
- Update test requests to use org_id instead of billing_id
- Add test cases for when billing account is not found
- Update test struct definitions to include customerSetup function
- Update test runners to initialize customerService mock

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@whoAbhishekSah whoAbhishekSah merged commit c3ded99 into main Nov 28, 2025
7 checks passed
@whoAbhishekSah whoAbhishekSah deleted the billing_simplification_transactions branch November 28, 2025 09:15
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.

4 participants