Skip to content

chore: add credits api extensions#4311

Merged
turip merged 1 commit into
mainfrom
chore/credits-api
May 7, 2026
Merged

chore: add credits api extensions#4311
turip merged 1 commit into
mainfrom
chore/credits-api

Conversation

@turip
Copy link
Copy Markdown
Member

@turip turip commented May 7, 2026

Overview

Add credits related api data.

Notes for reviewer

Summary by CodeRabbit

Release Notes

  • New Features
    • Invoices now display credit allocations, showing which credits were applied to individual line items with their amounts and descriptions.
    • Invoice totals now include a dedicated credits total amount alongside existing discount and charge totals.

@turip turip requested a review from a team as a code owner May 7, 2026 09:37
@turip turip added area/api release-note/feature Release note: Exciting New Features labels May 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4f019292-0e2a-45ae-98a6-948ec983219a

📥 Commits

Reviewing files that changed from the base of the PR and between 77577d3 and bf337e4.

⛔ Files ignored due to path filters (6)
  • api/client/go/client.gen.go is excluded by !api/client/**
  • api/client/javascript/src/client/schemas.ts is excluded by !api/client/**
  • api/client/python/openmeter/_generated/models/__init__.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_generated/models/_models.py is excluded by !**/_generated/**, !api/client/**
  • api/openapi.cloud.yaml is excluded by !**/openapi.cloud.yaml
  • api/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (7)
  • api/api.gen.go
  • api/spec/packages/legacy/src/billing/invoices/credits.tsp
  • api/spec/packages/legacy/src/billing/invoices/invoice.tsp
  • api/spec/packages/legacy/src/billing/invoices/main.tsp
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/httpdriver/invoice_test.go
  • openmeter/billing/httpdriver/invoiceline.go

📝 Walkthrough

Walkthrough

This PR adds end-to-end support for tracking credit allocations on invoices. It introduces a new InvoiceLineCreditAllocation TypeSpec model, extends invoice line and totals schemas with credit fields, implements backend mapping logic to convert internal credit data to API responses, and includes unit tests validating the credit serialization behavior.

Changes

Invoice Credit Allocations

Layer / File(s) Summary
TypeSpec Credit Model
api/spec/packages/legacy/src/billing/invoices/credits.tsp, api/spec/packages/legacy/src/billing/invoices/main.tsp
New InvoiceLineCreditAllocation model with read-only amount: Money and optional description fields; imported into invoice package.
TypeSpec Schema Extensions
api/spec/packages/legacy/src/billing/invoices/invoice.tsp
InvoiceLineBase gains optional creditAllocations array; InvoiceTotals gains creditsTotal numeric field, both read-only.
Backend Credit Mapping
openmeter/billing/httpdriver/invoiceline.go, openmeter/billing/httpdriver/invoice.go
New mapInvoiceLineCreditsToAPI helper converts internal billing.CreditsApplied to API CreditAllocations; integrated into detailed and usage-based line mappers; totals mapper includes CreditsTotal.
Unit Tests
openmeter/billing/httpdriver/invoice_test.go
Three new tests verify mapTotalsToAPI includes credits total, mapInvoiceLineCreditsToAPI correctly maps credits with amount/description, and empty credits are omitted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

area/api, area/billing, release-note/misc

Suggested reviewers

  • tothandras
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding credit-related API extensions across TypeSpec models and Go HTTP driver mapping logic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/credits-api

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@turip turip merged commit 8d3a5a0 into main May 7, 2026
33 of 35 checks passed
@turip turip deleted the chore/credits-api branch May 7, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants