Skip to content
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

[PM-18028] Attempting to enable automatic tax on customer with invalid location #5374

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

jonashendrickx
Copy link
Member

🎟️ Tracking

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

📔 Objective

Enabling automatic tax for customers without a country set or with tax rates causes issues.

📸 Screenshots

⏰ 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

@jonashendrickx jonashendrickx requested a review from a team as a code owner February 6, 2025 10:55
Copy link

sonarqubecloud bot commented Feb 6, 2025

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 14.06250% with 55 lines in your changes missing coverage. Please review.

Project coverage is 44.25%. Comparing base (1c3ea11) to head (fb25ed1).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...e/Services/Implementations/StripePaymentService.cs 18.75% 12 Missing and 1 partial ⚠️
.../Extensions/SubscriptionUpdateOptionsExtensions.cs 0.00% 11 Missing ⚠️
...ing/Extensions/UpcomingInvoiceOptionsExtensions.cs 0.00% 11 Missing ⚠️
...ling/Services/Implementations/SubscriberService.cs 16.66% 8 Missing and 2 partials ⚠️
...Services/Implementations/UpcomingInvoiceHandler.cs 0.00% 4 Missing ⚠️
.../Extensions/SubscriptionCreateOptionsExtensions.cs 50.00% 3 Missing and 1 partial ⚠️
src/Core/Billing/Extensions/CustomerExtensions.cs 0.00% 0 Missing and 1 partial ⚠️
...vices/Implementations/PremiumUserBillingService.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5374      +/-   ##
==========================================
+ Coverage   44.20%   44.25%   +0.05%     
==========================================
  Files        1494     1501       +7     
  Lines       69024    69312     +288     
  Branches     6224     6293      +69     
==========================================
+ Hits        30510    30677     +167     
- Misses      37194    37308     +114     
- Partials     1320     1327       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

Logo
Checkmarx One – Scan Summary & Detailsaff201f2-7e20-4a9d-8a43-4d9db7168a03

Great job, no security vulnerabilities found in this Pull Request

Copy link
Contributor

@cturnbull-bitwarden cturnbull-bitwarden left a comment

Choose a reason for hiding this comment

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

Approved with a nit!

return false;
}

options.DefaultTaxRates = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️
In general, I would opt for immutable operations over mutable ones like this.

Not to say that there's never a time we should mutate input params. While this encapsulates the logic to ensure that SubscriptionCreateOptions always has its DefaultTaxRates set to [], which is a good thing, it also introduces a side effect that is hidden from the caller, namely conditionally setting DefaultTaxRates and AutomaticTax on the input parameter options by reference.

Without the engineer knowing ahead of time that this side effect exists, it would be reasonable to assume that they might try to also set these values elsewhere depending on the return value of this method. This also introduces some coupling given that this side effect behavior is tightly governed by the external state, which we could argue makes it a bit harder to decouple later on should we choose.

@amorask-bitwarden has done a good job of setting up a reusable pattern to borrow from, by creating .From extensions to handle this kind of immutable mapping logic. Take OrganizationMetadataResponse as an example.

Again, this is a nit, just wanted to leave it as a thought

/// </summary>
/// <param name="customer"></param>
/// <returns></returns>
public static bool HasTaxLocationVerified(this Customer customer) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 nice, I like this

@jonashendrickx jonashendrickx merged commit 678d5d5 into main Feb 6, 2025
53 checks passed
@jonashendrickx jonashendrickx deleted the PM-18028 branch February 6, 2025 15:34
@jonashendrickx jonashendrickx restored the PM-18028 branch February 6, 2025 16:11
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.

3 participants