Skip to content

Conversation

@cyprain-okeke
Copy link
Contributor

🎟️ Tracking

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

📔 Objective

Fix premium subscription status handling to enable resubscription for users with canceled or expired subscriptions, and improve incomplete subscription payment retry logic.

Changes

API Layer (AccountBillingVNextController.cs:105)

  • Return 404 Not Found when user has no subscription instead of 200 OK with null body

Payment Processing (PaymentMethodAttachedHandler.cs:107-136)

  • Extend payment retry logic to handle both unpaid and incomplete subscription statuses
  • Add safeguard to prevent overcharging when multiple incomplete subscriptions exist
  • Log warning and skip retry when multiple incomplete subscriptions detected
  • Improve logging messages to include subscription status

Subscription Management (SubscriptionUpdatedHandler.cs:120-131)

  • Remove automatic cancellation logic for incomplete subscriptions with open invoices
  • This prevents premature cancellation and enables proper resubscription flow

Premium Subscription Creation (CreatePremiumCloudHostedSubscriptionCommand.cs:75-154)

  • Allow resubscription for users with canceled or incomplete_expired subscriptions
  • Update payment method on resubscribe scenarios to use new payment method
  • Accept incomplete status as valid for premium activation (in addition to active)
  • Skip "already premium" validation for users with terminal subscription states

Subscription Query (GetBitwardenSubscriptionQuery.cs:41-46)

  • Return null when user has no GatewaySubscriptionId instead of attempting to fetch subscription
  • Change return type from BitwardenSubscription to BitwardenSubscription?

📸 Screenshots

https://github.com/user-attachments/assets/ccef0537-32ee-4920-9c39-fa79e10625a4
https://github.com/user-attachments/assets/4c7d71fc-3ce0-4a3a-b304-4dced91853a0
https://github.com/user-attachments/assets/ea66df1d-6d74-46e4-8fed-2e02bca804f1

⏰ 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

@cyprain-okeke cyprain-okeke requested a review from a team as a code owner January 21, 2026 11:15
@cyprain-okeke cyprain-okeke requested a review from kdenney January 21, 2026 11:15
@github-actions
Copy link
Contributor

github-actions bot commented Jan 21, 2026

Logo
Checkmarx One – Scan Summary & Detailsecd40ab4-b081-461d-b5bb-692def866aa5

New Issues (5)

Checkmarx found the following issues in this Pull Request

# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF /src/Api/Billing/Controllers/VNext/AccountBillingVNextController.cs: 123
detailsMethod at line 123 of /src/Api/Billing/Controllers/VNext/AccountBillingVNextController.cs gets a parameter from a user request from request. Thi...
Attack Vector
2 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1178
detailsMethod at line 1178 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
3 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1062
detailsMethod at line 1062 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
4 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1527
detailsMethod at line 1527 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
5 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1403
detailsMethod at line 1403 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 293

@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 51.66667% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.06%. Comparing base (bab4750) to head (4551244).

Files with missing lines Patch % Lines
...es/Implementations/PaymentMethodAttachedHandler.cs 0.00% 26 Missing ⚠️
...nds/CreatePremiumCloudHostedSubscriptionCommand.cs 93.33% 0 Missing and 2 partials ⚠️
...Controllers/VNext/AccountBillingVNextController.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6877   +/-   ##
=======================================
  Coverage   56.05%   56.06%           
=======================================
  Files        1966     1966           
  Lines       86892    86925   +33     
  Branches     7737     7740    +3     
=======================================
+ Hits        48709    48734   +25     
- Misses      36382    36389    +7     
- Partials     1801     1802    +1     

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

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; just a couple suggestions and a request for more tests. :)

@cyprain-okeke cyprain-okeke requested a review from kdenney January 22, 2026 10:14
@amorask-bitwarden amorask-bitwarden self-requested a review January 22, 2026 15:01
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden left a comment

Choose a reason for hiding this comment

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

A few things and a couple missed requirements:

  1. We should no longer auto-cancel and void invoices for premium subscriptions that enter unpaid or incomplete_expired status. We should still disable premium.
  2. The UpdatePaymentMethodCommand’s AddPayPalAsync method needs to be updated to do the same thing as Task 2 above (pay the single, incomplete subscription invoice) using the IBraintreeService.PayInvoice method when the user adds or replaces their PayPal payment method.

Comment on lines +79 to +96
var hasTerminalSubscription = false;
if (!string.IsNullOrEmpty(user.GatewaySubscriptionId))
{
try
{
var existingSubscription = await stripeAdapter.GetSubscriptionAsync(user.GatewaySubscriptionId);
hasTerminalSubscription = existingSubscription.Status is
SubscriptionStatus.Canceled or
SubscriptionStatus.IncompleteExpired;
}
catch (Exception ex)
{
// Subscription doesn't exist in Stripe or can't be fetched (e.g., network issues, invalid ID)
// Log the issue but proceed with subscription creation to avoid blocking legitimate resubscribe attempts
_logger.LogWarning(ex, "Unable to fetch existing subscription {SubscriptionId} for user {UserId}. Proceeding with subscription creation",
user.GatewaySubscriptionId, user.Id);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Can we extract this entire thing to a private method?

_ =>
{
if (subscription.Status != SubscriptionStatus.Active)
if (subscription.Status is not (SubscriptionStatus.Active or SubscriptionStatus.Incomplete))
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ This doesn't seem correct. Can a subscription start in an incomplete status when paying with account credit? I don't think that's possible.

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.

4 participants