Allow pull payments denominated in SATS to be claimed

Fixes #3750.
This commit is contained in:
Dennis Reimann
2022-05-25 12:59:28 +02:00
parent cfbf081cac
commit c964870416
2 changed files with 12 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Abstractions.Extensions;
@@ -14,6 +15,7 @@ using BTCPayServer.Services.Rates;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NBitcoin;
namespace BTCPayServer.Controllers namespace BTCPayServer.Controllers
{ {
@@ -90,8 +92,7 @@ namespace BTCPayServer.Controllers
return View(nameof(ViewPullPayment), vm); return View(nameof(ViewPullPayment), vm);
} }
[Route("pull-payments/{pullPaymentId}/claim")] [HttpPost("pull-payments/{pullPaymentId}/claim")]
[HttpPost]
public async Task<IActionResult> ClaimPullPayment(string pullPaymentId, ViewPullPaymentModel vm) public async Task<IActionResult> ClaimPullPayment(string pullPaymentId, ViewPullPaymentModel vm)
{ {
using var ctx = _dbContextFactory.CreateContext(); using var ctx = _dbContextFactory.CreateContext();
@@ -122,10 +123,16 @@ namespace BTCPayServer.Controllers
{ {
ModelState.AddModelError(nameof(vm.ClaimedAmount), "Amount is required"); ModelState.AddModelError(nameof(vm.ClaimedAmount), "Amount is required");
} }
else if (vm.ClaimedAmount != 0 && destination.destination.Amount != null && vm.ClaimedAmount != destination.destination.Amount) else
{ {
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), ModelState.AddModelError(nameof(vm.ClaimedAmount),
$"Amount is implied in destination ({destination.destination.Amount}) that does not match the payout amount provided {vm.ClaimedAmount})"); $"Amount implied in destination ({implied}) does not match the payout amount provided ({provided}).");
}
} }
if (!ModelState.IsValid) if (!ModelState.IsValid)

View File

@@ -1,5 +1,4 @@
#nullable enable #nullable enable
using NBitcoin;
namespace BTCPayServer.Data namespace BTCPayServer.Data
{ {