コード例 #1
0
        private IEnumerable <ExportInvoiceHolder> convertFromDb(InvoiceEntity invoice)
        {
            var exportList = new List <ExportInvoiceHolder>();
            var currency   = Currencies.GetNumberFormatInfo(invoice.Currency, true);
            var invoiceDue = invoice.Price;

            // in this first version we are only exporting invoices that were paid
            foreach (var payment in invoice.GetPayments(true))
            {
                var cryptoCode = payment.GetPaymentMethodId().CryptoCode;
                var pdata      = payment.GetCryptoPaymentData();

                var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId());
                var paidAfterNetworkFees = pdata.GetValue() - payment.NetworkFee;
                invoiceDue -= paidAfterNetworkFees * pmethod.Rate;

                var target = new ExportInvoiceHolder
                {
                    ReceivedDate   = payment.ReceivedTime.UtcDateTime,
                    PaymentId      = pdata.GetPaymentId(),
                    CryptoCode     = cryptoCode,
                    ConversionRate = pmethod.Rate,
                    PaymentType    = payment.GetPaymentMethodId().PaymentType.ToPrettyString(),
                    Destination    = pdata.GetDestination(),
                    Paid           = pdata.GetValue().ToString(CultureInfo.InvariantCulture),
                    PaidCurrency   = Math.Round(pdata.GetValue() * pmethod.Rate, currency.NumberDecimalDigits).ToString(CultureInfo.InvariantCulture),
                    // Adding NetworkFee because Paid doesn't take into account network fees
                    // so if fee is 10000 satoshis, customer can essentially send infinite number of tx
                    // and merchant effectivelly would receive 0 BTC, invoice won't be paid
                    // while looking just at export you could sum Paid and assume merchant "received payments"
                    NetworkFee            = payment.NetworkFee.ToString(CultureInfo.InvariantCulture),
                    InvoiceDue            = Math.Round(invoiceDue, currency.NumberDecimalDigits),
                    OrderId               = invoice.Metadata.OrderId ?? string.Empty,
                    StoreId               = invoice.StoreId,
                    InvoiceId             = invoice.Id,
                    InvoiceCreatedDate    = invoice.InvoiceTime.UtcDateTime,
                    InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime,
                    InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime,
#pragma warning disable CS0618 // Type or member is obsolete
                    InvoiceFullStatus      = invoice.GetInvoiceState().ToString(),
                    InvoiceStatus          = invoice.StatusString,
                    InvoiceExceptionStatus = invoice.ExceptionStatusString,
#pragma warning restore CS0618 // Type or member is obsolete
                    InvoiceItemCode = invoice.Metadata.ItemCode,
                    InvoiceItemDesc = invoice.Metadata.ItemDesc,
                    InvoicePrice    = invoice.Price,
                    InvoiceCurrency = invoice.Currency,
                    BuyerEmail      = invoice.Metadata.BuyerEmail
                };

                exportList.Add(target);
            }

            exportList = exportList.OrderBy(a => a.ReceivedDate).ToList();

            return(exportList);
        }
コード例 #2
0
ファイル: InvoiceExport.cs プロジェクト: vinguan/btcpayserver
        private IEnumerable <ExportInvoiceHolder> convertFromDb(InvoiceEntity invoice)
        {
            var exportList = new List <ExportInvoiceHolder>();

            // in this first version we are only exporting invoices that were paid
            foreach (var payment in invoice.GetPayments())
            {
                // not accounted payments are payments which got double spent like RBfed
                if (!payment.Accounted)
                {
                    continue;
                }

                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 target = new ExportInvoiceHolder
                {
                    ReceivedDate    = payment.ReceivedTime.UtcDateTime,
                    PaymentId       = pdata.GetPaymentId(),
                    CryptoCode      = cryptoCode,
                    ConversionRate  = pmethod.Rate,
                    PaymentType     = details.GetPaymentType() == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain",
                    Destination     = details.GetPaymentDestination(),
                    PaymentDue      = $"{accounting.MinimumTotalDue} {cryptoCode}",
                    PaymentPaid     = $"{accounting.CryptoPaid} {cryptoCode}",
                    PaymentOverpaid = $"{accounting.OverpaidHelper} {cryptoCode}",

                    OrderId        = invoice.OrderId,
                    StoreId        = invoice.StoreId,
                    InvoiceId      = invoice.Id,
                    CreatedDate    = invoice.InvoiceTime.UtcDateTime,
                    ExpirationDate = invoice.ExpirationTime.UtcDateTime,
                    MonitoringDate = invoice.MonitoringExpiration.UtcDateTime,
#pragma warning disable CS0618 // Type or member is obsolete
                    Status = invoice.StatusString,
#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,
                };

                exportList.Add(target);
            }

            exportList = exportList.OrderBy(a => a.ReceivedDate).ToList();

            return(exportList);
        }
