Properly aggregate contributions amount

This commit is contained in:
nicolas.dorier 2019-02-19 16:15:14 +09:00
parent 3bbf4de5d2
commit 119f82fd4e
3 changed files with 11 additions and 6 deletions

View file

@ -285,11 +285,12 @@ namespace BTCPayServer.Tests
Assert.Equal(0m, model.Info.CurrentPendingAmount);
invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, tester.ExplorerNode.Network);
tester.ExplorerNode.SendToAddress(invoiceAddress, Money.Coins(0.5m));
tester.ExplorerNode.SendToAddress(invoiceAddress, Money.Coins(0.2m));
TestUtils.Eventually(() =>
{
model = Assert.IsType<ViewCrowdfundViewModel>(Assert
.IsType<ViewResult>(publicApps.ViewCrowdfund(appId, String.Empty).Result).Model);
Assert.Equal(0.5m, model.Info.CurrentPendingAmount);
Assert.Equal(0.7m, model.Info.CurrentPendingAmount);
});
}

View file

@ -15,6 +15,10 @@ namespace BTCPayServer.Controllers
public string AppId { get; set; }
public object Settings { get; set; }
public string StoreId { get; set; }
public override string ToString()
{
return String.Empty;
}
}

View file

@ -334,7 +334,7 @@ namespace BTCPayServer.Services.Apps
// If the user get a donation via other mean, he can register an invoice manually for such amount
// then mark the invoice as complete
var payments = p.GetPayments();
if (payments.Count == 0 &&
if (payments.Count == 0 &&
p.ExceptionStatus == InvoiceExceptionStatus.Marked &&
p.Status == InvoiceStatus.Complete)
return new[] { (Key: p.ProductInformation.Currency, Value: p.ProductInformation.Price) };
@ -346,11 +346,11 @@ namespace BTCPayServer.Services.Apps
// Else, we just sum the payments
return payments
.GroupBy(pay => pay.GetPaymentMethodId())
.Select(payGroup => (Key: payGroup.Key.ToString(),
Value: payGroup.Select(pay => pay.GetCryptoPaymentData().GetValue()).Sum())).ToArray();
.Select(pay => (Key: pay.GetPaymentMethodId().ToString(), Value: pay.GetCryptoPaymentData().GetValue()))
.ToArray();
})
.ToDictionary(p => p.Key, p => p.Value);
.GroupBy(p => p.Key)
.ToDictionary(p => p.Key, p => p.Select(v => v.Value).Sum());
}
private class PosHolder