feat: add resource quotas, PayPal subscriptions and paid disk allowances

Calculate and enforce configurable resource consumption, expose balances in PostIt and document the rule in CGU. Add confirmed monthly PayPal credits and disk quotas of twice the free default for Discovery and five times for Premium, with payment reconciliation, migrations and regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-08 05:02:23 +00:00
commit 650e5f5e30
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
69 changed files with 19111 additions and 203 deletions

View file

@ -96,6 +96,21 @@ namespace Yavsc.Models
entity.HasIndex(r => new { r.UserId, r.RecordedAtUtc });
entity.Property(r => r.Currency).HasMaxLength(8).HasDefaultValue(Constants.ResourceUsageDefaultCurrency);
entity.Property(r => r.UserName).HasMaxLength(256);
entity.Property(r => r.CreditPoints).HasPrecision(28, 8).HasDefaultValue(0m);
});
builder.Entity<ResourceSubscription>(entity =>
{
entity.HasIndex(s => s.PayPalId).IsUnique();
entity.HasIndex(s => s.UserId);
entity.HasOne<ApplicationUser>().WithMany().HasForeignKey(s => s.UserId).OnDelete(DeleteBehavior.Restrict);
entity.Property(s => s.MonthlyPoints).HasPrecision(28, 8);
});
builder.Entity<ResourceSubscriptionPayment>(entity =>
{
entity.HasIndex(p => new { p.SubscriptionId, p.Cycle }).IsUnique();
entity.HasOne<ResourceSubscription>().WithMany().HasForeignKey(p => p.SubscriptionId).OnDelete(DeleteBehavior.Restrict);
entity.Property(p => p.GrantedPoints).HasPrecision(28, 8);
});
// Customize the ASP.NET Identity model and override the defaults if needed.
@ -365,6 +380,8 @@ namespace Yavsc.Models
public DbSet<Estimate> Estimates { get; set; }
public DbSet<Signature> Signatures { get; set; }
public DbSet<ResourceUsageRecord> ResourceUsageRecords { get; set; }
public DbSet<ResourceSubscription> ResourceSubscriptions { get; set; }
public DbSet<ResourceSubscriptionPayment> ResourceSubscriptionPayments { get; set; }
public DbSet<AccountBalance> BankStatus { get; set; }
public DbSet<BalanceImpact> BalanceImpact { get; set; }

View file

@ -93,7 +93,16 @@ namespace Yavsc.Models
public virtual List<BankIdentity>? BankInfo { get; set; }
public long DiskQuota { get; set; } = 512 * 1024 * 1024;
public long DiskQuota { get; set; } = Constants.DefaultFSQ;
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public DateTimeOffset? PremiumDiskQuotaUntil { get; set; }
[JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public DateTimeOffset? DiscoveryDiskQuotaUntil { get; set; }
public long GetEffectiveDiskQuota(DateTimeOffset now)
=> PremiumDiskQuotaUntil > now ? checked(Constants.DefaultFSQ * 5L)
: DiscoveryDiskQuotaUntil > now ? checked(Constants.DefaultFSQ * 2L) : DiskQuota;
public long DiskUsage { get; set; } = 0;
public long MaxFileSize { get; set; } = 512 * 1024 * 1024;

View file

@ -0,0 +1,41 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Yavsc.Models.Payment;
public sealed class ResourceSubscription
{
public Guid Id { get; set; }
[MaxLength(450)]
public string UserId { get; set; } = "";
[MaxLength(32)]
public string Pack { get; set; } = "";
[MaxLength(64)]
public string PlanId { get; set; } = "";
[MaxLength(64)]
public string? PayPalId { get; set; }
[MaxLength(32)]
public string State { get; set; } = "CREATING";
public decimal MonthlyPoints { get; set; }
[Column(TypeName = "numeric(18,2)")]
public decimal PriceExcludingTax { get; set; }
public decimal VatPercent { get; set; }
[Column(TypeName = "numeric(18,2)")]
public decimal PriceIncludingTax { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset? StartsAt { get; set; }
public DateTimeOffset? NextBillingAt { get; set; }
public int LastCreditedCycle { get; set; } = -1;
}
public sealed class ResourceSubscriptionPayment
{
[MaxLength(64)]
public string Id { get; set; } = "";
public Guid SubscriptionId { get; set; }
public int Cycle { get; set; }
public DateTimeOffset PaidAt { get; set; }
public decimal GrantedPoints { get; set; }
public bool Reversed { get; set; }
}

View file

@ -23,6 +23,7 @@ public sealed class ResourceUsageRecord : ITrackedEntity
public decimal CpuSeconds { get; set; }
public decimal BandwidthMb { get; set; }
public decimal StorageMb { get; set; }
public decimal CreditPoints { get; set; }
public decimal EstimatedCompensation { get; set; }
[Required]