コード例 #3
0
        private IEnumerable <ExportInvoiceHolder> convertFromDb(InvoiceEntity invoice)
        {
            var exportList = new List <ExportInvoiceHolder>();

            // in this first version we are only exporting invoices that were paid
            foreach (var payment in invoice.GetPayments())
            {
                // not accounted payments are payments which got double spent like RBfed
                if (!payment.Accounted)
                {
                    continue;
                }

                var cryptoCode = payment.GetPaymentMethodId().CryptoCode;
                var pdata      = payment.GetCryptoPaymentData();

                var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), Networks);

                var target = new ExportInvoiceHolder
                {
                    ReceivedDate          = payment.ReceivedTime.UtcDateTime,
                    PaymentId             = pdata.GetPaymentId(),
                    CryptoCode            = cryptoCode,
                    ConversionRate        = pmethod.Rate,
                    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,
                    InvoiceCreatedDate    = invoice.InvoiceTime.UtcDateTime,
                    InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime,
                    InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime,
#pragma warning disable CS0618 // Type or member is obsolete
                    InvoiceFullStatus      = invoice.GetInvoiceState().ToString(),
                    InvoiceStatus          = invoice.StatusString,
                    InvoiceExceptionStatus = invoice.ExceptionStatusString,
#pragma warning restore CS0618 // Type or member is obsolete
                    InvoiceItemCode = invoice.ProductInformation.ItemCode,
                    InvoiceItemDesc = invoice.ProductInformation.ItemDesc,
                    InvoicePrice    = invoice.ProductInformation.Price,
                    InvoiceCurrency = invoice.ProductInformation.Currency,
                };

                exportList.Add(target);
            }

            exportList = exportList.OrderBy(a => a.ReceivedDate).ToList();

            return(exportList);
        }
コード例 #4
0
        private IEnumerable <ExportInvoiceHolder> convertFromDb(InvoiceEntity invoice)
        {
            var exportList = new List <ExportInvoiceHolder>();

            var invoiceDue = invoice.ProductInformation.Price;

            // in this first version we are only exporting invoices that were paid
            foreach (var payment in invoice.GetPayments())
            {
                // not accounted payments are payments which got double spent like RBfed
                if (!payment.Accounted)
                {
                    continue;
                }

                var cryptoCode = payment.GetPaymentMethodId().CryptoCode;
                var pdata      = payment.GetCryptoPaymentData();

                var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), Networks);
                var paidAfterNetworkFees = pdata.GetValue() - payment.NetworkFee;
                invoiceDue -= paidAfterNetworkFees * pmethod.Rate;

                var target = new ExportInvoiceHolder
                {
                    ReceivedDate   = payment.ReceivedTime.UtcDateTime,
                    PaymentId      = pdata.GetPaymentId(),
                    CryptoCode     = cryptoCode,
                    ConversionRate = pmethod.Rate,
                    PaymentType    = payment.GetPaymentMethodId().PaymentType == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain",
                    Destination    = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork(cryptoCode)),
                    Paid           = pdata.GetValue().ToString(CultureInfo.InvariantCulture),
                    PaidCurrency   = (pdata.GetValue() * pmethod.Rate).ToString(CultureInfo.InvariantCulture),
                    // Adding NetworkFee because Paid doesn't take into account network fees
                    // so if fee is 10000 satoshis, customer can essentially send infinite number of tx
                    // and merchant effectivelly would receive 0 BTC, invoice won't be paid
                    // while looking just at export you could sum Paid and assume merchant "received payments"
                    NetworkFee            = payment.NetworkFee.ToString(CultureInfo.InvariantCulture),
                    InvoiceDue            = invoiceDue,
                    OrderId               = invoice.OrderId,
                    StoreId               = invoice.StoreId,
                    InvoiceId             = invoice.Id,
                    InvoiceCreatedDate    = invoice.InvoiceTime.UtcDateTime,
                    InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime,
                    InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime,
#pragma warning disable CS0618 // Type or member is obsolete
                    InvoiceFullStatus      = invoice.GetInvoiceState().ToString(),
                    InvoiceStatus          = invoice.StatusString,
                    InvoiceExceptionStatus = invoice.ExceptionStatusString,
#pragma warning restore CS0618 // Type or member is obsolete
                    InvoiceItemCode = invoice.ProductInformation.ItemCode,
                    InvoiceItemDesc = invoice.ProductInformation.ItemDesc,
                    InvoicePrice    = invoice.ProductInformation.Price,
                    InvoiceCurrency = invoice.ProductInformation.Currency,
                };

                exportList.Add(target);
            }

            exportList = exportList.OrderBy(a => a.ReceivedDate).ToList();

            return(exportList);
        }