Skip to content

Feat: Add Organization Subscription-Preview Endpoint - #8245

Open
sbrown-livefront wants to merge 24 commits into
mainfrom
billing/PM-39927/org-subscription-preview
Open

Feat: Add Organization Subscription-Preview Endpoint#8245
sbrown-livefront wants to merge 24 commits into
mainfrom
billing/PM-39927/org-subscription-preview

Conversation

@sbrown-livefront

@sbrown-livefront sbrown-livefront commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-39927

📔 Objective

First endpoint on the new Bit.Subscriptions.Organization feature library and first consumer of the shared, Stripe-invoice-preview–driven cart summary. Sources the organization's upcoming-renewal cart totals from an actual Stripe invoice preview instead of reconstructing them from local subscription state.

Adds:

  • GetSubscriptionPreviewQuery (Bit.Invoicing) — shared, ISubscriber-generic query ported from GetBitwardenSubscriptionQuery. Resolves tier/cadence (collapsing TeamsStarter → Teams), previews via create_preview(subscription=id), falls back to the subscription overload when there's no upcoming invoice, and maps subscription status → SubscriptionPreview envelope (suspension/grace-period/cancel). Registered in AddInvoicing(). The Organization path is fully wired here; the User/Premium path is stubbed for Task 8.
  • GET /organizations/{organizationId:guid}/billing/subscription/preview — new route on the org subscription group, gated behind PM36631_PreviewDrivenCart.
  • Authorization via AuthorizeAttribute<OrganizationBillingRequirement> using the IOrganizationRequirement framework (Owner or confirmed provider-user-for-org; excludes Admin/Custom). Lives entirely in the OrganizationAuthorization library — no dependency on the Api project.
  • Unit tests for the query, the requirement, and the endpoint handler + group wiring.

@sbrown-livefront sbrown-livefront changed the title [PM-39928] feat: add organization subscription-preview endpoint Feat: Add Organization Subscription-Preview Endpoint Aug 21, 2026
@sbrown-livefront sbrown-livefront self-assigned this Aug 21, 2026
@sbrown-livefront sbrown-livefront added the t:feature Change Type - Feature Development label Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.61905% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.66%. Comparing base (7640e4b) to head (b15d8d0).

Files with missing lines Patch % Lines
...icePreviews/Queries/GetSubscriptionPreviewQuery.cs 85.54% 9 Missing and 3 partials ⚠️
...ion/OrganizationSubscriptionEndpointsExtensions.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8245      +/-   ##
==========================================
+ Coverage   63.64%   63.66%   +0.02%     
==========================================
  Files        2430     2433       +3     
  Lines      104962   105067     +105     
  Branches     9506     9517      +11     
==========================================
+ Hits        66798    66896      +98     
- Misses      35868    35872       +4     
- Partials     2296     2299       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kdenney
kdenney force-pushed the billing/PM-39925/invoice-preview-projection branch 2 times, most recently from a72b6a3 to 72c51a8 Compare August 24, 2026 17:31
@sbrown-livefront
sbrown-livefront force-pushed the billing/PM-39927/org-subscription-preview branch from ad72c4f to 6f86df0 Compare August 24, 2026 18:03
@sbrown-livefront sbrown-livefront added the ai-review Request a Claude code review label Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the new GetSubscriptionPreviewQuery in Bit.Invoicing, the GET .../billing/subscription/preview endpoint and handler in Bit.Subscriptions.Organization, the OrganizationBillingRequirement authorization path, and the AuthorizeAttribute<T> namespace move into the OrganizationAuthorization library. Traced authorization end to end: the group requires Policies.Application plus OrganizationBillingRequirement, and OrganizationRequirementHandler resolves the org from the same {organizationId:guid} route segment the host mounts, so there is no cross-org exposure; the handler 404s on both a missing organization and a subscriber with no Stripe subscription. Checked exception mapping (ConflictException → 409, NotFoundException → 404 via WithBasicExceptionHandling), DI lifetimes and TryAdd* usage, the invoice_upcoming_none fallback to the subscription projection, and confirmed the AuthorizeAttribute<T> move leaves no unmigrated references (remaining [Authorize<T>] mentions elsewhere are XML-doc comments, and ControllerAuthorizationTestHelpers matches by base type, not namespace). All eight prior review threads are resolved, and the only commits since the last round are merges from main; lock file churn is limited to propagating the new OrganizationAuthorization project reference, with no new NuGet packages.

Code Review Details

No new findings.

Comment thread src/Api/Startup.cs Outdated
@sbrown-livefront
sbrown-livefront marked this pull request as ready for review August 24, 2026 20:25
@sbrown-livefront
sbrown-livefront requested review from a team as code owners August 24, 2026 20:25
@sbrown-livefront
sbrown-livefront requested review from BTreston and cyprain-okeke and removed request for a team August 24, 2026 20:25
@kdenney
kdenney force-pushed the billing/PM-39925/invoice-preview-projection branch from 72c51a8 to 2bcc3d0 Compare August 25, 2026 14:58
@kdenney
kdenney requested review from a team as code owners August 25, 2026 14:58
@kdenney
kdenney force-pushed the billing/PM-39925/invoice-preview-projection branch from 2bcc3d0 to 01a50dd Compare August 25, 2026 15:53
@sbrown-livefront
sbrown-livefront force-pushed the billing/PM-39927/org-subscription-preview branch from dd2eb84 to 400d063 Compare August 25, 2026 21:01
Comment thread src/Libraries/OrganizationAuthorization/AuthorizeAttribute.cs
BTreston
BTreston previously approved these changes Aug 26, 2026

@BTreston BTreston left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for AC changes

@kdenney
kdenney force-pushed the billing/PM-39925/invoice-preview-projection branch from 01a50dd to e58bcfd Compare August 26, 2026 19:23
Base automatically changed from billing/PM-39925/invoice-preview-projection to main August 26, 2026 20:00
@kdenney
kdenney dismissed BTreston’s stale review August 26, 2026 20:00

The base branch was changed.

@sbrown-livefront
sbrown-livefront force-pushed the billing/PM-39927/org-subscription-preview branch from df4eccc to 63e3371 Compare August 27, 2026 14:49
Comment thread src/Libraries/Invoicing/InvoicePreviews/Queries/GetSubscriptionPreviewQuery.cs Outdated
Comment thread src/Libraries/Invoicing/README.md Outdated

@amorask-bitwarden amorask-bitwarden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, nice work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review t:feature Change Type - Feature Development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants