mirror of
https://github.com/bitwarden/server
synced 2026-01-30 16:23:37 +00:00
* feat(get-subscription): Add EnumMemberJsonConverter * feat(get-subscription): Add BitwardenDiscount model * feat(get-subscription): Add Cart model * feat(get-subscription): Add Storage model * feat(get-subscription): Add BitwardenSubscription model * feat(get-subscription): Add DiscountExtensions * feat(get-subscription): Add error code to StripeConstants * feat(get-subscription): Add GetBitwardenSubscriptionQuery * feat(get-subscription): Expose GET /account/billing/vnext/subscription * feat(reinstate-subscription): Add ReinstateSubscriptionCommand * feat(reinstate-subscription): Expose POST /account/billing/vnext/subscription/reinstate * feat(pay-with-paypal-immediately): Add SubscriberId union * feat(pay-with-paypal-immediately): Add BraintreeService with PayInvoice method * feat(pay-with-paypal-immediately): Pay PayPal invoice immediately when starting premium subscription * feat(pay-with-paypal-immediately): Pay invoice with Braintree on invoice.created for subscription cycles only * fix(update-storage): Always invoice for premium storage update * fix(update-storage): Move endpoint to subscription path * docs: Note FF removal POIs * (format): Run dotnet format
62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System.Runtime.Serialization;
|
|
using System.Text.Json.Serialization;
|
|
using Bit.Core.Utilities;
|
|
using Stripe;
|
|
|
|
namespace Bit.Core.Billing.Subscriptions.Models;
|
|
|
|
/// <summary>
|
|
/// The type of discounts Bitwarden supports.
|
|
/// </summary>
|
|
public enum BitwardenDiscountType
|
|
{
|
|
[EnumMember(Value = "amount-off")]
|
|
AmountOff,
|
|
|
|
[EnumMember(Value = "percent-off")]
|
|
PercentOff
|
|
}
|
|
|
|
/// <summary>
|
|
/// A record representing a discount applied to a Bitwarden subscription.
|
|
/// </summary>
|
|
public record BitwardenDiscount
|
|
{
|
|
/// <summary>
|
|
/// The type of the discount.
|
|
/// </summary>
|
|
[JsonConverter(typeof(EnumMemberJsonConverter<BitwardenDiscountType>))]
|
|
public required BitwardenDiscountType Type { get; init; }
|
|
|
|
/// <summary>
|
|
/// The value of the discount.
|
|
/// </summary>
|
|
public required decimal Value { get; init; }
|
|
|
|
public static implicit operator BitwardenDiscount(Discount? discount)
|
|
{
|
|
if (discount is not
|
|
{
|
|
Coupon.Valid: true
|
|
})
|
|
{
|
|
return null!;
|
|
}
|
|
|
|
return discount.Coupon switch
|
|
{
|
|
{ AmountOff: > 0 } => new BitwardenDiscount
|
|
{
|
|
Type = BitwardenDiscountType.AmountOff,
|
|
Value = discount.Coupon.AmountOff.Value
|
|
},
|
|
{ PercentOff: > 0 } => new BitwardenDiscount
|
|
{
|
|
Type = BitwardenDiscountType.PercentOff,
|
|
Value = discount.Coupon.PercentOff.Value
|
|
},
|
|
_ => null!
|
|
};
|
|
}
|
|
}
|