Skip to content

feat(billing): add customer billing profile selection endpoint - #5357

Merged
turip merged 1 commit into
mainfrom
feat/customer-billing-profile-endpoint
Oct 26, 2026
Merged

turip merged 1 commit into
mainfrom
feat/customer-billing-profile-endpoint

Conversation

@turip

@turip turip commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Overview

Add PUT /openmeter/customers/{customerId}/billing/profile to replace a customer's billing profile selection independently of app data. Providing billing_profile.id sets a pin; omitting billing_profile or sending null clears it and resumes following the namespace default.

The response includes the optional explicit selection and required read-only effective_billing_profile, matching billing GET. Compose CustomerBillingData from the shared profile model and app data, and regenerate the API and clients.

Notes for reviewer

Uses the set/clear billing profile assignment services. The combined billing PUT continues preserving the pin when the profile is omitted or null.

Clearing is idempotent and runs with response resolution in the existing locked transaction, so a missing default rolls back the unpin. Tests cover explicit default pins, subsequent default changes, app-data preservation, invalid references, missing/deleted customers, repeated clearing, and rollback.

Validation: PostgreSQL-backed billing HTTP, assignment service, and default-profile-change tests; scoped fast Go lint and vet; Go SDK tests; TypeScript SDK typecheck and 552 tests; e2e compilation; API regeneration and TypeSpec formatting.

Summary by CodeRabbit

  • New Features
    • Added a dedicated customer billing profile update operation to explicitly select a profile or clear the selection to use the current namespace default.
    • Billing responses distinguish the selected profile from the effective profile in use.
  • Bug Fixes
    • General billing updates preserve the existing profile selection when billing_profile is omitted or null.
    • Clearing a profile selection preserves customer data and supports repeated requests.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Adds PUT /openmeter/customers/{customerId}/billing/profile to change a customer's profile selection without changing app data.

  • Customers can change their billing profile without changing app data.

No actionable issues were found. Tests were inspected but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[PUT billing/profile] --> B[Check request and customer]
  B --> C[Start locked transaction]
  C --> D{Profile ID supplied?}
  D -->|Yes| E[Set explicit selection]
  D -->|No| F[Clear explicit selection]
  F --> G[Look up current default]
  E --> H[Commit and return profile]
  G --> H
  G -->|Lookup fails| I[Roll back selection change]
Loading

Reviews (5) · Last reviewed commit: "feat(billing): add customer billing prof..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d542386 and 2184ec8.

Files ignored due to path filters: 1
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
Files selected for processing: 4
  • api/spec/packages/aip-client-javascript/src/index.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/v3/api.gen.go
  • api/v3/client/models_customers.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Walkthrough

The API adds a dedicated operation to set or clear a customer’s billing-profile selection. Billing updates preserve the existing selection when billing_profile is omitted or null. Responses distinguish the selected profile from the effective profile.

Changes: Customer billing profile selection

Layer / File(s) Summary
Define the billing-profile contract
api/spec/packages/aip/src/customers/*, api/spec/packages/aip-client-javascript/src/models/*, api/v3/api.gen.go, api/v3/client/models_customers.go
The API and client models represent the selected profile as optional and nullable, and the effective profile as a separate value. The generated API registers the profile-update route.
Implement the profile update endpoint
api/v3/handlers/customers/billing/*, api/v3/server/routes.go, api/v3/api.gen.go
The handler assigns or clears a customer profile override, resolves the resulting profile under a customer lock, and returns the selected and effective profiles.
Expose the operation in client libraries and documentation
api/spec/packages/aip-client-javascript/README.md, api/spec/packages/aip-client-javascript/src/funcs/customers.ts, api/spec/packages/aip-client-javascript/src/sdk/customers.ts, api/spec/packages/aip-client-javascript/src/index.ts, api/spec/packages/aip-client-javascript/src/models/operations/customers.ts, api/v3/client/customers_billing.go, api/v3/client/README.md, openmeter/billing/README.md
The JavaScript and Go clients add profile-update methods. Documentation distinguishes updates that preserve the selection from the dedicated operation that clears it when the field is omitted or null.
Validate profile selection behavior
test/app/stripe/customerbilling_profile_v3_test.go, test/app/stripe/customerbilling_v3_test.go, e2e/billinginvoice_override_test.go, e2e/billinginvoices_v3_test.go
Tests cover selection, clearing, default-profile changes, invalid references, and nullable profile values.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant UpdateCustomerBillingProfile
  participant BillingService
  Client->>UpdateCustomerBillingProfile: PUT profile selection
  UpdateCustomerBillingProfile->>BillingService: Assign or clear customer override
  BillingService-->>UpdateCustomerBillingProfile: Resolved customer billing profile
  UpdateCustomerBillingProfile-->>Client: CustomerProfile response
Loading

Possibly related PRs

Suggested reviewers: tothandras, galexihu, borosr

Merge Risk: Minimal · up to 2184e

The change adds an endpoint to set or clear a customer's billing profile selection, and the generated API and client types follow that contract. No concrete merge-blocking risk was identified from the supplied evidence.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding a customer billing profile selection endpoint.
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.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@turip
turip force-pushed the feat/customer-billing-profile-assignments branch from 021260b to 2538d10 Compare October 26, 2026 11:55
@turip
turip force-pushed the feat/customer-billing-profile-endpoint branch from ace4497 to 5cfb99d Compare October 26, 2026 12:03
Base automatically changed from feat/customer-billing-profile-assignments to main October 26, 2026 12:39
@turip
turip force-pushed the feat/customer-billing-profile-endpoint branch from 5cfb99d to c35eac4 Compare October 26, 2026 12:41
@turip turip added area/api release-note/feature Release note: Exciting New Features area/billing labels Oct 26, 2026
@turip
turip marked this pull request as ready for review October 26, 2026 12:47
@turip
turip requested a review from a team as a code owner October 26, 2026 12:47
@turip
turip force-pushed the feat/customer-billing-profile-endpoint branch from c35eac4 to d542386 Compare October 26, 2026 14:05
@turip
turip force-pushed the feat/customer-billing-profile-endpoint branch from d542386 to 2184ec8 Compare October 26, 2026 14:14
@turip
turip merged commit 813b0fa into main Oct 26, 2026
35 checks passed
@turip
turip deleted the feat/customer-billing-profile-endpoint branch October 26, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants