From 93113fd8715359eb7f81fd529d4a79f27d1c2253 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 18 Dec 2018 21:35:52 +0900 Subject: [PATCH] Fix payment exports to reflect correctly payment data, rename fields. --- .../Controllers/InvoiceController.UI.cs | 4 +- .../Bitcoin/BitcoinLikePaymentData.cs | 10 +++ .../Lightning/LightningLikePaymentData.cs | 6 ++ .../Services/Invoices/Export/InvoiceExport.cs | 64 +++++++++---------- .../Services/Invoices/InvoiceEntity.cs | 1 + 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 8ea206191..b9ebdaecb 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -103,7 +103,7 @@ namespace BTCPayServer.Controllers { var m = new InvoiceDetailsModel.Payment(); m.Crypto = payment.GetPaymentMethodId().CryptoCode; - m.DepositAddress = onChainPaymentData.Output.ScriptPubKey.GetDestinationAddress(paymentNetwork.NBitcoinNetwork); + m.DepositAddress = onChainPaymentData.GetDestination(paymentNetwork); int confirmationCount = 0; if ((onChainPaymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted) @@ -484,7 +484,7 @@ namespace BTCPayServer.Controllers [BitpayAPIConstraint(false)] public async Task Export(string format, string searchTerm = null) { - var model = new InvoiceExport(); + var model = new InvoiceExport(_NetworkProvider); var invoices = await ListInvoicesProcess(searchTerm, 0, int.MaxValue); var res = model.Process(invoices, format); diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs index 9026aaf13..d31c0a52e 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs @@ -78,5 +78,15 @@ namespace BTCPayServer.Payments.Bitcoin } return false; } + + public BitcoinAddress GetDestination(BTCPayNetwork network) + { + return Output.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork); + } + + string CryptoPaymentData.GetDestination(BTCPayNetwork network) + { + return GetDestination(network).ToString(); + } } } diff --git a/BTCPayServer/Payments/Lightning/LightningLikePaymentData.cs b/BTCPayServer/Payments/Lightning/LightningLikePaymentData.cs index 4f2cc37fb..6d630f3a2 100644 --- a/BTCPayServer/Payments/Lightning/LightningLikePaymentData.cs +++ b/BTCPayServer/Payments/Lightning/LightningLikePaymentData.cs @@ -16,6 +16,12 @@ namespace BTCPayServer.Payments.Lightning [JsonConverter(typeof(LightMoneyJsonConverter))] public LightMoney Amount { get; set; } public string BOLT11 { get; set; } + + public string GetDestination(BTCPayNetwork network) + { + return GetPaymentId(); + } + public string GetPaymentId() { return BOLT11; diff --git a/BTCPayServer/Services/Invoices/Export/InvoiceExport.cs b/BTCPayServer/Services/Invoices/Export/InvoiceExport.cs index 755fdd0ba..adcb8f673 100644 --- a/BTCPayServer/Services/Invoices/Export/InvoiceExport.cs +++ b/BTCPayServer/Services/Invoices/Export/InvoiceExport.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Payments.Bitcoin; @@ -10,6 +11,12 @@ namespace BTCPayServer.Services.Invoices.Export { public class InvoiceExport { + public BTCPayNetworkProvider Networks { get; } + + public InvoiceExport(BTCPayNetworkProvider networks) + { + Networks = networks; + } public string Process(InvoiceEntity[] invoices, string fileFormat) { var csvInvoices = new List(); @@ -55,9 +62,7 @@ namespace BTCPayServer.Services.Invoices.Export var cryptoCode = payment.GetPaymentMethodId().CryptoCode; var pdata = payment.GetCryptoPaymentData(); - var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), null); - var accounting = pmethod.Calculate(); - var details = pmethod.GetPaymentMethodDetails(); + var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), Networks); var target = new ExportInvoiceHolder { @@ -65,27 +70,24 @@ namespace BTCPayServer.Services.Invoices.Export PaymentId = pdata.GetPaymentId(), CryptoCode = cryptoCode, ConversionRate = pmethod.Rate, - PaymentType = details.GetPaymentType() == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain", - Destination = details.GetPaymentDestination(), - PaymentDue = $"{accounting.MinimumTotalDue}", - PaymentPaid = $"{accounting.CryptoPaid}", - PaymentOverpaid = $"{accounting.OverpaidHelper}", - + PaymentType = payment.GetPaymentMethodId().PaymentType == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain", + Destination = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork(cryptoCode)), + Paid = pdata.GetValue().ToString(CultureInfo.InvariantCulture), OrderId = invoice.OrderId, StoreId = invoice.StoreId, InvoiceId = invoice.Id, - CreatedDate = invoice.InvoiceTime.UtcDateTime, - ExpirationDate = invoice.ExpirationTime.UtcDateTime, - MonitoringDate = invoice.MonitoringExpiration.UtcDateTime, + InvoiceCreatedDate = invoice.InvoiceTime.UtcDateTime, + InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime, + InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime, #pragma warning disable CS0618 // Type or member is obsolete - FullStatus = invoice.Status.ToString(), - Status = invoice.StatusString, - ExceptionStatus = invoice.ExceptionStatusString, + InvoiceFullStatus = invoice.Status.ToString(), + InvoiceStatus = invoice.StatusString, + InvoiceExceptionStatus = invoice.ExceptionStatusString, #pragma warning restore CS0618 // Type or member is obsolete - ItemCode = invoice.ProductInformation?.ItemCode, - ItemDesc = invoice.ProductInformation?.ItemDesc, - FiatPrice = invoice.ProductInformation?.Price ?? 0, - FiatCurrency = invoice.ProductInformation?.Currency, + InvoiceItemCode = invoice.ProductInformation.ItemCode, + InvoiceItemDesc = invoice.ProductInformation.ItemDesc, + InvoicePrice = invoice.ProductInformation.Price, + InvoiceCurrency = invoice.ProductInformation.Currency, }; exportList.Add(target); @@ -103,25 +105,23 @@ namespace BTCPayServer.Services.Invoices.Export public string StoreId { get; set; } public string OrderId { get; set; } public string InvoiceId { get; set; } - public DateTime CreatedDate { get; set; } - public DateTime ExpirationDate { get; set; } - public DateTime MonitoringDate { get; set; } + public DateTime InvoiceCreatedDate { get; set; } + public DateTime InvoiceExpirationDate { get; set; } + public DateTime InvoiceMonitoringDate { get; set; } public string PaymentId { get; set; } public string CryptoCode { get; set; } public string Destination { get; set; } public string PaymentType { get; set; } - public string PaymentDue { get; set; } - public string PaymentPaid { get; set; } - public string PaymentOverpaid { get; set; } + public string Paid { get; set; } public decimal ConversionRate { get; set; } - public decimal FiatPrice { get; set; } - public string FiatCurrency { get; set; } - public string ItemCode { get; set; } - public string ItemDesc { get; set; } - public string FullStatus { get; set; } - public string Status { get; set; } - public string ExceptionStatus { get; set; } + public decimal InvoicePrice { get; set; } + public string InvoiceCurrency { get; set; } + public string InvoiceItemCode { get; set; } + public string InvoiceItemDesc { get; set; } + public string InvoiceFullStatus { get; set; } + public string InvoiceStatus { get; set; } + public string InvoiceExceptionStatus { get; set; } } } diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index e223f8690..d586d27b3 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -982,5 +982,6 @@ namespace BTCPayServer.Services.Invoices bool PaymentConfirmed(PaymentEntity entity, SpeedPolicy speedPolicy, BTCPayNetwork network); PaymentTypes GetPaymentType(); + string GetDestination(BTCPayNetwork network); } }