mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-04 18:06:08 +01:00
parent
6a4d8f7404
commit
5b96ab89fd
5 changed files with 41 additions and 29 deletions
|
@ -448,15 +448,14 @@ namespace BTCPayServer.Controllers
|
|||
ApplicationDbContext ctx, string[] payoutIds,
|
||||
string storeId, CancellationToken cancellationToken)
|
||||
{
|
||||
var payouts = (await ctx.Payouts
|
||||
.Include(p => p.PullPaymentData)
|
||||
.Include(p => p.StoreData)
|
||||
.Where(p => payoutIds.Contains(p.Id))
|
||||
.Where(p => p.StoreDataId == storeId && (p.PullPaymentDataId == null || !p.PullPaymentData.Archived))
|
||||
.ToListAsync(cancellationToken))
|
||||
.Where(p => p.GetPaymentMethodId() == paymentMethodId)
|
||||
.ToList();
|
||||
return payouts;
|
||||
return await PullPaymentHostedService.GetPayouts(new PullPaymentHostedService.PayoutQuery()
|
||||
{
|
||||
IncludeArchived = false,
|
||||
IncludeStoreData = true,
|
||||
Stores = new[] {storeId},
|
||||
PayoutIds = payoutIds,
|
||||
PaymentMethods = new[] {paymentMethodId.ToString()}
|
||||
}, ctx, cancellationToken);
|
||||
}
|
||||
|
||||
[HttpGet("stores/{storeId}/pull-payments/{pullPaymentId}/payouts")]
|
||||
|
|
|
@ -202,12 +202,10 @@ public class BitcoinLikePayoutHandler : IPayoutHandler
|
|||
case "mark-paid":
|
||||
await using (var context = _dbContextFactory.CreateContext())
|
||||
{
|
||||
var payouts = (await context.Payouts
|
||||
.Include(p => p.PullPaymentData)
|
||||
.Include(p => p.PullPaymentData.StoreData)
|
||||
.Where(p => payoutIds.Contains(p.Id))
|
||||
.Where(p => p.PullPaymentData.StoreId == storeId && !p.PullPaymentData.Archived && p.State == PayoutState.AwaitingPayment)
|
||||
.ToListAsync()).Where(data =>
|
||||
var payouts = (await PullPaymentHostedService.GetPayouts(new PullPaymentHostedService.PayoutQuery()
|
||||
{
|
||||
States = new[] {PayoutState.AwaitingPayment}, Stores = new[] {storeId}, PayoutIds = payoutIds
|
||||
}, context)).Where(data =>
|
||||
PaymentMethodId.TryParse(data.PaymentMethodId, out var paymentMethodId) &&
|
||||
CanHandle(paymentMethodId))
|
||||
.Select(data => (data, ParseProof(data) as PayoutTransactionOnChainBlob)).Where(tuple => tuple.Item2 != null && tuple.Item2.TransactionId != null && tuple.Item2.Accounted == false);
|
||||
|
@ -217,24 +215,20 @@ public class BitcoinLikePayoutHandler : IPayoutHandler
|
|||
valueTuple.data.State = PayoutState.InProgress;
|
||||
SetProofBlob(valueTuple.data, valueTuple.Item2);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return new StatusMessageModel()
|
||||
{
|
||||
Message = "Payout payments have been marked confirmed",
|
||||
Severity = StatusMessageModel.StatusSeverity.Success
|
||||
};
|
||||
case "reject-payment":
|
||||
await using (var context = _dbContextFactory.CreateContext())
|
||||
await using (var context = _dbContextFactory.CreateContext())
|
||||
{
|
||||
var payouts = (await context.Payouts
|
||||
.Include(p => p.PullPaymentData)
|
||||
.Include(p => p.PullPaymentData.StoreData)
|
||||
.Where(p => payoutIds.Contains(p.Id))
|
||||
.Where(p => p.PullPaymentData.StoreId == storeId && !p.PullPaymentData.Archived && p.State == PayoutState.AwaitingPayment)
|
||||
.ToListAsync()).Where(data =>
|
||||
var payouts = (await PullPaymentHostedService.GetPayouts(new PullPaymentHostedService.PayoutQuery()
|
||||
{
|
||||
States = new[] {PayoutState.AwaitingPayment}, Stores = new[] {storeId}, PayoutIds = payoutIds
|
||||
}, context)).Where(data =>
|
||||
PaymentMethodId.TryParse(data.PaymentMethodId, out var paymentMethodId) &&
|
||||
CanHandle(paymentMethodId))
|
||||
.Select(data => (data, ParseProof(data) as PayoutTransactionOnChainBlob)).Where(tuple => tuple.Item2 != null && tuple.Item2.TransactionId != null && tuple.Item2.Accounted == true);
|
||||
|
|
|
@ -151,6 +151,9 @@ namespace BTCPayServer.HostedServices
|
|||
public string[] PayoutIds { get; set; }
|
||||
public string[] PaymentMethods { get; set; }
|
||||
public string[] Stores { get; set; }
|
||||
public bool IncludeArchived { get; set; }
|
||||
public bool IncludeStoreData { get; set; }
|
||||
public bool IncludePullPaymentData { get; set; }
|
||||
}
|
||||
|
||||
public async Task<List<PayoutData>> GetPayouts(PayoutQuery payoutQuery)
|
||||
|
@ -159,7 +162,8 @@ namespace BTCPayServer.HostedServices
|
|||
return await GetPayouts(payoutQuery, ctx);
|
||||
}
|
||||
|
||||
public async Task<List<PayoutData>> GetPayouts(PayoutQuery payoutQuery, ApplicationDbContext ctx)
|
||||
public static async Task<List<PayoutData>> GetPayouts(PayoutQuery payoutQuery, ApplicationDbContext ctx,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = ctx.Payouts.AsQueryable();
|
||||
if (payoutQuery.States is not null)
|
||||
|
@ -186,8 +190,23 @@ namespace BTCPayServer.HostedServices
|
|||
{
|
||||
query = query.Where(data => payoutQuery.Stores.Contains(data.StoreDataId));
|
||||
}
|
||||
if (payoutQuery.IncludeStoreData)
|
||||
{
|
||||
query = query.Include(data => data.StoreData);
|
||||
}
|
||||
|
||||
if (payoutQuery.IncludePullPaymentData || !payoutQuery.IncludeArchived)
|
||||
{
|
||||
query = query.Include(data => data.PullPaymentData);
|
||||
}
|
||||
|
||||
return await query.ToListAsync();
|
||||
if (!payoutQuery.IncludeArchived)
|
||||
{
|
||||
query = query.Where(data =>
|
||||
data.PullPaymentData == null || !data.PullPaymentData.Archived);
|
||||
}
|
||||
|
||||
return await query.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Data.PullPaymentData> GetPullPayment(string pullPaymentId, bool includePayouts)
|
||||
|
@ -769,7 +788,7 @@ namespace BTCPayServer.HostedServices
|
|||
|
||||
public string PayoutId { get; set; }
|
||||
public JObject Proof { get; set; }
|
||||
public PayoutState State { get; set; }
|
||||
public PayoutState State { get; set; } = PayoutState.Completed;
|
||||
|
||||
public static string GetErrorMessage(PayoutPaidResult result)
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ public class LightningPendingPayoutListener : BaseAsyncService
|
|||
.ToDictionary(network => new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike));
|
||||
|
||||
|
||||
var payouts = await _pullPaymentHostedService.GetPayouts(
|
||||
var payouts = await PullPaymentHostedService.GetPayouts(
|
||||
new PullPaymentHostedService.PayoutQuery()
|
||||
{
|
||||
States = new PayoutState[] { PayoutState.InProgress },
|
||||
|
|
|
@ -62,7 +62,7 @@ public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T
|
|||
{
|
||||
|
||||
await using var context = _applicationDbContextFactory.CreateContext();
|
||||
var payouts = await _pullPaymentHostedService.GetPayouts(
|
||||
var payouts = await PullPaymentHostedService.GetPayouts(
|
||||
new PullPaymentHostedService.PayoutQuery()
|
||||
{
|
||||
States = new[] { PayoutState.AwaitingPayment },
|
||||
|
|
Loading…
Add table
Reference in a new issue