mirror of
https://github.com/bitwarden/server
synced 2025-12-22 11:13:27 +00:00
[PM 26682]milestone 2d display discount on subscription page (#6542)
* The discount badge implementation * Address the claude pr comments * Add more unit testing * Add more test * used existing flag * Add the coupon Ids * Add more code documentation * Add some recommendation from claude * Fix addition comments and prs * Add more integration test * Fix some comment and add more test * rename the test methods * Add more unit test and comments * Resolve the null issues * Add more test * reword the comments * Rename Variable * Some code refactoring * Change the coupon ID to milestone-2c * Fix the failing Test
This commit is contained in:
@@ -643,9 +643,21 @@ public class StripePaymentService : IPaymentService
|
||||
var subscription = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId,
|
||||
new SubscriptionGetOptions { Expand = ["customer.discount.coupon.applies_to", "discounts.coupon.applies_to", "test_clock"] });
|
||||
|
||||
if (subscription == null)
|
||||
{
|
||||
return subscriptionInfo;
|
||||
}
|
||||
|
||||
subscriptionInfo.Subscription = new SubscriptionInfo.BillingSubscription(subscription);
|
||||
|
||||
var discount = subscription.Customer.Discount ?? subscription.Discounts.FirstOrDefault();
|
||||
// Discount selection priority:
|
||||
// 1. Customer-level discount (applies to all subscriptions for the customer)
|
||||
// 2. First subscription-level discount (if multiple exist, FirstOrDefault() selects the first one)
|
||||
// Note: When multiple subscription-level discounts exist, only the first one is used.
|
||||
// This matches Stripe's behavior where the first discount in the list is applied.
|
||||
// Defensive null checks: Even though we expand "customer" and "discounts", external APIs
|
||||
// may not always return the expected data structure, so we use null-safe operators.
|
||||
var discount = subscription.Customer?.Discount ?? subscription.Discounts?.FirstOrDefault();
|
||||
|
||||
if (discount != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user