Skip to content

[PM-40292] fix: Handle deleted Stripe customer on Admin user and provider edit pages - #8256

Closed
amorask-bitwarden wants to merge 3 commits into
mainfrom
billing/PM-40292/unable-to-access-provider-invalid-customerid
Closed

[PM-40292] fix: Handle deleted Stripe customer on Admin user and provider edit pages#8256
amorask-bitwarden wants to merge 3 commits into
mainfrom
billing/PM-40292/unable-to-access-provider-invalid-customerid

Conversation

@amorask-bitwarden

@amorask-bitwarden amorask-bitwarden commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🎟️ Tracking

Resolves PM-40292

📔 Objective

The Admin Portal user-edit and provider-edit pages returned a 500 when the subscriber's linked Stripe customer had been deleted. Retrieving a deleted Stripe customer returns an HTTP 200 stub (Deleted = true, Metadata = null) instead of a 404, which produced two different crashes:

  • User editGetBillingAsync calls Stripe's payment-methods list endpoint, which does return resource_missing for a deleted customer, throwing StripeException.
  • Provider editCustomerExtensions.ApprovedToPayByInvoice dereferenced the stub's null Metadata, throwing NullReferenceException.

Both pages now degrade gracefully, mirroring the organization fix from PM-38874:

  • UsersController.Edit (GET) wraps the billing loads in try/catch — resource_missing surfaces a Warning toast, any other failure an Error toast, and both billing values reset to null so the page still renders.
  • ApprovedToPayByInvoice guards null Metadata (fixing the root cause for all three callers), and ProvidersController.GetEditModel surfaces a Warning toast when the customer is a deleted stub.

In every case the admin can still edit the page and set a valid Gateway Customer ID.

Tests: new UsersControllerTests and CustomerExtensionsTests, plus a deleted-customer case added to ProvidersControllerTests.

…ider edit pages

A deleted Stripe customer made the Admin Portal user and provider edit
pages crash. The user page surfaced a StripeException from the payment-
methods lookup in GetBillingAsync; the provider page threw a
NullReferenceException dereferencing the deleted-customer stub's null
Metadata in ApprovedToPayByInvoice. Both now degrade gracefully: billing
state is skipped and the admin is warned to set a valid Gateway Customer
ID, mirroring the organization fix from PM-38874.
@amorask-bitwarden amorask-bitwarden added ai-review Request a Claude code review t:bugfix Change Type - Bugfix labels Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the Admin Portal handling of deleted Stripe customers across UsersController.Edit (GET), ProvidersController.GetEditModel, the ApprovedToPayByInvoice null-Metadata guard, the Views/Users/Edit.cshtml partial guard, and the new tests. The try/catch, logging, and toast wording mirror the organization fix from PM-38874 (OrganizationsController.cs:239-266), and the Deleted: true pattern correctly handles Stripe's nullable Deleted flag. The view guard only suppresses the billing section when a billing load actually failed — GetBillingAsync/GetBillingHistoryAsync always return non-null instances on success, so unaffected users see no change, and the Gateway Customer ID field and its scripts live outside the guarded block so admins can still remediate.

Code Review Details

No findings.

Note: the github-code-quality annotation on the generic catch (Exception) in src/Admin/Controllers/UsersController.cs:133 is not raised here — the block wraps only the two payment-service calls and matches the established pattern in OrganizationsController.GetEditModel.

Comment thread src/Admin/Controllers/UsersController.cs
Comment thread src/Admin/Controllers/UsersController.cs Dismissed
@amorask-bitwarden
amorask-bitwarden marked this pull request as ready for review August 25, 2026 20:12
@amorask-bitwarden
amorask-bitwarden requested review from a team as code owners August 25, 2026 20:12
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.55%. Comparing base (13faf3e) to head (4c6823b).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...in/AdminConsole/Controllers/ProvidersController.cs 75.00% 0 Missing and 2 partials ⚠️
src/Admin/Controllers/UsersController.cs 96.42% 1 Missing ⚠️
src/Admin/Views/Users/Edit.cshtml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8256      +/-   ##
==========================================
+ Coverage   63.19%   63.55%   +0.35%     
==========================================
  Files        2409     2430      +21     
  Lines      104393   105554    +1161     
  Branches     9453     9642     +189     
==========================================
+ Hits        65971    67082    +1111     
- Misses      36164    36169       +5     
- Partials     2258     2303      +45     

☔ View full report in Codecov by Harness.
📢 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.

@sbrown-livefront sbrown-livefront left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@amorask-bitwarden
amorask-bitwarden deleted the billing/PM-40292/unable-to-access-provider-invalid-customerid branch August 27, 2026 16:44
@amorask-bitwarden

Copy link
Copy Markdown
Contributor Author

Superseded by #8276. This PR was auto-closed when the branch was renamed to lowercase (PMpm) per release-engineering's no-capitals rule. The renamed branch and all commits (including the fix for the CRITICAL billing-partial review finding, commit 4c6823b) carried over to #8276.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants