2020-06-28 21:44:35 -05:00
|
|
|
using System;
|
2020-06-24 10:34:09 +09:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-10-21 17:43:02 +02:00
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2021-04-13 10:36:49 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
2020-06-24 10:34:09 +09:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
|
|
|
public class PayoutData
|
|
|
|
{
|
|
|
|
[Key]
|
|
|
|
[MaxLength(30)]
|
|
|
|
public string Id { get; set; }
|
|
|
|
public DateTimeOffset Date { get; set; }
|
|
|
|
public string PullPaymentDataId { get; set; }
|
2022-04-24 05:19:34 +02:00
|
|
|
public string StoreDataId { get; set; }
|
2020-06-24 10:34:09 +09:00
|
|
|
public PullPaymentData PullPaymentData { get; set; }
|
|
|
|
[MaxLength(20)]
|
|
|
|
public PayoutState State { get; set; }
|
|
|
|
[MaxLength(20)]
|
|
|
|
[Required]
|
|
|
|
public string PaymentMethodId { get; set; }
|
|
|
|
public byte[] Blob { get; set; }
|
|
|
|
public byte[] Proof { get; set; }
|
2021-10-23 22:10:54 +09:00
|
|
|
#nullable enable
|
2021-10-21 17:43:02 +02:00
|
|
|
public string? Destination { get; set; }
|
2021-10-23 22:10:54 +09:00
|
|
|
#nullable restore
|
2022-04-24 05:19:34 +02:00
|
|
|
public StoreData StoreData { get; set; }
|
2020-12-28 14:57:21 -06:00
|
|
|
|
2020-06-24 10:34:09 +09:00
|
|
|
internal static void OnModelCreating(ModelBuilder builder)
|
|
|
|
{
|
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasOne(o => o.PullPaymentData)
|
|
|
|
.WithMany(o => o.Payouts).OnDelete(DeleteBehavior.Cascade);
|
2022-04-24 05:19:34 +02:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasOne(o => o.StoreData)
|
|
|
|
.WithMany(o => o.Payouts).OnDelete(DeleteBehavior.Cascade);
|
2020-06-24 10:34:09 +09:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.Property(o => o.State)
|
|
|
|
.HasConversion<string>();
|
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasIndex(o => o.State);
|
2021-10-21 17:43:02 +02:00
|
|
|
builder.Entity<PayoutData>()
|
2021-12-31 16:59:02 +09:00
|
|
|
.HasIndex(x => new { DestinationId = x.Destination, x.State });
|
2020-06-24 10:34:09 +09:00
|
|
|
}
|
2020-12-28 14:57:21 -06:00
|
|
|
|
|
|
|
// utility methods
|
|
|
|
public bool IsInPeriod(PullPaymentData pp, DateTimeOffset now)
|
|
|
|
{
|
|
|
|
var period = pp.GetPeriod(now);
|
|
|
|
if (period is { } p)
|
|
|
|
{
|
2022-06-28 16:02:17 +02:00
|
|
|
return p.Start <= Date && (p.End is not { } end || Date < end);
|
2020-12-28 14:57:21 -06:00
|
|
|
}
|
2022-06-28 16:02:17 +02:00
|
|
|
|
|
|
|
return false;
|
2020-12-28 14:57:21 -06:00
|
|
|
}
|
2020-06-24 10:34:09 +09:00
|
|
|
}
|
|
|
|
}
|