Fix payment exports to reflect correctly payment data, rename fields.

This commit is contained in:
nicolas.dorier 2018-12-18 21:35:52 +09:00
parent d5ae79c38c
commit 93113fd871
5 changed files with 51 additions and 34 deletions

View file

@ -103,7 +103,7 @@ namespace BTCPayServer.Controllers
{ {
var m = new InvoiceDetailsModel.Payment(); var m = new InvoiceDetailsModel.Payment();
m.Crypto = payment.GetPaymentMethodId().CryptoCode; m.Crypto = payment.GetPaymentMethodId().CryptoCode;
m.DepositAddress = onChainPaymentData.Output.ScriptPubKey.GetDestinationAddress(paymentNetwork.NBitcoinNetwork); m.DepositAddress = onChainPaymentData.GetDestination(paymentNetwork);
int confirmationCount = 0; int confirmationCount = 0;
if ((onChainPaymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted) if ((onChainPaymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted)
@ -484,7 +484,7 @@ namespace BTCPayServer.Controllers
[BitpayAPIConstraint(false)] [BitpayAPIConstraint(false)]
public async Task<IActionResult> Export(string format, string searchTerm = null) public async Task<IActionResult> Export(string format, string searchTerm = null)
{ {
var model = new InvoiceExport(); var model = new InvoiceExport(_NetworkProvider);
var invoices = await ListInvoicesProcess(searchTerm, 0, int.MaxValue); var invoices = await ListInvoicesProcess(searchTerm, 0, int.MaxValue);
var res = model.Process(invoices, format); var res = model.Process(invoices, format);

View file

@ -78,5 +78,15 @@ namespace BTCPayServer.Payments.Bitcoin
} }
return false; return false;
} }
public BitcoinAddress GetDestination(BTCPayNetwork network)
{
return Output.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork);
}
string CryptoPaymentData.GetDestination(BTCPayNetwork network)
{
return GetDestination(network).ToString();
}
} }
} }

View file

