Skip to content

[PM 18208]Cancel self-serve trials with no payment method #5916

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cyprain-okeke
Copy link
Contributor

🎟️ Tracking

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

📔 Objective

Acceptance criteria

GIVEN: a free trial is being created without a payment method (applies to PM/SM, Families, Teams, and Enterprise)

THEN: trial_settings.end_behavior.missing_payment_method should be set to cancel

GIVEN: ALL the following

a subscription is in a trialing status

the trial_settings.end_behavior.missing_payment_method is set to cancel

WHEN: account credit is added (any amount)

THEN: update trial_settings.end_behavior.missing_payment_method to create-invoice

Description

The finance and billing teams have requested that the following changes be made to how we handle payment optional trials in order to better align with accounting best practices.

📸 Screenshots

Screenshot 2025-06-04 at 11 31 06

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 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

@cyprain-okeke cyprain-okeke requested a review from a team as a code owner June 4, 2025 10:32
Copy link
Contributor

github-actions bot commented Jun 4, 2025

Logo
Checkmarx One – Scan Summary & Details5bce8bc9-92b3-4f90-9c53-96ec09601715

New Issues (1)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Icons/Controllers/IconsController.cs: 43
detailsMethod Get at line 43 of /src/Icons/Controllers/IconsController.cs gets a parameter from a user request from Get. This parameter value flows thro...
ID: wTYkppP9wWZ4JKEG9l69cPSPWek%3D
Attack Vector
Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Icons/Controllers/IconsController.cs: 43

Copy link

codecov bot commented Jun 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 47.73%. Comparing base (66301bb) to head (20cc2c3).

Files with missing lines Patch % Lines
...ices/Implementations/OrganizationBillingService.cs 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5916      +/-   ##
==========================================
- Coverage   47.74%   47.73%   -0.01%     
==========================================
  Files        1665     1665              
  Lines       75008    75019      +11     
  Branches     6755     6756       +1     
==========================================
  Hits        35814    35814              
- Misses      37734    37745      +11     
  Partials     1460     1460              

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

@@ -417,6 +417,18 @@ private async Task<Subscription> CreateSubscriptionAsync(
TrialPeriodDays = subscriptionSetup.SkipTrial ? 0 : plan.TrialPeriodDays
};

// Only set trial_settings.end_behavior.missing_payment_method to "cancel" if there is no payment method
if (string.IsNullOrEmpty(customer.InvoiceSettings?.DefaultPaymentMethodId))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is PayPal a valid payment method for this scenario? If so, this would not catch a PayPal customer.

@@ -76,6 +76,25 @@ public async Task Credit(User user, decimal amount)
};

await stripeAdapter.CustomerUpdateAsync(customer.Id, options);

// If the user has a subscription in trial, update the trial settings
if (!string.IsNullOrEmpty(user.GatewaySubscriptionId))
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden Jun 4, 2025

Choose a reason for hiding this comment

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

❓ Isn't create_invoice the default setting for this switch? You can verify this by creating a subscription against main and checking the trial_settings. If so, this block of code is unnecessary.

Copy link

sonarqubecloud bot commented Jun 5, 2025

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.

2 participants