From 060f30d0bf5162555f730149814c6fc902b8d9b6 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Thu, 5 Aug 2021 07:47:25 +0200 Subject: [PATCH] Payouts: Unify confirm external payment and manually mark as paid actions (#2751) --- BTCPayServer.Tests/SeleniumTests.cs | 2 +- .../WalletsController.PullPayments.cs | 39 +++++++------------ .../BitcoinLike/BitcoinLikePayoutHandler.cs | 3 +- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index cff08596e..bd9f1aa41 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -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(); diff --git a/BTCPayServer/Controllers/WalletsController.PullPayments.cs b/BTCPayServer/Controllers/WalletsController.PullPayments.cs index ae025dd7e..c0dfa42d8 100644 --- a/BTCPayServer/Controllers/WalletsController.PullPayments.cs +++ b/BTCPayServer/Controllers/WalletsController.PullPayments.cs @@ -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> GetPayoutsForPaymentMethod(PaymentMethodId paymentMethodId, diff --git a/BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.cs b/BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.cs index 69ac1de60..ee4a00520 100644 --- a/BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.cs +++ b/BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.cs @@ -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