2022-06-29 19:46:41 -04:00
|
|
|
|
using Stripe;
|
2019-02-18 15:40:47 -05:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
namespace Bit.Core.Models.Business
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class SubscriptionInfo
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingSubscription Subscription { get; set; }
|
|
|
|
|
|
public BillingUpcomingInvoice UpcomingInvoice { get; set; }
|
|
|
|
|
|
public bool UsingInAppPurchase { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public class BillingSubscription
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingSubscription(Subscription sub)
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
Status = sub.Status;
|
|
|
|
|
|
TrialStartDate = sub.TrialStart;
|
|
|
|
|
|
TrialEndDate = sub.TrialEnd;
|
|
|
|
|
|
PeriodStartDate = sub.CurrentPeriodStart;
|
|
|
|
|
|
PeriodEndDate = sub.CurrentPeriodEnd;
|
|
|
|
|
|
CancelledDate = sub.CanceledAt;
|
|
|
|
|
|
CancelAtEndDate = sub.CancelAtPeriodEnd;
|
|
|
|
|
|
Cancelled = sub.Status == "canceled" || sub.Status == "unpaid" || sub.Status == "incomplete_expired";
|
|
|
|
|
|
if (sub.Items?.Data != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Items = sub.Items.Data.Select(i => new BillingSubscriptionItem(i));
|
|
|
|
|
|
}
|
2019-02-18 15:40:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public DateTime? TrialStartDate { get; set; }
|
|
|
|
|
|
public DateTime? TrialEndDate { get; set; }
|
|
|
|
|
|
public DateTime? PeriodStartDate { get; set; }
|
|
|
|
|
|
public DateTime? PeriodEndDate { get; set; }
|
|
|
|
|
|
public TimeSpan? PeriodDuration => PeriodEndDate - PeriodStartDate;
|
|
|
|
|
|
public DateTime? CancelledDate { get; set; }
|
|
|
|
|
|
public bool CancelAtEndDate { get; set; }
|
|
|
|
|
|
public string Status { get; set; }
|
|
|
|
|
|
public bool Cancelled { get; set; }
|
|
|
|
|
|
public IEnumerable<BillingSubscriptionItem> Items { get; set; } = new List<BillingSubscriptionItem>();
|
2019-02-18 15:40:47 -05:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class BillingSubscriptionItem
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingSubscriptionItem(SubscriptionItem item)
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
if (item.Plan != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = item.Plan.Nickname;
|
|
|
|
|
|
Amount = item.Plan.Amount.GetValueOrDefault() / 100M;
|
|
|
|
|
|
Interval = item.Plan.Interval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Quantity = (int)item.Quantity;
|
|
|
|
|
|
SponsoredSubscriptionItem = Utilities.StaticStore.SponsoredPlans.Any(p => p.StripePlanId == item.Plan.Id);
|
2019-02-18 15:40:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
public decimal Amount { get; set; }
|
|
|
|
|
|
public int Quantity { get; set; }
|
|
|
|
|
|
public string Interval { get; set; }
|
|
|
|
|
|
public bool SponsoredSubscriptionItem { get; set; }
|
2019-02-18 15:40:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class BillingUpcomingInvoice
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingUpcomingInvoice() { }
|
2019-02-18 15:40:47 -05:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingUpcomingInvoice(Invoice inv)
|
2019-02-18 15:40:47 -05:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
Amount = inv.AmountDue / 100M;
|
|
|
|
|
|
Date = inv.Created;
|
2019-02-18 15:40:47 -05:00
|
|
|
|
}
|
2022-08-29 14:53:16 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public BillingUpcomingInvoice(Braintree.Subscription sub)
|
|
|
|
|
|
{
|
|
|
|
|
|
Amount = sub.NextBillAmount.GetValueOrDefault() + sub.Balance.GetValueOrDefault();
|
|
|
|
|
|
if (Amount < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Amount = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
Date = sub.NextBillingDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public decimal Amount { get; set; }
|
|
|
|
|
|
public DateTime? Date { get; set; }
|
|
|
|
|
|
}
|
2019-02-18 15:40:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|