diff --git a/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs b/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs index ed866f6a5..90d24d194 100644 --- a/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs +++ b/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs @@ -192,7 +192,7 @@ namespace BTCPayServer.Data.Payouts.LightningLike return new ResultVM { PayoutId = payoutData.Id, - Result = PayResult.Error, + Success = false, Destination = blob.Destination, Message = message }; @@ -216,7 +216,7 @@ namespace BTCPayServer.Data.Payouts.LightningLike { public string PayoutId { get; set; } public string Destination { get; set; } - public PayResult Result { get; set; } + public bool? Success { get; set; } public string Message { get; set; } } diff --git a/BTCPayServer/Payments/Lightning/LightningPendingPayoutListener.cs b/BTCPayServer/Payments/Lightning/LightningPendingPayoutListener.cs index 8577e7fca..7cc17f40f 100644 --- a/BTCPayServer/Payments/Lightning/LightningPendingPayoutListener.cs +++ b/BTCPayServer/Payments/Lightning/LightningPendingPayoutListener.cs @@ -100,25 +100,25 @@ public class LightningPendingPayoutListener : BaseAsyncService if (proof is not null) payment = await client.GetPayment(proof.PaymentHash, CancellationToken); } - catch + catch (OperationCanceledException) { + // Do not mark as cancelled if the operation was cancelled. + // This can happen with Nostr GetPayment if the connection to relay is too slow. + continue; } - if (payment is null) - { - payoutData.State = PayoutState.Cancelled; - continue; - } - switch (payment.Status) - { - case LightningPaymentStatus.Complete: - payoutData.State = PayoutState.Completed; - proof.Preimage = payment.Preimage; - payoutData.SetProofBlob(proof, null); - break; - case LightningPaymentStatus.Failed: - payoutData.State = PayoutState.Cancelled; - break; - } + payoutData.State = payment?.Status switch + { + LightningPaymentStatus.Complete => PayoutState.Completed, + LightningPaymentStatus.Failed => PayoutState.Cancelled, + LightningPaymentStatus.Unknown or LightningPaymentStatus.Pending => PayoutState.InProgress, + _ => PayoutState.Cancelled + }; + + if (payment is { Status: LightningPaymentStatus.Complete }) + { + proof.Preimage = payment.Preimage; + payoutData.SetProofBlob(proof, null); + } } foreach (PayoutData payoutData in payoutByStoreByPaymentMethod) diff --git a/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs index 557a0c73e..253f28a11 100644 --- a/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs @@ -110,7 +110,7 @@ public class LightningAutomatedPayoutProcessor : BaseAutomatedPayoutProcessor
  • = 10) @@ -141,7 +141,7 @@ public class LightningAutomatedPayoutProcessor : BaseAutomatedPayoutProcessor
  • true, + LightningPaymentStatus.Failed => false, + _ => null }; + amountSent ??= payment?.AmountSent; + preimage ??= payment?.Preimage; } - if (payment.Preimage is not null) - proofBlob.Preimage = payment.Preimage; - if (payment.Status == LightningPaymentStatus.Complete) + if (preimage is not null) + proofBlob.Preimage = preimage; + + var vm = new ResultVM + { + PayoutId = payoutData.Id, + Success = success, + Destination = payoutBlob.Destination + }; + if (success is true) { payoutData.State = PayoutState.Completed; payoutData.SetProofBlob(proofBlob, null); - return new ResultVM - { - PayoutId = payoutData.Id, - Result = PayResult.Ok, - Destination = payoutBlob.Destination, - Message = payment.AmountSent != null - ? $"Paid out {payment.AmountSent.ToDecimal(LightMoneyUnit.BTC)} {payoutData.Currency}" - : "Paid out" - }; + vm.Message = amountSent != null + ? $"Paid out {amountSent.ToDecimal(LightMoneyUnit.BTC)} {payoutData.Currency}" + : "Paid out"; } - else if (payment.Status == LightningPaymentStatus.Failed) + else if (success is false) { payoutData.State = PayoutState.AwaitingPayment; - string reason = ""; - if (pay?.ErrorDetail is string err) - reason = $" ({err})"; - return new ResultVM - { - PayoutId = payoutData.Id, - Result = PayResult.Error, - Destination = payoutBlob.Destination, - Message = $"The payment failed{reason}" - }; + var err = errorReason is null ? "" : $" ({errorReason})"; + vm.Message = $"The payment failed{err}"; } else { // Payment will be saved as pending, the LightningPendingPayoutListener will handle settling/cancelling payoutData.State = PayoutState.InProgress; payoutData.SetProofBlob(proofBlob, null); - return new ResultVM - { - PayoutId = payoutData.Id, - Result = PayResult.Ok, - Destination = payoutBlob.Destination, - Message = "The payment has been initiated but is still in-flight." - }; + vm.Message = "The payment has been initiated but is still in-flight."; } + return vm; } protected override async Task ProcessShouldSave(object paymentMethodConfig, List payouts) diff --git a/BTCPayServer/Views/UILightningLikePayout/LightningPayoutResult.cshtml b/BTCPayServer/Views/UILightningLikePayout/LightningPayoutResult.cshtml index 66438c31a..1422fbab9 100644 --- a/BTCPayServer/Views/UILightningLikePayout/LightningPayoutResult.cshtml +++ b/BTCPayServer/Views/UILightningLikePayout/LightningPayoutResult.cshtml @@ -8,9 +8,9 @@

    @ViewData["Title"]

    @foreach (var item in Model) { -