mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
[feat] Allow CS to perform bulk actions on Stripe subscriptions from the Admin portal (#2116)
* [feat] Allow CS to perform bulk actions on Stripe subscriptions from the Admin portal * [fix] An unrelated lint error
This commit is contained in:
41
src/Core/Models/Stripe/StripeSubscriptionListOptions.cs
Normal file
41
src/Core/Models/Stripe/StripeSubscriptionListOptions.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace Bit.Core.Models.BitStripe
|
||||
{
|
||||
// Stripe's SubscriptionListOptions model has a complex input for date filters.
|
||||
// It expects a dictionary, and has lots of validation rules around what can have a value and what can't.
|
||||
// To simplify this a bit we are extending Stripe's model and using our own date inputs, and building the dictionary they expect JiT.
|
||||
// ___
|
||||
// Our model also facilitates selecting all elements in a list, which is unsupported by Stripe's model.
|
||||
public class StripeSubscriptionListOptions : Stripe.SubscriptionListOptions
|
||||
{
|
||||
public DateTime? CurrentPeriodEndDate { get; set; }
|
||||
public string CurrentPeriodEndRange { get; set; } = "lt";
|
||||
public bool SelectAll { get; set; }
|
||||
public new Stripe.DateRangeOptions CurrentPeriodEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
return CurrentPeriodEndDate.HasValue ?
|
||||
new Stripe.DateRangeOptions()
|
||||
{
|
||||
LessThan = CurrentPeriodEndRange == "lt" ? CurrentPeriodEndDate : null,
|
||||
GreaterThan = CurrentPeriodEndRange == "gt" ? CurrentPeriodEndDate : null
|
||||
} :
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
||||
public Stripe.SubscriptionListOptions ToStripeApiOptions()
|
||||
{
|
||||
var stripeApiOptions = (Stripe.SubscriptionListOptions)this;
|
||||
if (CurrentPeriodEndDate.HasValue)
|
||||
{
|
||||
stripeApiOptions.CurrentPeriodEnd = new Stripe.DateRangeOptions()
|
||||
{
|
||||
LessThan = CurrentPeriodEndRange == "lt" ? CurrentPeriodEndDate : null,
|
||||
GreaterThan = CurrentPeriodEndRange == "gt" ? CurrentPeriodEndDate : null
|
||||
};
|
||||
}
|
||||
return stripeApiOptions;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user