コード例 #1
0
        private InvoiceEntity ToEntity(Data.InvoiceData invoice)
        {
            var entity = invoice.GetBlob(_Networks);
            PaymentMethodDictionary paymentMethods = null;

#pragma warning disable CS0618
            entity.Payments = invoice.Payments.Select(p =>
            {
                var paymentEntity = p.GetBlob(_Networks);
                if (paymentEntity is null)
                {
                    return(null);
                }
                // PaymentEntity on version 0 does not have their own fee, because it was assumed that the payment method have fixed fee.
                // We want to hide this legacy detail in InvoiceRepository, so we fetch the fee from the PaymentMethod and assign it to the PaymentEntity.
                if (paymentEntity.Version == 0)
                {
                    if (paymentMethods == null)
                    {
                        paymentMethods = entity.GetPaymentMethods();
                    }
                    var paymentMethodDetails = paymentMethods.TryGet(paymentEntity.GetPaymentMethodId())?.GetPaymentMethodDetails();
                    if (paymentMethodDetails != null) // == null should never happen, but we never know.
                    {
                        paymentEntity.NetworkFee = paymentMethodDetails.GetNextNetworkFee();
                    }
                }

                return(paymentEntity);
            })
                              .Where(p => p != null)
                              .OrderBy(a => a.ReceivedTime).ToList();
#pragma warning restore CS0618
            var state = invoice.GetInvoiceState();
            entity.ExceptionStatus = state.ExceptionStatus;
            entity.Status          = state.Status;
            entity.RefundMail      = invoice.CustomerEmail;
            entity.Refundable      = false;
            if (invoice.HistoricalAddressInvoices != null)
            {
                entity.HistoricalAddresses = invoice.HistoricalAddressInvoices.ToArray();
            }
            if (invoice.AddressInvoices != null)
            {
                entity.AvailableAddressHashes = invoice.AddressInvoices.Select(a => a.GetAddress() + a.GetpaymentMethodId().ToString()).ToHashSet();
            }
            if (invoice.Events != null)
            {
                entity.Events = invoice.Events.OrderBy(c => c.Timestamp).ToList();
            }

            if (!string.IsNullOrEmpty(entity.RefundMail) && string.IsNullOrEmpty(entity.BuyerInformation.BuyerEmail))
            {
                entity.BuyerInformation.BuyerEmail = entity.RefundMail;
            }
            entity.Archived = invoice.Archived;
            return(entity);
        }
コード例 #2
0
        private InvoiceEntity ToEntity(Data.InvoiceData invoice)
        {
            var entity = ToObject(invoice.Blob);
            PaymentMethodDictionary paymentMethods = null;

#pragma warning disable CS0618
            entity.Payments = invoice.Payments.Select(p =>
            {
                var paymentEntity       = ToObject <PaymentEntity>(p.Blob, null);
                paymentEntity.Accounted = p.Accounted;
                paymentEntity.PaymentMethodHandlerDictionary = _paymentMethodHandlerDictionary;
                // PaymentEntity on version 0 does not have their own fee, because it was assumed that the payment method have fixed fee.
                // We want to hide this legacy detail in InvoiceRepository, so we fetch the fee from the PaymentMethod and assign it to the PaymentEntity.
                if (paymentEntity.Version == 0)
                {
                    if (paymentMethods == null)
                    {
                        paymentMethods = entity.GetPaymentMethods();
                    }
                    var paymentMethodDetails = paymentMethods.TryGet(paymentEntity.GetPaymentMethodId())?.GetPaymentMethodDetails();
                    if (paymentMethodDetails != null) // == null should never happen, but we never know.
                    {
                        paymentEntity.NetworkFee = paymentMethodDetails.GetNextNetworkFee();
                    }
                }

                return(paymentEntity);
            })
                              .OrderBy(a => a.ReceivedTime).ToList();
#pragma warning restore CS0618
            var state = invoice.GetInvoiceState();
            entity.ExceptionStatus = state.ExceptionStatus;
            entity.Status          = state.Status;
            entity.RefundMail      = invoice.CustomerEmail;
            entity.Refundable      = invoice.RefundAddresses.Count != 0;
            if (invoice.HistoricalAddressInvoices != null)
            {
                entity.HistoricalAddresses = invoice.HistoricalAddressInvoices.ToArray();
            }
            if (invoice.AddressInvoices != null)
            {
                entity.AvailableAddressHashes = invoice.AddressInvoices.Select(a => a.GetAddress() + a.GetpaymentMethodId().ToString()).ToHashSet();
            }
            if (invoice.Events != null)
            {
                entity.Events = invoice.Events.OrderBy(c => c.Timestamp).ToList();
            }
            return(entity);
        }
コード例 #3
0
        private InvoiceEntity ToEntity(Data.InvoiceData invoice)
        {
            var entity = ToObject(invoice.Blob);
            PaymentMethodDictionary paymentMethods = null;

#pragma warning disable CS0618
            entity.Payments = invoice.Payments.Select(p =>
            {
                var unziped    = ZipUtils.Unzip(p.Blob);
                var cryptoCode = GetCryptoCode(unziped);
                var network    = _Networks.GetNetwork <BTCPayNetworkBase>(cryptoCode);
                PaymentEntity paymentEntity = null;
                if (network == null)
                {
                    paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject <PaymentEntity>(unziped, null);
                }
                else
                {
                    paymentEntity = network.ToObject <PaymentEntity>(unziped);
                }
                paymentEntity.Network   = network;
                paymentEntity.Accounted = p.Accounted;
                // PaymentEntity on version 0 does not have their own fee, because it was assumed that the payment method have fixed fee.
                // We want to hide this legacy detail in InvoiceRepository, so we fetch the fee from the PaymentMethod and assign it to the PaymentEntity.
                if (paymentEntity.Version == 0)
                {
                    if (paymentMethods == null)
                    {
                        paymentMethods = entity.GetPaymentMethods();
                    }
                    var paymentMethodDetails = paymentMethods.TryGet(paymentEntity.GetPaymentMethodId())?.GetPaymentMethodDetails();
                    if (paymentMethodDetails != null) // == null should never happen, but we never know.
                    {
                        paymentEntity.NetworkFee = paymentMethodDetails.GetNextNetworkFee();
                    }
                }

                return(paymentEntity);
            })
                              .OrderBy(a => a.ReceivedTime).ToList();
#pragma warning restore CS0618
            var state = invoice.GetInvoiceState();
            entity.ExceptionStatus = state.ExceptionStatus;
            entity.Status          = state.Status;
            entity.RefundMail      = invoice.CustomerEmail;
            entity.Refundable      = invoice.RefundAddresses.Count != 0;
            if (invoice.HistoricalAddressInvoices != null)
            {
                entity.HistoricalAddresses = invoice.HistoricalAddressInvoices.ToArray();
            }
            if (invoice.AddressInvoices != null)
            {
                entity.AvailableAddressHashes = invoice.AddressInvoices.Select(a => a.GetAddress() + a.GetpaymentMethodId().ToString()).ToHashSet();
            }
            if (invoice.Events != null)
            {
                entity.Events = invoice.Events.OrderBy(c => c.Timestamp).ToList();
            }

            if (!string.IsNullOrEmpty(entity.RefundMail) && string.IsNullOrEmpty(entity.BuyerInformation.BuyerEmail))
            {
                entity.BuyerInformation.BuyerEmail = entity.RefundMail;
            }
            return(entity);
        }