Skip to content

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

Merged
amorask-bitwarden merged 4 commits into
mainfrom
billing/pm-40292/unable-to-access-provider-invalid-customerid
Aug 28, 2026
Merged

[PM-40292] fix: Handle deleted Stripe customer on Admin user and provider edit pages#8276
amorask-bitwarden merged 4 commits into
mainfrom
billing/pm-40292/unable-to-access-provider-invalid-customerid

Conversation

@amorask-bitwarden

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

Copy link
Copy Markdown
Contributor

🎟️ Tracking

Resolves PM-40292

Supersedes #8256, which was auto-closed when the branch was renamed to lowercase (PMpm) per release-engineering's no-capitals rule. The one CRITICAL review finding from that PR — the billing partial dereferencing null BillingInfo/BillingHistoryInfo in Views/Users/Edit.cshtml — is fixed here in commit 4c6823b.

📔 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.
  • Views/Users/Edit.cshtml guards the billing partial so a null billing model hides the section instead of crashing during render.
  • 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.

amorask-bitwarden and others added 3 commits August 25, 2026 14:31
…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.
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the deleted-Stripe-customer handling across UsersController.Edit (GET), ProvidersController.GetEditModel, the Views/Users/Edit.cshtml billing partial guard, and the ApprovedToPayByInvoice null-Metadata guard, plus the three accompanying test files. The user-edit try/catch and the view guard match the already-merged organization pattern in OrganizationsController.Edit and AdminConsole/Views/Organizations/Edit.cshtml line for line, including the StripeError?.Code filter, the reset of both billing values in the catch, and the Warning/Error TempData keys that _Layout.cshtml renders. UserEditModel is #nullable disable and stores both billing values without dereferencing them, so passing nulls is safe, and the customer is { Deleted: true } pattern correctly handles Stripe.NET's bool?. The Metadata guard fixes the NRE for all three ApprovedToPayByInvoice call sites, including the unguarded POST-path call at ProvidersController.cs:398.

No findings.

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

codecov Bot commented Aug 27, 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.48%. Comparing base (955cfa2) to head (3e6a747).

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    #8276       +/-   ##
=========================================
+ Coverage      0   63.48%   +63.48%     
=========================================
  Files         0     2430     +2430     
  Lines         0   104955   +104955     
  Branches      0     9506     +9506     
=========================================
+ Hits          0    66631    +66631     
- Misses        0    36031    +36031     
- Partials      0     2293     +2293     

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

@amorask-bitwarden
amorask-bitwarden merged commit 7640e4b into main Aug 28, 2026
56 of 57 checks passed
@amorask-bitwarden
amorask-bitwarden deleted the billing/pm-40292/unable-to-access-provider-invalid-customerid branch August 28, 2026 14:53
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