Skip to content

Commit

Permalink
Payments Report: Add POS data columns
Browse files Browse the repository at this point in the history
Extends the payments report data with subtotal, tip and discount amounts. This works for keypad and cart sales. Closes btcpayserver#5290.
  • Loading branch information
dennisreimann committed Feb 2, 2024
1 parent 71c5566 commit 91628ad
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions BTCPayServer/Services/Reporting/PaymentsReportProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ ViewDefinition CreateViewDefinition()
new ("LightningAddress", "string"),
new ("Currency", "string"),
new ("CurrencyAmount", "amount"),
new ("Rate", "amount")
new ("Rate", "amount"),
new ("Subtotal", "amount"),
new ("Discount", "amount"),
new ("Tip", "amount")
},
Charts =
{
Expand Down Expand Up @@ -163,7 +166,7 @@ public override async Task Query(QueryContext queryContext, CancellationToken ca
values.Add(paymentType.CryptoCode);

var cryptoAmount = paymentData.GetValue();

var currency = invoiceBlob.Currency ?? "USD";
var divisibility = 8;
if (_btcPayNetworkProvider.TryGetNetwork<BTCPayNetwork>(paymentType.CryptoCode, out var network))
{
Expand All @@ -177,18 +180,25 @@ public override async Task Query(QueryContext queryContext, CancellationToken ca
.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails)?
.ConsumedLightningAddress;
values.Add(consumerdLightningAddress);
values.Add(invoiceBlob.Currency);
values.Add(currency);
if (invoiceBlob.Rates.TryGetValue(paymentType.CryptoCode, out var rate))
{
values.Add(DisplayFormatter.ToFormattedAmount(rate * cryptoAmount, invoiceBlob.Currency ?? "USD")); // Currency amount
values.Add(DisplayFormatter.ToFormattedAmount(rate, invoiceBlob.Currency ?? "USD"));
values.Add(DisplayFormatter.ToFormattedAmount(rate * cryptoAmount, currency)); // Currency amount
values.Add(DisplayFormatter.ToFormattedAmount(rate, currency));
}
else
{
values.Add(null);
values.Add(null);
}

var subtotal = invoiceBlob.Metadata.PosData?.Value<decimal?>("subTotal");
values.Add(subtotal.HasValue ? DisplayFormatter.ToFormattedAmount(subtotal.Value, currency) : null);
var discount = invoiceBlob.Metadata.PosData?.Value<decimal?>("discountAmount");
values.Add(discount.HasValue ? DisplayFormatter.ToFormattedAmount(discount.Value, currency) : null);
var tip = invoiceBlob.Metadata.PosData?.Value<decimal?>("tip");
values.Add(tip.HasValue ? DisplayFormatter.ToFormattedAmount(tip.Value, currency) : null);

queryContext.Data.Add(values);
}
}
Expand Down

0 comments on commit 91628ad

Please sign in to comment.