Skip to content

[PM-33899] Release schedule on terminal subscription operations#7305

Open
amorask-bitwarden wants to merge 3 commits intomainfrom
billing/PM-33899/release-schedule-terminal
Open

[PM-33899] Release schedule on terminal subscription operations#7305
amorask-bitwarden wants to merge 3 commits intomainfrom
billing/PM-33899/release-schedule-terminal

Conversation

@amorask-bitwarden
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden commented Mar 25, 2026

🎟️ Tracking

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

📔 Objective

Introduces IPriceIncreaseScheduler — a shared service that consolidates subscription schedule creation and release logic behind the PM32645_DeferPriceMigrationToRenewal feature flag. Previously, schedule creation lived as a private method in UpcomingInvoiceHandler and release guards were inlined at each call site.

Schedule(Subscription) — Creates a two-phase subscription schedule that defers a price increase to the renewal date. Resolves the subscriber type via SubscriberId metadata to determine the correct migration path (Premium or Families), builds the appropriate Phase 2 configuration (target price + discount), and creates the schedule in Stripe. Returns bool so callers can skip downstream processing (e.g., renewal emails) when a schedule already exists.

Release(string customerId, string subscriptionId) — Releases any active schedule for the subscription, cancelling a pending deferred price increase. Logs and re-throws on failure, requiring manual release via the Stripe Dashboard.

Call sites:

  • UpcomingInvoiceHandler — calls Schedule during invoice.upcoming processing (replaces the private SchedulePriceMigrationAsync)
  • SubscriptionUpdatedHandler — calls Release when a subscription goes unpaid; calls Schedule when a subscription recovers (recreates the schedule)
  • UpgradePremiumToOrganizationCommand — calls Release before upgrading to an org plan
  • SetUpSponsorshipCommand — calls Release before applying a sponsorship

📸 Screenshots

@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2026

Logo
Checkmarx One – Scan Summary & Details5a48ff82-724b-4a29-accc-e338e5e7bcdc

Great job! No new security vulnerabilities introduced in this pull request

@amorask-bitwarden amorask-bitwarden marked this pull request as ready for review March 25, 2026 14:16
@amorask-bitwarden amorask-bitwarden requested a review from a team as a code owner March 25, 2026 14:16
@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 83.02752% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.94%. Comparing base (89f6e43) to head (9cd250d).

Files with missing lines Patch % Lines
src/Core/Billing/Pricing/PriceIncreaseScheduler.cs 81.77% 31 Missing and 4 partials ⚠️
...Services/Implementations/UpcomingInvoiceHandler.cs 60.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7305      +/-   ##
==========================================
+ Coverage   57.91%   57.94%   +0.03%     
==========================================
  Files        2044     2045       +1     
  Lines       90130    90243     +113     
  Branches     8018     8026       +8     
==========================================
+ Hits        52199    52295      +96     
- Misses      36066    36080      +14     
- Partials     1865     1868       +3     

☔ 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.

@sonarqubecloud
Copy link

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.

1 participant