mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Receipts: Fix amount paid discrepancy (#4287)
Displays the actual amount paid instead of the total invoice price. Fixes #4242.
This commit is contained in:
@@ -179,48 +179,51 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
JToken? receiptData = null;
|
JToken? receiptData = null;
|
||||||
i.Metadata?.AdditionalData?.TryGetValue("receiptData", out receiptData);
|
i.Metadata?.AdditionalData?.TryGetValue("receiptData", out receiptData);
|
||||||
|
|
||||||
|
var payments = i.GetPayments(true)
|
||||||
|
.Select(paymentEntity =>
|
||||||
|
{
|
||||||
|
var paymentData = paymentEntity.GetCryptoPaymentData();
|
||||||
|
var paymentMethodId = paymentEntity.GetPaymentMethodId();
|
||||||
|
if (paymentData is null || paymentMethodId is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string txId = paymentData.GetPaymentId();
|
||||||
|
string? link = GetTransactionLink(paymentMethodId, txId);
|
||||||
|
var paymentMethod = i.GetPaymentMethod(paymentMethodId);
|
||||||
|
var amount = paymentData.GetValue();
|
||||||
|
var rate = paymentMethod.Rate;
|
||||||
|
var paid = (amount - paymentEntity.NetworkFee) * rate;
|
||||||
|
|
||||||
|
return new ViewPaymentRequestViewModel.PaymentRequestInvoicePayment
|
||||||
|
{
|
||||||
|
Amount = amount,
|
||||||
|
Paid = paid,
|
||||||
|
ReceivedDate = paymentEntity.ReceivedTime.DateTime,
|
||||||
|
PaidFormatted = _CurrencyNameTable.FormatCurrency(paid, i.Currency),
|
||||||
|
RateFormatted = _CurrencyNameTable.FormatCurrency(rate, i.Currency),
|
||||||
|
PaymentMethod = paymentMethodId.ToPrettyString(),
|
||||||
|
Link = link,
|
||||||
|
Id = txId,
|
||||||
|
Destination = paymentData.GetDestination()
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.Where(payment => payment != null)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return View(new InvoiceReceiptViewModel
|
return View(new InvoiceReceiptViewModel
|
||||||
{
|
{
|
||||||
StoreName = store.StoreName,
|
StoreName = store.StoreName,
|
||||||
Status = i.Status.ToModernStatus(),
|
Status = i.Status.ToModernStatus(),
|
||||||
Amount = i.Price,
|
Amount = payments.Sum(p => p!.Paid),
|
||||||
Currency = i.Currency,
|
Currency = i.Currency,
|
||||||
Timestamp = i.InvoiceTime,
|
Timestamp = i.InvoiceTime,
|
||||||
InvoiceId = i.Id,
|
InvoiceId = i.Id,
|
||||||
OrderId = i.Metadata?.OrderId,
|
OrderId = i.Metadata?.OrderId,
|
||||||
OrderUrl = i.Metadata?.OrderUrl,
|
OrderUrl = i.Metadata?.OrderUrl,
|
||||||
Payments = receipt.ShowPayments is false ? null : i.GetPayments(true).Select(paymentEntity =>
|
Payments = receipt.ShowPayments is false ? null : payments,
|
||||||
{
|
|
||||||
var paymentData = paymentEntity.GetCryptoPaymentData();
|
|
||||||
var paymentMethodId = paymentEntity.GetPaymentMethodId();
|
|
||||||
if (paymentData is null || paymentMethodId is null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
string txId = paymentData.GetPaymentId();
|
|
||||||
string? link = GetTransactionLink(paymentMethodId, txId);
|
|
||||||
var paymentMethod = i.GetPaymentMethod(paymentMethodId);
|
|
||||||
var amount = paymentData.GetValue();
|
|
||||||
var rate = paymentMethod.Rate;
|
|
||||||
var paid = (amount - paymentEntity.NetworkFee) * rate;
|
|
||||||
|
|
||||||
return new ViewPaymentRequestViewModel.PaymentRequestInvoicePayment
|
|
||||||
{
|
|
||||||
Amount = amount,
|
|
||||||
Paid = paid,
|
|
||||||
ReceivedDate = paymentEntity.ReceivedTime.DateTime,
|
|
||||||
PaidFormatted = _CurrencyNameTable.FormatCurrency(paid, i.Currency),
|
|
||||||
RateFormatted = _CurrencyNameTable.FormatCurrency(rate, i.Currency),
|
|
||||||
PaymentMethod = paymentMethodId.ToPrettyString(),
|
|
||||||
Link = link,
|
|
||||||
Id = txId,
|
|
||||||
Destination = paymentData.GetDestination()
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.Where(payment => payment != null)
|
|
||||||
.ToList(),
|
|
||||||
ReceiptOptions = receipt,
|
ReceiptOptions = receipt,
|
||||||
AdditionalData = receiptData is null
|
AdditionalData = receiptData is null
|
||||||
? new Dictionary<string, object>()
|
? new Dictionary<string, object>()
|
||||||
|
|||||||
Reference in New Issue
Block a user