@ -16,6 +16,12 @@ namespace BTCPayServer.Payments.Lightning
[JsonConverter(typeof(LightMoneyJsonConverter))] [JsonConverter(typeof(LightMoneyJsonConverter))]
public LightMoney Amount { get; set; } public LightMoney Amount { get; set; }
public string BOLT11 { get; set; } public string BOLT11 { get; set; }
public string GetDestination(BTCPayNetwork network)
{
return GetPaymentId();
}
public string GetPaymentId() public string GetPaymentId()
{ {
return BOLT11; return BOLT11;

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.Payments.Bitcoin; using BTCPayServer.Payments.Bitcoin;
@ -10,6 +11,12 @@ namespace BTCPayServer.Services.Invoices.Export
{ {
public class InvoiceExport public class InvoiceExport
{ {
public BTCPayNetworkProvider Networks { get; }
public InvoiceExport(BTCPayNetworkProvider networks)
{
Networks = networks;
}
public string Process(InvoiceEntity[] invoices, string fileFormat) public string Process(InvoiceEntity[] invoices, string fileFormat)
{ {
var csvInvoices = new List<ExportInvoiceHolder>(); var csvInvoices = new List<ExportInvoiceHolder>();
@ -55,9 +62,7 @@ namespace BTCPayServer.Services.Invoices.Export
var cryptoCode = payment.GetPaymentMethodId().CryptoCode; var cryptoCode = payment.GetPaymentMethodId().CryptoCode;
var pdata = payment.GetCryptoPaymentData(); var pdata = payment.GetCryptoPaymentData();
var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), null); var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), Networks);
var accounting = pmethod.Calculate();
var details = pmethod.GetPaymentMethodDetails();
var target = new ExportInvoiceHolder var target = new ExportInvoiceHolder
{ {
@ -65,27 +70,24 @@ namespace BTCPayServer.Services.Invoices.Export
PaymentId = pdata.GetPaymentId(), PaymentId = pdata.GetPaymentId(),
CryptoCode = cryptoCode, CryptoCode = cryptoCode,
ConversionRate = pmethod.Rate, ConversionRate = pmethod.Rate,
PaymentType = details.GetPaymentType() == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain", PaymentType = payment.GetPaymentMethodId().PaymentType == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain",
Destination = details.GetPaymentDestination(), Destination = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork(cryptoCode)),
PaymentDue = $"{accounting.MinimumTotalDue}", Paid = pdata.GetValue().ToString(CultureInfo.InvariantCulture),
PaymentPaid = $"{accounting.CryptoPaid}",
PaymentOverpaid = $"{accounting.OverpaidHelper}",
OrderId = invoice.OrderId, OrderId = invoice.OrderId,
StoreId = invoice.StoreId, StoreId = invoice.StoreId,
InvoiceId = invoice.Id, InvoiceId = invoice.Id,
CreatedDate = invoice.InvoiceTime.UtcDateTime, InvoiceCreatedDate = invoice.InvoiceTime.UtcDateTime,
ExpirationDate = invoice.ExpirationTime.UtcDateTime, InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime,
MonitoringDate = invoice.MonitoringExpiration.UtcDateTime, InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime,
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
FullStatus = invoice.Status.ToString(), InvoiceFullStatus = invoice.Status.ToString(),
Status = invoice.StatusString, InvoiceStatus = invoice.StatusString,
ExceptionStatus = invoice.ExceptionStatusString, InvoiceExceptionStatus = invoice.ExceptionStatusString,
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
ItemCode = invoice.ProductInformation?.ItemCode, InvoiceItemCode = invoice.ProductInformation.ItemCode,
ItemDesc = invoice.ProductInformation?.ItemDesc, InvoiceItemDesc = invoice.ProductInformation.ItemDesc,
FiatPrice = invoice.ProductInformation?.Price ?? 0, InvoicePrice = invoice.ProductInformation.Price,
FiatCurrency = invoice.ProductInformation?.Currency, InvoiceCurrency = invoice.ProductInformation.Currency,
}; };
exportList.Add(target); exportList.Add(target);
@ -103,25 +105,23 @@ namespace BTCPayServer.Services.Invoices.Export
public string StoreId { get; set; } public string StoreId { get; set; }
public string OrderId { get; set; } public string OrderId { get; set; }
public string InvoiceId { get; set; } public string InvoiceId { get; set; }
public DateTime CreatedDate { get; set; } public DateTime InvoiceCreatedDate { get; set; }
public DateTime ExpirationDate { get; set; } public DateTime InvoiceExpirationDate { get; set; }
public DateTime MonitoringDate { get; set; } public DateTime InvoiceMonitoringDate { get; set; }
public string PaymentId { get; set; } public string PaymentId { get; set; }
public string CryptoCode { get; set; } public string CryptoCode { get; set; }
public string Destination { get; set; } public string Destination { get; set; }
public string PaymentType { get; set; } public string PaymentType { get; set; }
public string PaymentDue { get; set; } public string Paid { get; set; }
public string PaymentPaid { get; set; }
public string PaymentOverpaid { get; set; }
public decimal ConversionRate { get; set; } public decimal ConversionRate { get; set; }
public decimal FiatPrice { get; set; } public decimal InvoicePrice { get; set; }
public string FiatCurrency { get; set; } public string InvoiceCurrency { get; set; }
public string ItemCode { get; set; } public string InvoiceItemCode { get; set; }
public string ItemDesc { get; set; } public string InvoiceItemDesc { get; set; }
public string FullStatus { get; set; } public string InvoiceFullStatus { get; set; }
public string Status { get; set; } public string InvoiceStatus { get; set; }
public string ExceptionStatus { get; set; } public string InvoiceExceptionStatus { get; set; }
} }
} }

View file

@ -982,5 +982,6 @@ namespace BTCPayServer.Services.Invoices
bool PaymentConfirmed(PaymentEntity entity, SpeedPolicy speedPolicy, BTCPayNetwork network); bool PaymentConfirmed(PaymentEntity entity, SpeedPolicy speedPolicy, BTCPayNetwork network);
PaymentTypes GetPaymentType(); PaymentTypes GetPaymentType();
string GetDestination(BTCPayNetwork network);
} }
} }