From c96487041638f4a155d355b948b8be830830d0bb Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Wed, 25 May 2022 12:59:28 +0200 Subject: [PATCH] Allow pull payments denominated in SATS to be claimed Fixes #3750. --- .../Controllers/UIPullPaymentController.cs | 17 ++++++++++++----- BTCPayServer/Data/Payouts/IClaimDestination.cs | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/Controllers/UIPullPaymentController.cs b/BTCPayServer/Controllers/UIPullPaymentController.cs index 159167611..25d2b7c2d 100644 --- a/BTCPayServer/Controllers/UIPullPaymentController.cs +++ b/BTCPayServer/Controllers/UIPullPaymentController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Abstractions.Extensions; @@ -14,6 +15,7 @@ using BTCPayServer.Services.Rates; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using NBitcoin; namespace BTCPayServer.Controllers { @@ -90,8 +92,7 @@ namespace BTCPayServer.Controllers return View(nameof(ViewPullPayment), vm); } - [Route("pull-payments/{pullPaymentId}/claim")] - [HttpPost] + [HttpPost("pull-payments/{pullPaymentId}/claim")] public async Task ClaimPullPayment(string pullPaymentId, ViewPullPaymentModel vm) { using var ctx = _dbContextFactory.CreateContext(); @@ -122,10 +123,16 @@ namespace BTCPayServer.Controllers { ModelState.AddModelError(nameof(vm.ClaimedAmount), "Amount is required"); } - else if (vm.ClaimedAmount != 0 && destination.destination.Amount != null && vm.ClaimedAmount != destination.destination.Amount) + else { - ModelState.AddModelError(nameof(vm.ClaimedAmount), - $"Amount is implied in destination ({destination.destination.Amount}) that does not match the payout amount provided {vm.ClaimedAmount})"); + var amount = ppBlob.Currency == "SATS" ? new Money(vm.ClaimedAmount, MoneyUnit.Satoshi).ToUnit(MoneyUnit.BTC) : vm.ClaimedAmount; + if (destination.destination.Amount != null && amount != destination.destination.Amount) + { + var implied = _currencyNameTable.DisplayFormatCurrency(destination.destination.Amount.Value, paymentMethodId.CryptoCode); + var provided = _currencyNameTable.DisplayFormatCurrency(vm.ClaimedAmount, ppBlob.Currency); + ModelState.AddModelError(nameof(vm.ClaimedAmount), + $"Amount implied in destination ({implied}) does not match the payout amount provided ({provided})."); + } } if (!ModelState.IsValid) diff --git a/BTCPayServer/Data/Payouts/IClaimDestination.cs b/BTCPayServer/Data/Payouts/IClaimDestination.cs index 21d8136ee..62f1ac8d3 100644 --- a/BTCPayServer/Data/Payouts/IClaimDestination.cs +++ b/BTCPayServer/Data/Payouts/IClaimDestination.cs @@ -1,5 +1,4 @@ #nullable enable -using NBitcoin; namespace BTCPayServer.Data {