From 19e2215376c318545c0836cac6e2055217837553 Mon Sep 17 00:00:00 2001 From: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Date: Mon, 23 Oct 2023 10:02:02 -0400 Subject: [PATCH] Added percent off to discount, removed discount from user sub (#3326) --- .../Response/Organizations/OrganizationResponseModel.cs | 4 ++-- src/Api/Models/Response/SubscriptionResponseModel.cs | 8 ++++---- src/Core/Models/Business/SubscriptionInfo.cs | 4 +++- src/Core/Services/Implementations/StripePaymentService.cs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Api/AdminConsole/Models/Response/Organizations/OrganizationResponseModel.cs b/src/Api/AdminConsole/Models/Response/Organizations/OrganizationResponseModel.cs index 1d83f79e1..c4e848b35 100644 --- a/src/Api/AdminConsole/Models/Response/Organizations/OrganizationResponseModel.cs +++ b/src/Api/AdminConsole/Models/Response/Organizations/OrganizationResponseModel.cs @@ -112,7 +112,7 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel { Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null; UpcomingInvoice = subscription.UpcomingInvoice != null ? new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null; - Discount = subscription.Discount != null ? new BillingCustomerDiscount(subscription.Discount) : null; + CustomerDiscount = subscription.CustomerDiscount != null ? new BillingCustomerDiscount(subscription.CustomerDiscount) : null; Expiration = DateTime.UtcNow.AddYears(1); // Not used, so just give it a value. if (hideSensitiveData) @@ -143,7 +143,7 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel public string StorageName { get; set; } public double? StorageGb { get; set; } - public BillingCustomerDiscount Discount { get; set; } + public BillingCustomerDiscount CustomerDiscount { get; set; } public BillingSubscription Subscription { get; set; } public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; } diff --git a/src/Api/Models/Response/SubscriptionResponseModel.cs b/src/Api/Models/Response/SubscriptionResponseModel.cs index 553b7dd99..883f7ac90 100644 --- a/src/Api/Models/Response/SubscriptionResponseModel.cs +++ b/src/Api/Models/Response/SubscriptionResponseModel.cs @@ -13,7 +13,6 @@ public class SubscriptionResponseModel : ResponseModel Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null; UpcomingInvoice = subscription.UpcomingInvoice != null ? new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null; - Discount = subscription.Discount != null ? new BillingCustomerDiscount(subscription.Discount) : null; StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null; StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB MaxStorageGb = user.MaxStorageGb; @@ -41,7 +40,6 @@ public class SubscriptionResponseModel : ResponseModel public short? MaxStorageGb { get; set; } public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; } public BillingSubscription Subscription { get; set; } - public BillingCustomerDiscount Discount { get; set; } public UserLicense License { get; set; } public DateTime? Expiration { get; set; } public bool UsingInAppPurchase { get; set; } @@ -53,10 +51,12 @@ public class BillingCustomerDiscount { Id = discount.Id; Active = discount.Active; + PercentOff = discount.PercentOff; } - public string Id { get; set; } - public bool Active { get; set; } + public string Id { get; } + public bool Active { get; } + public decimal? PercentOff { get; } } public class BillingSubscription diff --git a/src/Core/Models/Business/SubscriptionInfo.cs b/src/Core/Models/Business/SubscriptionInfo.cs index f8284e0e3..8a0a6add7 100644 --- a/src/Core/Models/Business/SubscriptionInfo.cs +++ b/src/Core/Models/Business/SubscriptionInfo.cs @@ -4,7 +4,7 @@ namespace Bit.Core.Models.Business; public class SubscriptionInfo { - public BillingCustomerDiscount Discount { get; set; } + public BillingCustomerDiscount CustomerDiscount { get; set; } public BillingSubscription Subscription { get; set; } public BillingUpcomingInvoice UpcomingInvoice { get; set; } public bool UsingInAppPurchase { get; set; } @@ -17,10 +17,12 @@ public class SubscriptionInfo { Id = discount.Id; Active = discount.Start != null && discount.End == null; + PercentOff = discount.Coupon?.PercentOff; } public string Id { get; } public bool Active { get; } + public decimal? PercentOff { get; } } public class BillingSubscription diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index dc6d4dd6f..0f7965db7 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1568,7 +1568,7 @@ public class StripePaymentService : IPaymentService if (customer.Discount != null) { - subscriptionInfo.Discount = new SubscriptionInfo.BillingCustomerDiscount(customer.Discount); + subscriptionInfo.CustomerDiscount = new SubscriptionInfo.BillingCustomerDiscount(customer.Discount); } if (subscriber.IsUser())