-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-24616] refactor stripe adapter #6527
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?
Conversation
# Conflicts: # bitwarden_license/src/Commercial.Core/Billing/Providers/Services/ProviderBillingService.cs # bitwarden_license/test/Commercial.Core.Test/Billing/Providers/Services/ProviderBillingServiceTests.cs # src/Admin/AdminConsole/Controllers/ProvidersController.cs # src/Api/Billing/Controllers/OrganizationBillingController.cs # src/Api/Billing/Controllers/ProviderBillingController.cs # src/Core/AdminConsole/OrganizationFeatures/Import/ImportOrganizationUsersAndGroupsCommand.cs # src/Core/Billing/Organizations/Services/OrganizationBillingService.cs # src/Core/Billing/Payment/Commands/VerifyBankAccountCommand.cs # src/Core/Billing/Payment/Queries/GetPaymentMethodQuery.cs # src/Core/Billing/Providers/Migration/Services/Implementations/ProviderMigrator.cs # src/Core/Billing/Services/Implementations/StripePaymentService.cs # src/Core/Billing/Services/Implementations/SubscriberService.cs # src/Core/Billing/Tax/Commands/PreviewTaxAmountCommand.cs # src/Core/Services/IStripeAdapter.cs # src/Core/Services/Implementations/StripeAdapter.cs # test/Core.Test/AdminConsole/OrganizationFeatures/Import/ImportOrganizationUsersAndGroupsCommandTests.cs # test/Core.Test/Billing/Organizations/Queries/GetOrganizationWarningsQueryTests.cs # test/Core.Test/Billing/Payment/Commands/VerifyBankAccountCommandTests.cs # test/Core.Test/Billing/Services/StripePaymentServiceTests.cs # test/Core.Test/Billing/Services/SubscriberServiceTests.cs # test/Core.Test/Billing/Tax/Commands/PreviewTaxAmountCommandTests.cs
…beeep/PM-24616-move-stripe-adapter # Conflicts: # bitwarden_license/src/Commercial.Core/AdminConsole/Providers/RemoveOrganizationFromProviderCommand.cs # bitwarden_license/test/Commercial.Core.Test/AdminConsole/ProviderFeatures/RemoveOrganizationFromProviderCommandTests.cs # src/Admin/Controllers/ToolsController.cs # src/Core/Billing/Providers/Migration/Services/Implementations/OrganizationMigrator.cs # src/Core/Billing/Providers/Migration/Services/Implementations/ProviderMigrator.cs # src/Core/Billing/Services/Implementations/StripePaymentService.cs # src/Core/Services/IStripeAdapter.cs # src/Core/Services/Implementations/StripeAdapter.cs
# Conflicts: # .gitignore # bitwarden_license/src/Commercial.Core/AdminConsole/Providers/RemoveOrganizationFromProviderCommand.cs # bitwarden_license/test/Commercial.Core.Test/AdminConsole/ProviderFeatures/RemoveOrganizationFromProviderCommandTests.cs # src/Api/Billing/Controllers/ProviderBillingController.cs # src/Api/Billing/Models/Responses/ProviderSubscriptionResponse.cs # src/Billing/BillingSettings.cs # src/Billing/Controllers/BitPayController.cs # src/Billing/Services/Implementations/ProviderEventService.cs # src/Billing/Services/Implementations/SubscriptionDeletedHandler.cs # src/Billing/appsettings.json # src/Core/Billing/Extensions/SubscriptionExtensions.cs # src/Core/Billing/Organizations/Queries/GetOrganizationWarningsQuery.cs # src/Core/Billing/Organizations/Services/OrganizationBillingService.cs # src/Core/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommand.cs # src/Core/Billing/Premium/Commands/PreviewPremiumTaxCommand.cs # src/Core/Billing/Services/Implementations/StripePaymentService.cs # src/Core/Services/IStripeAdapter.cs # src/Core/Services/Implementations/StripeAdapter.cs # test/Billing.Test/Services/ProviderEventServiceTests.cs # test/Billing.Test/Services/SubscriptionDeletedHandlerTests.cs # test/Core.Test/Billing/Organizations/Commands/PreviewOrganizationTaxCommandTests.cs # test/Core.Test/Billing/Organizations/Queries/GetOrganizationWarningsQueryTests.cs # test/Core.Test/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommandTests.cs # test/Core.Test/Billing/Premium/Commands/PreviewPremiumTaxCommandTests.cs
|
New Issues (1)Checkmarx found the following issues in this Pull Request
|
# Conflicts: # src/Core/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommand.cs # test/Core.Test/Billing/Premium/Commands/CreatePremiumCloudHostedSubscriptionCommandTests.cs
|
Claude finished @kdenney's task —— View job Code Review Complete
Summary of Changes Since Last ReviewAll three issues from my previous review have been successfully resolved:
The recent commits ( Critical IssuesNone found. The refactoring addresses previous feedback comprehensively. Suggested Improvements1. 📝 Inconsistent Nullable Directives FormatFile: The nullable disable directive has an extra blank line that's inconsistent with other files in the same refactoring: // Current:
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable
// Should be:
// FIXME: Update this file to be null safe and then delete the line below
#nullable disableCompare with: RationaleConsistency in formatting across the codebase makes it easier to apply automated fixes later when addressing the nullable reference type FIXMEs. 2. 🤔 Service Registration Change Needs VerificationFile: The service registration changed from: services.AddScoped<IPaymentService, StripePaymentService>();to: services.AddScoped<IStripePaymentService, StripePaymentService>();Questions:
EvidenceI verified that no code currently references
If this is intentional as part of the BEEEP initiative to separate Stripe-specific services, consider:
3.
|
| File | Missing Lines | Coverage |
|---|---|---|
StripeAdapter.cs |
63 | 21.25% |
StripePaymentService.cs |
58 | 4.91% |
PremiumUserBillingService.cs |
7 | 0.00% |
Recommendation:
While this is a refactoring PR (primarily renaming and moving), the low coverage is concerning for payment/billing code. Consider:
- High Priority: Add unit tests for
StripeAdaptermethods that weren't previously tested - Medium Priority: Improve coverage for error paths in
StripePaymentService(especially around Stripe exception handling) - Future Task: Add integration tests for the payment flow end-to-end
Why This Matters
Payment and billing code requires exceptional test coverage because:
- Financial correctness is critical (SOC 2, HIPAA compliance requirements)
- Stripe API changes can break integrations silently
- Refactoring without adequate tests increases regression risk
- The codebase has
#nullable disable, making it more prone to null reference issues
Even though this is "just a refactoring," the act of moving code is a good opportunity to add tests for previously untested paths.
4. 🌱 Consider Future Null Safety Improvements
Multiple files in this PR have #nullable disable FIXMEs:
StripeAdapter.csStripePaymentService.csStripeSyncService.cs(no FIXME, but implicitly nullable)PremiumUserBillingService.csIStripePaymentService.csIStripeAdapter.cs
Suggestion: While not required for this PR, consider filing a follow-up issue to address nullable reference types in the billing services, as this would:
- Align with ADR-0024 (Use .NET nullable reference types)
- Reduce null-reference exceptions in critical payment paths
- Improve code quality and maintainability
Good Practices Observed
👍 Consistent method naming - All adapter methods now follow the {Verb}{Noun}Async pattern
👍 Proper namespace organization - Services moved to appropriate Billing.Services namespace
👍 Interface segregation - IStripeAdapter cleanly separates Stripe API concerns
👍 Test updates included - Test files were properly renamed and updated alongside production code
👍 No functional changes - This is a true refactoring with minimal behavior changes
👍 Expression body usage - Simple pass-through methods use concise expression bodies
Action Items for Author
Required Before Merge:
- Verify the
IPaymentService→IStripePaymentServicechange won't break any consumers (internal or external) - Confirm CI tests pass completely (they currently pass, but coverage is flagged)
Recommended (Optional):
- Fix formatting inconsistency in
StripeAdapter.csnullable directive (lines 1-3) - Consider adding issue for improving test coverage in payment services
- Consider adding issue for addressing nullable reference type FIXMEs in billing services
Overall Assessment
This is a well-executed refactoring that successfully:
- ✅ Moves
StripeAdapterto the correct namespace (Core.Billing.Services) - ✅ Establishes consistent naming conventions across all Stripe-related methods
- ✅ Addresses all feedback from previous review
- ✅ Updates all call sites across 100 files without introducing compilation errors
- ✅ Maintains backward compatibility in behavior (aside from the noted DI registration change)
The main concerns are around test coverage and the service registration change, which should be verified but don't block the refactoring itself.
Recommendation: Approve after confirming the IPaymentService → IStripePaymentService change is intentional and documented.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6527 +/- ##
==========================================
+ Coverage 51.89% 52.04% +0.15%
==========================================
Files 1905 1906 +1
Lines 84232 84221 -11
Branches 7509 7516 +7
==========================================
+ Hits 43708 43837 +129
+ Misses 38821 38679 -142
- Partials 1703 1705 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|


🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-24616
📔 Objective
This is a BEEEP initiative. Main goal was to move and cleanup the StripeAdapter. Changes made:
⏰ 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