[PM-31040] Replace ISetupIntentCache with customer-based approach#6954
Merged
amorask-bitwarden merged 40 commits intomainfrom Feb 18, 2026
Merged
[PM-31040] Replace ISetupIntentCache with customer-based approach#6954amorask-bitwarden merged 40 commits intomainfrom
ISetupIntentCache with customer-based approach#6954amorask-bitwarden merged 40 commits intomainfrom
Conversation
…ser table definitions
…d Dapper implementation
…pper implementation
… index configuration
…ry instead of cache
…tPaymentMethodQuery
…sPaymentMethodQuery
…etupIntent and query by customer
…dHostedSubscriptionCommand
…od and UserService.ReplacePaymentMethodAsync
…query Stripe by customer ID Add Task 15a to plan - this was a missed requirement for updating GetPaymentSourceAsync which still used the cache.
…lize and UserService.SignUpPremiumAsync
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6954 +/- ##
==========================================
+ Coverage 56.49% 60.59% +4.10%
==========================================
Files 2003 2003
Lines 88287 87886 -401
Branches 7881 7829 -52
==========================================
+ Hits 49874 53255 +3381
+ Misses 36581 32724 -3857
- Partials 1832 1907 +75 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
New Issues (3)Checkmarx found the following issues in this Pull Request
|
sbrown-livefront
previously approved these changes
Feb 12, 2026
69f804e
sbrown-livefront
previously approved these changes
Feb 13, 2026
BTreston
previously approved these changes
Feb 17, 2026
Contributor
BTreston
left a comment
There was a problem hiding this comment.
approved for AC owned files
86f780e
mkincaid-bw
previously approved these changes
Feb 18, 2026
|
sbrown-livefront
approved these changes
Feb 18, 2026
BTreston
approved these changes
Feb 18, 2026
rkac-bw
approved these changes
Feb 18, 2026
Contributor
rkac-bw
left a comment
There was a problem hiding this comment.
Approved as per Mark's approval
gbubemismith
pushed a commit
that referenced
this pull request
Feb 27, 2026
…6954) * docs(billing): add design document for replacing SetupIntent cache * docs(billing): add implementation plan for replacing SetupIntent cache * feat(db): add gateway lookup stored procedures for Organization, Provider, and User * feat(db): add gateway lookup indexes to Organization, Provider, and User table definitions * chore(db): add SQL Server migration for gateway lookup indexes and stored procedures * feat(repos): add gateway lookup methods to IOrganizationRepository and Dapper implementation * feat(repos): add gateway lookup methods to IProviderRepository and Dapper implementation * feat(repos): add gateway lookup methods to IUserRepository and Dapper implementation * feat(repos): add EF OrganizationRepository gateway lookup methods and index configuration * feat(repos): add EF ProviderRepository gateway lookup methods and index configuration * feat(repos): add EF UserRepository gateway lookup methods and index configuration * chore(db): add EF migrations for gateway lookup indexes * refactor(billing): update SetupIntentSucceededHandler to use repository instead of cache * refactor(billing): simplify StripeEventService by expanding customer on SetupIntent * refactor(billing): query Stripe for SetupIntents by customer ID in GetPaymentMethodQuery * refactor(billing): query Stripe for SetupIntents by customer ID in HasPaymentMethodQuery * refactor(billing): update OrganizationBillingService to set customer on SetupIntent * refactor(billing): update ProviderBillingService to set customer on SetupIntent and query by customer * refactor(billing): update UpdatePaymentMethodCommand to set customer on SetupIntent * refactor(billing): remove bank account support from CreatePremiumCloudHostedSubscriptionCommand * refactor(billing): remove OrganizationBillingService.UpdatePaymentMethod dead code * refactor(billing): remove ProviderBillingService.UpdatePaymentMethod * refactor(billing): remove PremiumUserBillingService.UpdatePaymentMethod and UserService.ReplacePaymentMethodAsync * refactor(billing): remove SubscriberService.UpdatePaymentSource and related dead code * refactor(billing): update SubscriberService.GetPaymentSourceAsync to query Stripe by customer ID Add Task 15a to plan - this was a missed requirement for updating GetPaymentSourceAsync which still used the cache. * refactor(billing): complete removal of PremiumUserBillingService.Finalize and UserService.SignUpPremiumAsync * refactor(billing): remove ISetupIntentCache and SetupIntentDistributedCache * chore: remove temporary planning documents * chore: run dotnet format * fix(billing): add MaxLength(50) to Provider gateway ID properties * chore(db): add EF migrations for Provider gateway column lengths * chore: run dotnet format * chore: rename SQL migration for chronological order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-31040
📔 Objective
Replace the
ISetupIntentCachedistributed cache with a customer-based approach that directly associates StripeSetupIntentobjects with StripeCustomerobjects. This eliminates infrastructure dependencies on the distributed cache and simplifies the codebase by removing dead code paths.Problem
The
SetupIntentDistributedCachemaintained a bidirectional mapping between subscriber IDs and SetupIntent IDs, which was fragile and caused issues with the bank account payment method flow for organizations and providers.Solution
Instead of caching the SetupIntent-to-subscriber relationship:
customerfield on theSetupIntentwhen it's retrieved (during subscription creation or payment method update)GatewayCustomerIdwhen webhooks arrive, using new repository methodsChanges
Database Infrastructure (Phase 1-3)
GatewayCustomerIdandGatewaySubscriptionIdGatewayCustomerIdandGatewaySubscriptionIdcolumns for all three entity tablesSetupIntent Handling Updates (Phase 4-5)
SetupIntentSucceededHandlerto query repositories by customer ID instead of using the cacheStripeEventServiceby expanding customer data directly from SetupIntentGetPaymentMethodQueryandHasPaymentMethodQueryto query Stripe by customer IDOrganizationBillingService,ProviderBillingService, andUpdatePaymentMethodCommandto set the customer on SetupIntentsDead Code Removal (Phase 6-7)
CreatePremiumCloudHostedSubscriptionCommand(premium users cannot use bank accounts)UpdatePaymentMethodfromOrganizationBillingService,ProviderBillingService, andPremiumUserBillingService(replaced byUpdatePaymentMethodCommand)UpdatePaymentSourcefromSubscriberServiceSignUpPremiumAsyncandReplacePaymentMethodAsyncfromUserService(orphaned at API layer)FinalizefromPremiumUserBillingServiceISetupIntentCacheandSetupIntentDistributedCache📸 Screenshots
Screen.Recording.2026-02-05.at.1.40.26.PM.mov
⏰ 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