Skip to content

Commit

Permalink
Step 2: Created default subscription, with default provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Jun 13, 2024
1 parent 6ed2bf5 commit b03a851
Show file tree
Hide file tree
Showing 86 changed files with 2,064 additions and 368 deletions.
250 changes: 250 additions & 0 deletions src/Application.Resources.Shared/Subscriptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
using Application.Interfaces.Resources;

namespace Application.Resources.Shared;


public class Subscription : IIdentifiableResource
{
public required string BuyerId { get; set; }

public required string OwningEntityId { get; set; }

public string? ProviderName { get; set; }

public Dictionary<string, string> ProviderState { get; set; } = new();

public required string Id { get; set; }
}

public class SubscriptionForMigration : Subscription
{
#pragma warning disable SAASAPP014
public required Dictionary<string, object> Buyer { get; set; }
#pragma warning restore SAASAPP014
}

public class SubscriptionWithPlan : Subscription
{
public bool CanBeCancelled { get; set; }

public bool CanBeUnsubscribed { get; set; }

public DateTime? CancelledDateUtc { get; set; }

public required InvoiceSummary Invoice { get; set; }

public required SubscriptionPaymentMethod PaymentMethod { get; set; }

public required PlanPeriod Period { get; set; }

public required SubscriptionPlan Plan { get; set; }

public SubscriptionStatus Status { get; set; }

public required string SubscriptionId { get; set; }
}

public class SubscriptionPlan : IIdentifiableResource
{
public bool IsTrial { get; set; }

public SubscriptionTier Tier { get; set; }

public DateTime? TrialEndDateUtc { get; set; }

public required string Id { get; set; }
}

public class PlanPeriod
{
public int Frequency { get; set; }

public PeriodFrequencyUnit Unit { get; set; }
}

public enum PeriodFrequencyUnit
{
Eternity = 0,
Day = 1,
Week = 2,
Month = 3,
Year = 4
}

public enum SubscriptionStatus
{
Unsubscribed = 0,
Activated = 1,
Cancelled = 2,
Cancelling = 3
}

public enum SubscriptionTier
{
Unsubscribed = 0,
Basic = 1,
Premium = 2
}

public class Invoice : IIdentifiableResource
{
public decimal Amount { get; set; } // In the denomination of the Currency

public required string Currency { get; set; } // ISO4217

public bool IncludesTax { get; set; }

public DateTime InvoicedOnUtc { get; set; }

public List<InvoiceLineItem> LineItems { get; set; } = new();

public List<InvoiceNote> Notes { get; set; } = new();

public required InvoiceItemPayment Payment { get; set; }

public DateTime? PeriodEndUtc { get; set; }

public DateTime? PeriodStartUtc { get; set; }

public InvoiceStatus Status { get; set; }

public decimal TaxAmount { get; set; } // In the denomination of the Currency

public required string Id { get; set; }
}

public class InvoiceSummary
{
public decimal Amount { get; set; } // In the denomination of the Currency

public required string Currency { get; set; } // ISO4217

public DateTime? NextUtc { get; set; }
}

public class InvoiceLineItem
{
public decimal Amount { get; set; } // In the denomination of the Currency

public required string Currency { get; set; } // ISO4217

public required string Description { get; set; }

public bool IsTaxed { get; set; }

public required string Reference { get; set; }

public decimal TaxAmount { get; set; } // In the denomination of the Currency
}

public class InvoiceItemPayment
{
public decimal Amount { get; set; } // In the denomination of the Currency

public required string Currency { get; set; } // ISO4217

public DateTime PaidOnUtc { get; set; }

public required string Reference { get; set; }
}

public class InvoiceNote
{
public required string Description { get; set; }
}

public enum InvoiceStatus
{
Unpaid,
Paid
}

public class SubscriptionPaymentMethod
{
public static readonly SubscriptionPaymentMethod None = new()
{
Status = PaymentMethodStatus.Invalid,
Type = PaymentMethodType.None,
ExpiresOn = null
};

public DateOnly? ExpiresOn { get; set; }

public PaymentMethodStatus Status { get; set; }

public PaymentMethodType Type { get; set; }
}

public enum PaymentMethodType
{
None = 0,
Card = 1,
Other = 2
}

public enum PaymentMethodStatus
{
Invalid = 0,
Valid = 1
}

public class PricingPlans
{
public List<PricingPlan> Annually { get; set; } = new();

public List<PricingPlan> Daily { get; set; } = new();

public List<PricingPlan> Eternally { get; set; } = new();

public List<PricingPlan> Monthly { get; set; } = new();

public List<PricingPlan> Weekly { get; set; } = new();
}

public class PricingPlan : IIdentifiableResource
{
public required PlanPeriod Billing { get; set; }

public required string Currency { get; set; } // ISO4217

public required string Description { get; set; }

public required string DisplayName { get; set; }

public List<PricingFeatureSection> FeatureSection { get; set; } = new();

public bool IsRecommended { get; set; }

public required string Notes { get; set; }

public required decimal Cost { get; set; } // In the denomination of the Currency

public required decimal SetupCost { get; set; } // In the denomination of the Currency

public required SubscriptionTrialPeriod Trial { get; set; }

public required string Id { get; set; }
}

public class SubscriptionTrialPeriod
{
public int Frequency { get; set; }

public bool HasTrial { get; set; }

public PeriodFrequencyUnit Unit { get; set; }
}

public class PricingFeatureSection
{
public required string Description { get; set; }

public List<PricingFeatureItem> Features { get; set; } = new();
}

public class PricingFeatureItem
{
public required string Description { get; set; }

public bool IsIncluded { get; set; }
}
20 changes: 17 additions & 3 deletions src/Application.Services.Shared/IBillingGatewayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ public interface IBillingGatewayService
/// Creates a new subscription the specified <see cref="buyer" />
/// </summary>
Task<Result<BillingProviderState, Error>> SubscribeAsync(ICallerContext caller, SubscriptionBuyer buyer,
SubscribeOptions options);
SubscribeOptions options, CancellationToken cancellationToken);
}

/// <summary>
/// Maintains the internal state for the billing provider
/// </summary>
public class BillingProviderState : Dictionary<string, string>
{
public BillingProviderState()
{
}

public BillingProviderState(Dictionary<string, string> properties) : base(properties)
{
}
}

/// <summary>
Expand Down Expand Up @@ -54,14 +68,14 @@ public class SubscriptionBuyer
{
public required ProfileAddress Address { get; set; }

public required BuyerOrganization Organization { get; set; }

public required string EmailAddress { get; set; }

public required string Id { get; set; }

public required PersonName Name { get; set; }

public required BuyerOrganization Organization { get; set; }

public string? PhoneNumber { get; set; }
}

Expand Down
10 changes: 6 additions & 4 deletions src/Application.Services.Shared/IBillingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Domain.Services.Shared;

namespace Application.Services.Shared;

/// <summary>
Expand All @@ -6,14 +8,14 @@ namespace Application.Services.Shared;
public interface IBillingProvider
{
/// <summary>
/// returns the name of the provider
/// Returns the gateway service for the provider
/// </summary>
string ProviderName { get; }
public IBillingGatewayService GatewayService { get; }

/// <summary>
/// Returns the gateway service for the provider
/// returns the name of the provider
/// </summary>
public IBillingGatewayService GatewayService { get; }
string ProviderName { get; }

/// <summary>
/// Returns the proxy to manage state changes to the provider
Expand Down
Loading

0 comments on commit b03a851

Please sign in to comment.