Payouts: Unify confirm external payment and manually mark as paid actions (#2751)

This commit is contained in:
Andrew Camilleri 2021-08-05 07:47:25 +02:00 committed by GitHub
parent f84b2c5160
commit 060f30d0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 27 deletions

View File

@ -1081,7 +1081,7 @@ namespace BTCPayServer.Tests
Assert.Contains(PayoutState.AwaitingPayment.GetStateString(), s.Driver.PageSource);
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-selectAllCheckbox")).Click();
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-actions")).Click();
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-confirm-payment")).Click();
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-mark-paid")).Click();
s.FindAlertMessage();
s.Driver.FindElement(By.Id("InProgress-view")).Click();

View File

@ -204,10 +204,18 @@ namespace BTCPayServer.Controllers
});
}
var command = vm.Command.Substring(vm.Command.IndexOf('-', StringComparison.InvariantCulture) + 1);
var handler = _payoutHandlers
.FirstOrDefault(handler => handler.CanHandle(paymentMethodId));
if (handler != null)
{
var result = await handler.DoSpecificAction(command, payoutIds, walletId.StoreId);
if (result != null)
{
TempData.SetStatusMessageModel(result);
}
}
switch (command)
{
case "approve-pay":
case "approve":
{
@ -264,8 +272,7 @@ namespace BTCPayServer.Controllers
{
Message = "Payouts approved", Severity = StatusMessageModel.StatusSeverity.Success
});
return RedirectToAction(nameof(Payouts),
new {walletId = walletId.ToString(), pullPaymentId = vm.PullPaymentId});
break;
}
case "pay":
@ -337,8 +344,7 @@ namespace BTCPayServer.Controllers
{
Message = "Payouts marked as paid", Severity = StatusMessageModel.StatusSeverity.Success
});
return RedirectToAction(nameof(Payouts),
new {walletId = walletId.ToString(), pullPaymentId = vm.PullPaymentId});
break;
}
case "cancel":
@ -348,25 +354,10 @@ namespace BTCPayServer.Controllers
{
Message = "Payouts archived", Severity = StatusMessageModel.StatusSeverity.Success
});
return RedirectToAction(nameof(Payouts),
new {walletId = walletId.ToString(), pullPaymentId = vm.PullPaymentId});
break;
}
var handler = _payoutHandlers
.FirstOrDefault(handler => handler.CanHandle(paymentMethodId));
if (handler != null)
{
var result = await handler.DoSpecificAction(command, payoutIds, walletId.StoreId);
TempData.SetStatusMessageModel(result);
return RedirectToAction(nameof(Payouts), new
{
walletId = walletId.ToString(),
pullPaymentId = vm.PullPaymentId
});
}
return NotFound();
return RedirectToAction(nameof(Payouts),
new {walletId = walletId.ToString(), pullPaymentId = vm.PullPaymentId});
}
private static async Task<List<PayoutData>> GetPayoutsForPaymentMethod(PaymentMethodId paymentMethodId,

View File

@ -143,7 +143,6 @@ public class BitcoinLikePayoutHandler : IPayoutHandler
{
{PayoutState.AwaitingPayment, new List<(string Action, string Text)>()
{
("confirm-payment", "Confirm payouts as paid"),
("reject-payment", "Reject payout transaction")
}}
};
@ -153,7 +152,7 @@ public class BitcoinLikePayoutHandler : IPayoutHandler
{
switch (action)
{
case "confirm-payment":
case "mark-paid":
await using (var context = _dbContextFactory.CreateContext())
{
var payouts = (await context.Payouts