Skip to content

[PM-30271] Create Retrieve Eligible Subscription Discounts Endpoint#7063

Open
sbrown-livefront wants to merge 11 commits intomainfrom
billing/pm-30271/fetch-discounts-endpoint
Open

[PM-30271] Create Retrieve Eligible Subscription Discounts Endpoint#7063
sbrown-livefront wants to merge 11 commits intomainfrom
billing/pm-30271/fetch-discounts-endpoint

Conversation

@sbrown-livefront
Copy link
Collaborator

🎟️ Tracking

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

📔 Objective

This pull request introduces a new API endpoint for retrieving eligible subscription discounts for a user and implements the supporting backend infrastructure for discount eligibility evaluation. It adds new service interfaces, implementations, audience filter logic, and comprehensive tests to ensure correct discount selection and mapping.

API and Controller Enhancements:

  • Added a new GET /discounts endpoint in AccountBillingVNextController that returns all applicable subscription discounts for the authenticated user. This endpoint is feature-flagged and uses a new query interface to fetch eligible discounts.

Discount Eligibility Infrastructure:

  • Introduced the ISubscriptionDiscountService interface and its implementation SubscriptionDiscountService to manage discount eligibility checks, including support for audience-based rules.
  • Added the IDiscountAudienceFilter interface and a factory (IDiscountAudienceFilterFactory/DiscountAudienceFilterFactory) for instantiating audience filters based on discount targeting rules, with an initial implementation for "UserHasNoPreviousSubscriptions".

Query and Response Models:

  • Created the IGetApplicableDiscountsQuery interface and its implementation to return eligible discounts mapped to the new SubscriptionDiscountResponseModel, which includes all relevant discount details.

Dependency Injection and Service Registration:

  • Registered all new services, queries, and filter factories in the payment service registration module to ensure proper DI resolution.

📸 Screenshots

Screen.Recording.2026-02-24.at.10.56.01.AM.mov

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Logo
Checkmarx One – Scan Summary & Detailsbe7d3eae-c3c3-4070-9a7b-ab06ed2a9841


New Issues (1) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF /src/Api/Billing/Controllers/VNext/AccountBillingVNextController.cs: 133
detailsMethod at line 133 of /src/Api/Billing/Controllers/VNext/AccountBillingVNextController.cs gets a parameter from a user request from user. This p...
Attack Vector

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.79%. Comparing base (44e993e) to head (29c373d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7063      +/-   ##
==========================================
+ Coverage   56.76%   56.79%   +0.02%     
==========================================
  Files        2014     2019       +5     
  Lines       88218    88279      +61     
  Branches     7855     7861       +6     
==========================================
+ Hits        50073    50134      +61     
  Misses      36321    36321              
  Partials     1824     1824              

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

@sonarqubecloud
Copy link

@kdenney kdenney self-requested a review February 25, 2026 21:12
@sbrown-livefront sbrown-livefront self-assigned this Feb 25, 2026

// Discount services
services.AddTransient<ISubscriptionDiscountService, SubscriptionDiscountService>();
services.AddTransient<IDiscountAudienceFilterFactory, DiscountAudienceFilterFactory>();
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ What do you think about adding the factory class as a singleton? Since it shouldn't ever need instantiated more than once, I don't think... Do you agree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do! Great callout. I'll update this

/// <inheritdoc />
/// <remarks>
/// To add support for a new audience type: add an enum value, create a filter class, and add a case here.
/// </remarks>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. Thanks for adding this comment here!


// Assert
Assert.Null(filter);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ What do you think about adding a unit test here that would use reflection to loop through all of the possible values in the enum and with the exception of AllUsers, would fail if any don't have a corresponding filter returned, as a guard against the pattern not being followed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, so I understand, if a user adds a new enum but not a filter, the unit test will show there is no corresponding filter?

Great idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep exactly. 🙌

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