mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
Return discount info in Subscription responses [AC-1657] (#3278)
* Return whether customer has Stripe discount applied from /api/accounts/subscription * Return whether customer has Stripe discount applied from /api/organizations/{id}/subscription
This commit is contained in:
parent
12b03482ae
commit
46117b194e
@ -116,6 +116,7 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel
|
|||||||
{
|
{
|
||||||
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
|
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
|
||||||
UpcomingInvoice = subscription.UpcomingInvoice != null ? new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : 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.
|
Expiration = DateTime.UtcNow.AddYears(1); // Not used, so just give it a value.
|
||||||
|
|
||||||
if (hideSensitiveData)
|
if (hideSensitiveData)
|
||||||
@ -146,6 +147,7 @@ public class OrganizationSubscriptionResponseModel : OrganizationResponseModel
|
|||||||
|
|
||||||
public string StorageName { get; set; }
|
public string StorageName { get; set; }
|
||||||
public double? StorageGb { get; set; }
|
public double? StorageGb { get; set; }
|
||||||
|
public BillingCustomerDiscount Discount { get; set; }
|
||||||
public BillingSubscription Subscription { get; set; }
|
public BillingSubscription Subscription { get; set; }
|
||||||
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
|
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ public class SubscriptionResponseModel : ResponseModel
|
|||||||
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
|
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
|
||||||
UpcomingInvoice = subscription.UpcomingInvoice != null ?
|
UpcomingInvoice = subscription.UpcomingInvoice != null ?
|
||||||
new BillingSubscriptionUpcomingInvoice(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;
|
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
|
||||||
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
|
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
|
||||||
MaxStorageGb = user.MaxStorageGb;
|
MaxStorageGb = user.MaxStorageGb;
|
||||||
@ -41,11 +42,24 @@ public class SubscriptionResponseModel : ResponseModel
|
|||||||
public short? MaxStorageGb { get; set; }
|
public short? MaxStorageGb { get; set; }
|
||||||
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
|
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
|
||||||
public BillingSubscription Subscription { get; set; }
|
public BillingSubscription Subscription { get; set; }
|
||||||
|
public BillingCustomerDiscount Discount { get; set; }
|
||||||
public UserLicense License { get; set; }
|
public UserLicense License { get; set; }
|
||||||
public DateTime? Expiration { get; set; }
|
public DateTime? Expiration { get; set; }
|
||||||
public bool UsingInAppPurchase { 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 class BillingSubscription
|
||||||
{
|
{
|
||||||
public BillingSubscription(SubscriptionInfo.BillingSubscription sub)
|
public BillingSubscription(SubscriptionInfo.BillingSubscription sub)
|
||||||
|
@ -5,10 +5,25 @@ namespace Bit.Core.Models.Business;
|
|||||||
|
|
||||||
public class SubscriptionInfo
|
public class SubscriptionInfo
|
||||||
{
|
{
|
||||||
|
public BillingCustomerDiscount Discount { get; set; }
|
||||||
public BillingSubscription Subscription { get; set; }
|
public BillingSubscription Subscription { get; set; }
|
||||||
public BillingUpcomingInvoice UpcomingInvoice { get; set; }
|
public BillingUpcomingInvoice UpcomingInvoice { get; set; }
|
||||||
public bool UsingInAppPurchase { 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 class BillingSubscription
|
||||||
{
|
{
|
||||||
public BillingSubscription(Subscription sub)
|
public BillingSubscription(Subscription sub)
|
||||||
|
@ -1557,11 +1557,20 @@ public class StripePaymentService : IPaymentService
|
|||||||
{
|
{
|
||||||
var subscriptionInfo = new SubscriptionInfo();
|
var subscriptionInfo = new SubscriptionInfo();
|
||||||
|
|
||||||
if (subscriber.IsUser() && !string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
|
if (!string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
|
||||||
{
|
{
|
||||||
var customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
|
var customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
|
||||||
|
|
||||||
|
if (customer.Discount != null)
|
||||||
|
{
|
||||||
|
subscriptionInfo.Discount = new SubscriptionInfo.BillingCustomerDiscount(customer.Discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subscriber.IsUser())
|
||||||
|
{
|
||||||
subscriptionInfo.UsingInAppPurchase = customer.Metadata.ContainsKey("appleReceipt");
|
subscriptionInfo.UsingInAppPurchase = customer.Metadata.ContainsKey("appleReceipt");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))
|
if (!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user