Skip to content

[PM-31771]Default payment method not updated within subscription#7253

Open
cyprain-okeke wants to merge 2 commits intomainfrom
billing/pm-31771/default-payment-method-not-updated-within-subscription
Open

[PM-31771]Default payment method not updated within subscription#7253
cyprain-okeke wants to merge 2 commits intomainfrom
billing/pm-31771/default-payment-method-not-updated-within-subscription

Conversation

@cyprain-okeke
Copy link
Contributor

@cyprain-okeke cyprain-okeke commented Mar 19, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-31771

📔 Objective

This PR fixes a bug where the payment method was not being properly updated when restarting a canceled organization
subscription through the resubscribe flow.

Background

When an organization owner restarted a canceled subscription by providing a new payment method via the /subscription/restart
endpoint, the old payment method was still being used to charge the subscription instead of the newly provided payment method.

Changes

  • Modified RestartSubscriptionCommand.cs: Added explicit fetching of the customer's current default payment method and passing
    it to the SubscriptionCreateOptions when creating the new subscription
  • Updated RestartSubscriptionCommandTests.cs: Added mocks for GetCustomer and assertions to verify DefaultPaymentMethod is
    explicitly set in all success scenarios

Technical Details

Previously, the subscription restart flow relied on Stripe's OffSession = true parameter to automatically use the customer's
default payment method. However, this could result in using a stale/cached payment method due to timing issues between updating
the payment method and creating the subscription.

The fix explicitly fetches the customer object after the payment method has been updated and passes the DefaultPaymentMethodId
to the SubscriptionCreateOptions, ensuring the correct payment method is always used regardless of Stripe's caching behavior.

Testing

  • All 13 existing unit tests pass
  • Added verification that DefaultPaymentMethod is explicitly set in subscription creation across all test scenarios
  • Manual testing confirmed payment method is now properly updated when restarting subscriptions

Fixes: [Issue tracking payment method update bug during subscription restart]

📸 Screenshots

Before the Fix Video

Screen.Recording.2026-03-19.at.2.05.04.PM.mov

After the Fix Video

Screen.Recording.2026-03-19.at.1.57.44.PM.mov

@cyprain-okeke cyprain-okeke requested a review from a team as a code owner March 19, 2026 13:43
@cyprain-okeke cyprain-okeke requested a review from kdenney March 19, 2026 13:43
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Logo
Checkmarx One – Scan Summary & Details7f8b3fc0-eff5-42ac-993c-9fda08dbb2fe

Great job! No new security vulnerabilities introduced in this pull request

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.68%. Comparing base (3d99dbe) to head (8ee23fc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7253   +/-   ##
=======================================
  Coverage   57.68%   57.68%           
=======================================
  Files        2035     2035           
  Lines       89647    89649    +2     
  Branches     7994     7995    +1     
=======================================
+ Hits        51709    51711    +2     
+ Misses      36074    36073    -1     
- Partials     1864     1865    +1     

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant