btcpayserver/BTCPayServer/Models/ViewPullPaymentModel.cs

113 lines
3.9 KiB
C#
Raw Normal View History

2020-06-28 21:44:35 -05:00
using System;
2020-06-24 10:34:09 +09:00
using System.Collections.Generic;
using System.Linq;
2021-12-31 16:59:02 +09:00
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Client.Models;
2020-06-24 10:34:09 +09:00
using BTCPayServer.Data;
using BTCPayServer.Payments;
using BTCPayServer.Payouts;
2020-06-24 10:34:09 +09:00
using BTCPayServer.Services.Rates;
using PullPaymentData = BTCPayServer.Data.PullPaymentData;
2020-06-24 10:34:09 +09:00
namespace BTCPayServer.Models
{
public class ViewPullPaymentModel
{
public ViewPullPaymentModel()
{
}
public ViewPullPaymentModel(PullPaymentData data, DateTimeOffset now)
{
Id = data.Id;
StoreId = data.StoreId;
2020-06-24 10:34:09 +09:00
var blob = data.GetBlob();
PayoutMethodIds = blob.SupportedPaymentMethods;
BitcoinOnly = blob.SupportedPaymentMethods.All(p => p == PayoutTypes.CHAIN.GetPayoutMethodId("BTC") || p == PayoutTypes.LN.GetPayoutMethodId("BTC"));
SelectedPayoutMethod = PayoutMethodIds.First().ToString();
2020-06-24 10:34:09 +09:00
Archived = data.Archived;
AutoApprove = blob.AutoApproveClaims;
2020-06-24 10:34:09 +09:00
Title = blob.View.Title;
Description = blob.View.Description;
2020-06-24 10:34:09 +09:00
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;
IsPending = !data.IsExpired(now);
2020-06-24 10:34:09 +09:00
if (data.Archived)
{
Status = "Archived";
}
else if (data.IsExpired(now))
2020-06-24 10:34:09 +09:00
{
Status = "Expired";
}
else if (!data.HasStarted(now))
2020-06-24 10:34:09 +09:00
{
Status = "Not yet started";
}
else
{
Status = string.Empty;
}
EndsIn = string.Empty;
if (data.EndsIn(now) is TimeSpan e)
2020-06-24 10:34:09 +09:00
{
EndsIn = e.TimeString();
2020-06-24 10:34:09 +09:00
}
}
public bool BitcoinOnly { get; set; }
public string StoreId { get; set; }
public string SelectedPayoutMethod { get; set; }
public PayoutMethodId[] PayoutMethodIds { get; set; }
public string SetupDeepLink { get; set; }
public string ResetDeepLink { get; set; }
2020-06-24 10:34:09 +09:00
public string HubPath { get; set; }
public string EndsIn { get; set; }
2020-06-24 10:34:09 +09:00
public string Email { get; set; }
public string Status { get; set; }
public bool IsPending { get; set; }
public decimal AmountCollected { get; set; }
public decimal AmountDue { get; set; }
public decimal ClaimedAmount { get; set; }
public decimal MinimumClaim { get; set; }
public string Destination { get; set; }
public decimal Amount { get; set; }
public string Id { get; set; }
public string Currency { get; set; }
public DateTime? ExpiryDate { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public List<PayoutLine> Payouts { get; set; } = new();
public DateTimeOffset StartDate { get; set; }
public DateTime LastRefreshed { get; set; }
2020-06-24 10:34:09 +09:00
public CurrencyData CurrencyData { get; set; }
public Uri LnurlEndpoint { get; set; }
public StoreBrandingViewModel StoreBranding { get; set; }
2020-06-24 10:34:09 +09:00
public bool Archived { get; set; }
public bool AutoApprove { get; set; }
2020-06-24 10:34:09 +09:00
public class PayoutLine
{
public string Id { get; set; }
public decimal Amount { get; set; }
public string AmountFormatted { get; set; }
public PayoutState Status { get; set; }
2020-06-24 10:34:09 +09:00
public string Destination { get; set; }
public string Currency { get; set; }
public string Link { get; set; }
public string TransactionId { get; set; }
public PaymentMethodId PaymentMethod { get; set; }
2020-06-24 10:34:09 +09:00
}
}
}