Skip to content

Conversation

@amorask-bitwarden
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden commented Jan 28, 2026

🎟️ Tracking

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

📔 Objective

Consolidates the handling of subscriptions that transition to unpaid status across all entity types (Premium users, Organizations, and Providers).

Previously, each entity type was handled differently:

  • Premium users: Subscription was immediately canceled
  • Organizations: A Quartz job was scheduled to cancel the subscription after 7 days
  • Providers: cancel_at was set on the subscription to 7 days in the future

This PR standardizes on the Provider approach for all entity types:

  1. Disable the subscriber (user premium, organization, or provider)
  2. Set the subscription's cancel_at to 7 days in the future

This gives customers a consistent 7-day grace period to resolve payment issues before their subscription is canceled, regardless of subscription type.

Additional improvements:

  • Removes the Quartz scheduler dependency for organization cancellation
  • Adds ProrationBehavior.None to prevent unintended proration charges during cancellation/reactivation
  • Includes CancellationDetails.Comment for better audit trail when setting cancellation

Testing: Unit tests in SubscriptionUpdatedHandlerTests.cs were updated to reflect the consolidated behavior and verify the new subscription update options.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@amorask-bitwarden amorask-bitwarden marked this pull request as ready for review January 28, 2026 20:17
@amorask-bitwarden amorask-bitwarden requested a review from a team as a code owner January 28, 2026 20:17
@github-actions
Copy link
Contributor

Logo
Checkmarx One – Scan Summary & Detailscc41100f-e7de-43ea-af68-a32cd53767ca

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

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 96.73913% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.06%. Comparing base (bfefd27) to head (158cbb9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ices/Implementations/SubscriptionUpdatedHandler.cs 96.73% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6918      +/-   ##
==========================================
- Coverage   56.06%   56.06%   -0.01%     
==========================================
  Files        1969     1969              
  Lines       87078    87014      -64     
  Branches     7757     7735      -22     
==========================================
- Hits        48821    48784      -37     
+ Misses      36448    36425      -23     
+ Partials     1809     1805       -4     

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

var premiumPriceIds = premiumPlans.SelectMany(p => new[] { p.Seat.StripePriceId, p.Storage.StripePriceId }).ToHashSet();
return subscription.Items.Any(i => premiumPriceIds.Contains(i.Price.Id));
}
var now = subscription.TestClock?.FrozenTime ?? DateTime.UtcNow;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man, I'm filing this away to remember in the future. I am now wondering if I should have used this instead of using the invoice period end in my current PR haha

Copy link
Contributor

@kdenney kdenney left a comment

Choose a reason for hiding this comment

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

Nice job!! 🎉 This is way cleaner. I have just a couple of non-blocking questions.

LatestInvoice.BillingReason: BillingReasons.SubscriptionCreate or BillingReasons.SubscriptionCycle
};

private Task DisableSubscriberAsync(SubscriberId subscriberId, DateTime? currentPeriodEnd) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ What do you think about moving these methods that operate on a SubscriberId into SubscriberService? It would help clean up this file even more, they will be public so unit tests can target the methods individually which is always a bonus, and I could even see a possibility for these to be used elsewhere in the application at some point so having them in a service makes that easy.

{
var scheduler = await _schedulerFactory.GetScheduler();

var job = JobBuilder.Create<SubscriptionCancellationJob>()
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ This job is now unused. I assume that removing SubscriptionCancellationJob from the codebase would cause any scheduled jobs in the queue at the time of release to throw exceptions? I also assume that's why you didn't delete it in this PR? 😆 Is there a follow-up ticket for deleting it?

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.

3 participants