diff --git a/src/Api/Models/Response/Organizations/OrganizationResponseModel.cs b/src/Api/Models/Response/Organizations/OrganizationResponseModel.cs index 11f5a795a..f04c28c5e 100644 --- a/src/Api/Models/Response/Organizations/OrganizationResponseModel.cs +++ b/src/Api/Models/Response/Organizations/OrganizationResponseModel.cs @@ -116,6 +116,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; Expiration = DateTime.UtcNow.AddYears(1); // Not used, so just give it a value. if (hideSensitiveData) @@ -146,6 +147,7 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel public string StorageName { get; set; } public double? StorageGb { get; set; } + public BillingCustomerDiscount Discount { 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 4c0ee9338..042da2e9e 100644 --- a/src/Api/Models/Response/SubscriptionResponseModel.cs +++ b/src/Api/Models/Response/SubscriptionResponseModel.cs @@ -14,6 +14,7 @@ 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,11 +42,24 @@ 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; } } +public class BillingCustomerDiscount +{ + public BillingCustomerDiscount(SubscriptionInfo.BillingCustomerDiscount discount) + { + Id = discount.Id; + Active = discount.Active; + } + + public string Id { get; set; } + public bool Active { get; set; } +} + public class BillingSubscription { public BillingSubscription(SubscriptionInfo.BillingSubscription sub) diff --git a/src/Core/Models/Business/SubscriptionInfo.cs b/src/Core/Models/Business/SubscriptionInfo.cs index c72e291de..87fe3157c 100644 --- a/src/Core/Models/Business/SubscriptionInfo.cs +++ b/src/Core/Models/Business/SubscriptionInfo.cs @@ -5,10 +5,25 @@ namespace Bit.Core.Models.Business; public class SubscriptionInfo { + public BillingCustomerDiscount Discount { get; set; } public BillingSubscription Subscription { get; set; } public BillingUpcomingInvoice UpcomingInvoice { get; set; } public bool UsingInAppPurchase { get; set; } + public class BillingCustomerDiscount + { + public BillingCustomerDiscount() { } + + public BillingCustomerDiscount(Discount discount) + { + Id = discount.Id; + Active = discount.Start != null && discount.End == null; + } + + public string Id { get; } + public bool Active { get; } + } + public class BillingSubscription { public BillingSubscription(Subscription sub) diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 4d2eb4ef8..33610bee7 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1557,10 +1557,19 @@ public class StripePaymentService : IPaymentService { var subscriptionInfo = new SubscriptionInfo(); - if (subscriber.IsUser() && !string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId)) + if (!string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId)) { var customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId); - subscriptionInfo.UsingInAppPurchase = customer.Metadata.ContainsKey("appleReceipt"); + + if (customer.Discount != null) + { + subscriptionInfo.Discount = new SubscriptionInfo.BillingCustomerDiscount(customer.Discount); + } + + if (subscriber.IsUser()) + { + subscriptionInfo.UsingInAppPurchase = customer.Metadata.ContainsKey("appleReceipt"); + } } if (!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))