Skip to content

[PM-37084] Business Aware Schedule Recovery and Cancellation#7686

Merged
sbrown-livefront merged 43 commits into
mainfrom
billing/pm-37084/business-aware-schedule-recovery
May 26, 2026
Merged

[PM-37084] Business Aware Schedule Recovery and Cancellation#7686
sbrown-livefront merged 43 commits into
mainfrom
billing/pm-37084/business-aware-schedule-recovery

Conversation

@sbrown-livefront
Copy link
Copy Markdown
Collaborator

@sbrown-livefront sbrown-livefront commented May 20, 2026

🎟️ Tracking

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

📔 Objective

Introduces significant improvements and refactoring to the subscription price increase scheduling logic, particularly around business plan migrations and test clock handling. The changes centralize and streamline the scheduling of price increases, add new guard options, and improve testability and metadata handling. Below are the most important changes grouped by theme:

Business Plan Price Increase Scheduling Refactor:

  • Introduced a new method ScheduleForSubscription in IPriceIncreaseScheduler and its implementation, which centralizes the logic for scheduling deferred price increases based on subscription owner type, with optional guards via the new OrganizationPriceIncreaseOptions record. This includes robust eligibility checks and error handling.
  • Refactored the business price migration scheduling flow in UpcomingInvoiceHandler to use ScheduleForSubscription, and added logic to wait for Stripe test clocks to advance before proceeding, improving test reliability.

Metadata and Feature Flag Handling:

  • Standardized the use of metadata keys by referencing MetadataKeys constants, including a new CancellingUserId key, and improved feature flag checks for cancellation and migration flows in SubscriberService.

Test Clock and Stripe Integration Improvements:

  • Ensured that all relevant Stripe subscription fetches expand the correct fields (notably "customer.discount" instead of just "customer"), and added test clock handling to ensure correct sequencing in test environments.

Scheduler Invocation and Release Consistency:

  • Ensured that the price increase scheduler is consistently invoked or released in all relevant subscription state transitions, such as when removing pending cancellations or resuming from unpaid status.

📸 Screenshots

Screen.Recording.2026-05-21.at.2.42.23.PM.mov

@sbrown-livefront sbrown-livefront changed the title Billing/pm 37084/business aware schedule recovery [PM-37084] Business Aware Schedule Recovery May 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 64.75410% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.50%. Comparing base (fa1397d) to head (6e8b785).

Files with missing lines Patch % Lines
src/Core/Billing/Pricing/PriceIncreaseScheduler.cs 69.11% 18 Missing and 3 partials ⚠️
...Services/Implementations/UpcomingInvoiceHandler.cs 16.66% 17 Missing and 3 partials ⚠️
...illing/Pricing/OrganizationPriceIncreaseOptions.cs 50.00% 1 Missing ⚠️
...ling/Services/Implementations/SubscriberService.cs 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7686      +/-   ##
==========================================
- Coverage   60.51%   60.50%   -0.02%     
==========================================
  Files        2139     2140       +1     
  Lines       94608    94693      +85     
  Branches     8462     8472      +10     
==========================================
+ Hits        57253    57291      +38     
- Misses      35349    35391      +42     
- Partials     2006     2011       +5     

☔ View full report in Codecov by Sentry.
📢 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.

@sbrown-livefront sbrown-livefront self-assigned this May 20, 2026
@sbrown-livefront sbrown-livefront added the ai-review Request a Claude code review label May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This review covers a refactor of price-increase scheduling and business-plan migration recovery: a new IPriceIncreaseScheduler.ScheduleForSubscription dispatch method, OrganizationPriceIncreaseOptions guard record, expanded Stripe customer.discount retrieval across the affected handlers/commands, a CancellingUserId metadata constant, and feature-flag broadening (PM32645 ∪ PM35215) in SubscriberService and ReinstateSubscriptionCommand. Previously raised critical/important issues from prior rounds (missing Stripe expansions, dispatch routing Track A orgs through the business path, schedule-recovery wiring in SubscriberService.ScheduleForSubscription) are all resolved in the current diff. Test coverage for the new dispatch matrix (user, Track A, non-Track A org, provider, SkipIfAlreadyScheduled guard, default-options bypass) is thorough.

Code Review Details
  • ♻️ : WaitForTestClockToAdvanceAsync duplicated verbatim across UpcomingInvoiceHandler and SubscriptionUpdatedHandler (magic strings, unbounded poll); candidate for shared helper
    • src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs:425

Comment thread src/Billing/Services/Implementations/SubscriptionUpdatedHandler.cs
Comment thread test/Billing.Test/Services/SubscriptionUpdatedHandlerTests.cs
Comment thread src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs
Comment thread src/Core/Billing/Services/Implementations/SubscriberService.cs
Comment thread src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs Outdated
Comment on lines +377 to 382
var cohort = await cohortRepository.GetByIdAsync(assignment.CohortId);
if (cohort?.MigrationPathId is null) return true;

var scheduled = await priceIncreaseScheduler.ScheduleBusinessPriceIncrease(subscription, cohort);
if (!scheduled)
{
return true;
}
var migrationPath = MigrationPaths.FromId(cohort.MigrationPathId.Value);
if (migrationPath is null) return true;

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.

⛏ Seems like some logging would be useful for these null cases here, no? Otherwise, we might not see an email and not know why. I know it's unlikely given the scheduling succeeded, but just to have our bases covered.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 30a0ead

return false;
}

if (!IsTrackABusinessPlanType(organization.PlanType))
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.

❌ If we made this check more like this one: https://github.com/bitwarden/server/blob/billing/pm-37084/business-aware-schedule-recovery/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs#L235-L243, we wouldn't have to change it again when the next cohort is worked on. The cohort would act as the gate rather than these plan type checks.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in ca8e254

Comment thread src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs
@sonarqubecloud
Copy link
Copy Markdown

Comment thread src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs
@sbrown-livefront sbrown-livefront merged commit ee07462 into main May 26, 2026
67 checks passed
@sbrown-livefront sbrown-livefront deleted the billing/pm-37084/business-aware-schedule-recovery branch May 26, 2026 21:16
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants