-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-30908]Correct Premium subscription status handling #6877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[PM-30908]Correct Premium subscription status handling #6877
Conversation
|
New Issues (5)Checkmarx found the following issues in this Pull Request
|
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
kdenney
left a comment
There was a problem hiding this 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. :)
src/Core/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommand.cs
Outdated
Show resolved
Hide resolved
src/Core/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommand.cs
Show resolved
Hide resolved
amorask-bitwarden
left a comment
There was a problem hiding this 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:
- We should no longer auto-cancel and void invoices for premium subscriptions that enter unpaid or incomplete_expired status. We should still disable premium.
- 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.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
…n-status-handling


🎟️ 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)
Payment Processing (PaymentMethodAttachedHandler.cs:107-136)
Subscription Management (SubscriptionUpdatedHandler.cs:120-131)
Premium Subscription Creation (CreatePremiumCloudHostedSubscriptionCommand.cs:75-154)
Subscription Query (GetBitwardenSubscriptionQuery.cs:41-46)
📸 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
🦮 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