protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); // some of the data models don't have OnModelCreating for now, commenting them AddressInvoiceData.OnModelCreating(builder); APIKeyData.OnModelCreating(builder); AppData.OnModelCreating(builder); //StoredFile.OnModelCreating(builder); HistoricalAddressInvoiceData.OnModelCreating(builder); InvoiceEventData.OnModelCreating(builder); InvoiceSearchData.OnModelCreating(builder); InvoiceWebhookDeliveryData.OnModelCreating(builder); InvoiceData.OnModelCreating(builder); NotificationData.OnModelCreating(builder); //OffchainTransactionData.OnModelCreating(builder); Data.PairedSINData.OnModelCreating(builder); PairingCodeData.OnModelCreating(builder); //PayjoinLock.OnModelCreating(builder); PaymentRequestData.OnModelCreating(builder); PaymentData.OnModelCreating(builder); PayoutData.OnModelCreating(builder); PendingInvoiceData.OnModelCreating(builder); //PlannedTransaction.OnModelCreating(builder); PullPaymentData.OnModelCreating(builder); RefundData.OnModelCreating(builder); //SettingData.OnModelCreating(builder); StoreWebhookData.OnModelCreating(builder); //StoreData.OnModelCreating(builder); U2FDevice.OnModelCreating(builder); Fido2Credential.OnModelCreating(builder); Data.UserStore.OnModelCreating(builder); //WalletData.OnModelCreating(builder); WalletTransactionData.OnModelCreating(builder); WebhookDeliveryData.OnModelCreating(builder); //WebhookData.OnModelCreating(builder); if (Database.IsSqlite() && !_designTime) { // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations // here: https://docs.microsoft.com/en-us/ef/core/providers/sqlite/limitations#query-limitations // To work around this, when the Sqlite database provider is used, all model properties of type DateTimeOffset // use the DateTimeOffsetToBinaryConverter // Based on: https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754 // This only supports millisecond precision, but should be sufficient for most use cases. foreach (var entityType in builder.Model.GetEntityTypes()) { var properties = entityType.ClrType.GetProperties().Where(p => p.PropertyType == typeof(DateTimeOffset)); foreach (var property in properties) { builder .Entity(entityType.Name) .Property(property.Name) .HasConversion(new Microsoft.EntityFrameworkCore.Storage.ValueConversion.DateTimeOffsetToBinaryConverter()); } } } }
public bool IsInPeriod(PullPaymentData pp, DateTimeOffset now) { var period = pp.GetPeriod(now); if (period is { } p) { return(p.Start <= Date && (p.End is DateTimeOffset end ? Date < end : true)); }
public ViewPullPaymentModel(PullPaymentData data, DateTimeOffset now) { Id = data.Id; StoreId = data.StoreId; var blob = data.GetBlob(); PaymentMethods = blob.SupportedPaymentMethods; SelectedPaymentMethod = PaymentMethods.First().ToString(); Archived = data.Archived; AutoApprove = blob.AutoApproveClaims; Title = blob.View.Title; Description = blob.View.Description; Amount = blob.Limit; Currency = blob.Currency; Description = blob.View.Description; ExpiryDate = data.EndDate is DateTimeOffset dt ? (DateTime?)dt.UtcDateTime : null; Email = blob.View.Email; MinimumClaim = blob.MinimumClaim; EmbeddedCSS = blob.View.EmbeddedCSS; CustomCSSLink = blob.View.CustomCSSLink; if (!string.IsNullOrEmpty(EmbeddedCSS)) { EmbeddedCSS = $"<style>{EmbeddedCSS}</style>"; } IsPending = !data.IsExpired(); var period = data.GetPeriod(now); if (data.Archived) { Status = "Archived"; } else if (data.IsExpired()) { Status = "Expired"; } else if (period is null) { Status = "Not yet started"; } else { Status = string.Empty; } ResetIn = string.Empty; if (period?.End is DateTimeOffset pe) { var resetIn = (pe - DateTimeOffset.UtcNow); if (resetIn < TimeSpan.Zero) { resetIn = TimeSpan.Zero; } ResetIn = resetIn.TimeString(); } }
public static IQueryable <PayoutData> GetPayoutInPeriod(this IQueryable <PayoutData> payouts, PullPaymentData pp, DateTimeOffset now) { var request = payouts.Where(p => p.PullPaymentDataId == pp.Id); var period = pp.GetPeriod(now); if (period is { } p) { var start = p.Start; if (p.End is DateTimeOffset end) { return(request.Where(p => p.Date >= start && p.Date < end)); } else { return(request.Where(p => p.Date >= start)); } }
public static IQueryable <PayoutData> GetPayoutInPeriod(this IQueryable <PayoutData> payouts, PullPaymentData pp) { return(GetPayoutInPeriod(payouts, pp, DateTimeOffset.UtcNow)); }
public static bool IsSupported(this PullPaymentData data, BTCPayServer.Payments.PaymentMethodId paymentId) { return(data.GetBlob().SupportedPaymentMethods.Contains(paymentId)); }
public static void SetBlob(this PullPaymentData data, PullPaymentBlob blob) { data.Blob = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(blob)); }
public static PullPaymentBlob GetBlob(this PullPaymentData data) { return(JsonConvert.DeserializeObject <PullPaymentBlob>(Encoding.UTF8.GetString(data.Blob))); }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); NotificationData.OnModelCreating(builder); builder.Entity <InvoiceData>() .HasOne(o => o.StoreData) .WithMany(a => a.Invoices).OnDelete(DeleteBehavior.Cascade); builder.Entity <InvoiceData>().HasIndex(o => o.StoreDataId); builder.Entity <PaymentData>() .HasOne(o => o.InvoiceData) .WithMany(i => i.Payments).OnDelete(DeleteBehavior.Cascade); builder.Entity <PaymentData>() .HasIndex(o => o.InvoiceDataId); builder.Entity <RefundAddressesData>() .HasOne(o => o.InvoiceData) .WithMany(i => i.RefundAddresses).OnDelete(DeleteBehavior.Cascade); builder.Entity <RefundAddressesData>() .HasIndex(o => o.InvoiceDataId); builder.Entity <UserStore>() .HasOne(o => o.StoreData) .WithMany(i => i.UserStores).OnDelete(DeleteBehavior.Cascade); builder.Entity <UserStore>() .HasKey(t => new { t.ApplicationUserId, t.StoreDataId }); builder.Entity <APIKeyData>() .HasOne(o => o.StoreData) .WithMany(i => i.APIKeys) .HasForeignKey(i => i.StoreId).OnDelete(DeleteBehavior.Cascade); builder.Entity <APIKeyData>() .HasOne(o => o.User) .WithMany(i => i.APIKeys) .HasForeignKey(i => i.UserId).OnDelete(DeleteBehavior.Cascade); builder.Entity <APIKeyData>() .HasIndex(o => o.StoreId); builder.Entity <AppData>() .HasOne(o => o.StoreData) .WithMany(i => i.Apps).OnDelete(DeleteBehavior.Cascade); builder.Entity <AppData>() .HasOne(a => a.StoreData); builder.Entity <UserStore>() .HasOne(pt => pt.ApplicationUser) .WithMany(p => p.UserStores) .HasForeignKey(pt => pt.ApplicationUserId); builder.Entity <UserStore>() .HasOne(pt => pt.StoreData) .WithMany(t => t.UserStores) .HasForeignKey(pt => pt.StoreDataId); builder.Entity <AddressInvoiceData>() .HasOne(o => o.InvoiceData) .WithMany(i => i.AddressInvoices).OnDelete(DeleteBehavior.Cascade); builder.Entity <AddressInvoiceData>() #pragma warning disable CS0618 .HasKey(o => o.Address); #pragma warning restore CS0618 builder.Entity <PairingCodeData>() .HasKey(o => o.Id); builder.Entity <PendingInvoiceData>() .HasOne(o => o.InvoiceData) .WithMany(o => o.PendingInvoices) .HasForeignKey(o => o.Id).OnDelete(DeleteBehavior.Cascade); builder.Entity <PairedSINData>() .HasOne(o => o.StoreData) .WithMany(i => i.PairedSINs).OnDelete(DeleteBehavior.Cascade); builder.Entity <PairedSINData>(b => { b.HasIndex(o => o.SIN); b.HasIndex(o => o.StoreDataId); }); builder.Entity <HistoricalAddressInvoiceData>() .HasOne(o => o.InvoiceData) .WithMany(i => i.HistoricalAddressInvoices).OnDelete(DeleteBehavior.Cascade); builder.Entity <HistoricalAddressInvoiceData>() .HasKey(o => new { o.InvoiceDataId, #pragma warning disable CS0618 o.Address #pragma warning restore CS0618 }); builder.Entity <InvoiceEventData>() .HasOne(o => o.InvoiceData) .WithMany(i => i.Events).OnDelete(DeleteBehavior.Cascade); builder.Entity <InvoiceEventData>() .HasKey(o => new { o.InvoiceDataId, #pragma warning disable CS0618 o.UniqueId #pragma warning restore CS0618 }); builder.Entity <PaymentRequestData>() .HasOne(o => o.StoreData) .WithMany(i => i.PaymentRequests) .OnDelete(DeleteBehavior.Cascade); builder.Entity <PaymentRequestData>() .Property(e => e.Created) .HasDefaultValue(new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)); builder.Entity <PaymentRequestData>() .HasIndex(o => o.Status); builder.Entity <WalletTransactionData>() .HasKey(o => new { o.WalletDataId, #pragma warning disable CS0618 o.TransactionId #pragma warning restore CS0618 }); builder.Entity <WalletTransactionData>() .HasOne(o => o.WalletData) .WithMany(w => w.WalletTransactions).OnDelete(DeleteBehavior.Cascade); PullPaymentData.OnModelCreating(builder); PayoutData.OnModelCreating(builder); if (Database.IsSqlite() && !_designTime) { // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations // here: https://docs.microsoft.com/en-us/ef/core/providers/sqlite/limitations#query-limitations // To work around this, when the Sqlite database provider is used, all model properties of type DateTimeOffset // use the DateTimeOffsetToBinaryConverter // Based on: https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754 // This only supports millisecond precision, but should be sufficient for most use cases. foreach (var entityType in builder.Model.GetEntityTypes()) { var properties = entityType.ClrType.GetProperties().Where(p => p.PropertyType == typeof(DateTimeOffset)); foreach (var property in properties) { builder .Entity(entityType.Name) .Property(property.Name) .HasConversion(new Microsoft.EntityFrameworkCore.Storage.ValueConversion.DateTimeOffsetToBinaryConverter()); } } } }