コード例 #1
0
        public async Task <IActionResult> Invoice(string invoiceId)
        {
            var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery()
            {
                UserId = GetUserId(),
                InvoiceId = invoiceId
            })).FirstOrDefault();

            if (invoice == null)
            {
                return(NotFound());
            }

            var dto   = invoice.EntityToDTO();
            var store = await _StoreRepository.FindStore(invoice.StoreId);

            InvoiceDetailsModel model = new InvoiceDetailsModel()
            {
                StoreName          = store.StoreName,
                StoreLink          = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
                Id                 = invoice.Id,
                Status             = invoice.Status,
                RefundEmail        = invoice.RefundMail,
                CreatedDate        = invoice.InvoiceTime,
                ExpirationDate     = invoice.ExpirationTime,
                OrderId            = invoice.OrderId,
                BuyerInformation   = invoice.BuyerInformation,
                Rate               = invoice.Rate,
                Fiat               = dto.Price + " " + dto.Currency,
                BTC                = invoice.GetTotalCryptoDue().ToString() + " BTC",
                BTCDue             = invoice.GetCryptoDue().ToString() + " BTC",
                BTCPaid            = invoice.GetTotalPaid().ToString() + " BTC",
                NetworkFee         = invoice.GetNetworkFee().ToString() + " BTC",
                NotificationUrl    = invoice.NotificationURL,
                ProductInformation = invoice.ProductInformation,
                BitcoinAddress     = invoice.DepositAddress,
                PaymentUrl         = dto.PaymentUrls.BIP72
            };

            var payments = invoice
                           .Payments
                           .Select(async payment =>
            {
                var m             = new InvoiceDetailsModel.Payment();
                m.DepositAddress  = payment.Output.ScriptPubKey.GetDestinationAddress(_Network);
                m.Confirmations   = (await _Explorer.GetTransactionAsync(payment.Outpoint.Hash))?.Confirmations ?? 0;
                m.TransactionId   = payment.Outpoint.Hash.ToString();
                m.ReceivedTime    = payment.ReceivedTime;
                m.TransactionLink = _Network == Network.Main ? $"https://www.smartbit.com.au/tx/{m.TransactionId}" : $"https://testnet.smartbit.com.au/tx/{m.TransactionId}";
                return(m);
            })
                           .ToArray();
            await Task.WhenAll(payments);

            model.Payments      = payments.Select(p => p.GetAwaiter().GetResult()).ToList();
            model.StatusMessage = StatusMessage;
            return(View(model));
        }
コード例 #2
0
        private InvoiceDetailsModel InvoicePopulatePayments(InvoiceEntity invoice)
        {
            var model = new InvoiceDetailsModel();

            foreach (var data in invoice.GetPaymentMethods())
            {
                var accounting      = data.Calculate();
                var paymentMethodId = data.GetId();
                var cryptoPayment   = new InvoiceDetailsModel.CryptoPayment();
                cryptoPayment.PaymentMethod = paymentMethodId.ToPrettyString();
                cryptoPayment.Due           = _CurrencyNameTable.DisplayFormatCurrency(accounting.Due.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
                cryptoPayment.Paid          = _CurrencyNameTable.DisplayFormatCurrency(accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
                cryptoPayment.Overpaid      = _CurrencyNameTable.DisplayFormatCurrency(accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
                var paymentMethodDetails = data.GetPaymentMethodDetails();
                cryptoPayment.Address = paymentMethodDetails.GetPaymentDestination();
                cryptoPayment.Rate    = ExchangeRate(data);
                model.CryptoPayments.Add(cryptoPayment);
            }

            foreach (var payment in invoice.GetPayments())
            {
                var paymentData = payment.GetCryptoPaymentData();
                //TODO: abstract
                if (paymentData is Payments.Bitcoin.BitcoinLikePaymentData onChainPaymentData)
                {
                    var m = new InvoiceDetailsModel.Payment();
                    m.Crypto         = payment.GetPaymentMethodId().CryptoCode;
                    m.DepositAddress = onChainPaymentData.GetDestination();

                    int confirmationCount = onChainPaymentData.ConfirmationCount;
                    if (confirmationCount >= payment.Network.MaxTrackedConfirmation)
                    {
                        m.Confirmations = "At least " + (payment.Network.MaxTrackedConfirmation);
                    }
                    else
                    {
                        m.Confirmations = confirmationCount.ToString(CultureInfo.InvariantCulture);
                    }

                    m.TransactionId   = onChainPaymentData.Outpoint.Hash.ToString();
                    m.ReceivedTime    = payment.ReceivedTime;
                    m.TransactionLink = string.Format(CultureInfo.InvariantCulture, payment.Network.BlockExplorerLink, m.TransactionId);
                    m.Replaced        = !payment.Accounted;
                    model.OnChainPayments.Add(m);
                }
                else
                {
                    var lightningPaymentData = (LightningLikePaymentData)paymentData;
                    model.OffChainPayments.Add(new InvoiceDetailsModel.OffChainPayment()
                    {
                        Crypto = payment.Network.CryptoCode,
                        BOLT11 = lightningPaymentData.BOLT11
                    });
                }
            }
            return(model);
        }
コード例 #3
0
        public async Task <IActionResult> Invoice(string invoiceId)
        {
            var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery()
            {
                UserId = GetUserId(),
                InvoiceId = invoiceId,
                IncludeAddresses = true,
                IncludeEvents = true
            })).FirstOrDefault();

            if (invoice == null)
            {
                return(NotFound());
            }

            var dto   = invoice.EntityToDTO(_NetworkProvider);
            var store = await _StoreRepository.FindStore(invoice.StoreId);

            InvoiceDetailsModel model = new InvoiceDetailsModel()
            {
                StoreName          = store.StoreName,
                StoreLink          = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
                Id                 = invoice.Id,
                Status             = invoice.Status,
                TransactionSpeed   = invoice.SpeedPolicy == SpeedPolicy.HighSpeed ? "high" : invoice.SpeedPolicy == SpeedPolicy.MediumSpeed ? "medium" : "low",
                RefundEmail        = invoice.RefundMail,
                CreatedDate        = invoice.InvoiceTime,
                ExpirationDate     = invoice.ExpirationTime,
                MonitoringDate     = invoice.MonitoringExpiration,
                OrderId            = invoice.OrderId,
                BuyerInformation   = invoice.BuyerInformation,
                Fiat               = FormatCurrency((decimal)dto.Price, dto.Currency),
                NotificationUrl    = invoice.NotificationURL,
                RedirectUrl        = invoice.RedirectURL,
                ProductInformation = invoice.ProductInformation,
                StatusException    = invoice.ExceptionStatus,
                Events             = invoice.Events
            };

            foreach (var data in invoice.GetPaymentMethods(null))
            {
                var cryptoInfo      = dto.CryptoInfo.First(o => o.GetpaymentMethodId() == data.GetId());
                var accounting      = data.Calculate();
                var paymentMethodId = data.GetId();
                var cryptoPayment   = new InvoiceDetailsModel.CryptoPayment();
                cryptoPayment.PaymentMethod = ToString(paymentMethodId);
                cryptoPayment.Due           = accounting.Due.ToString() + $" {paymentMethodId.CryptoCode}";
                cryptoPayment.Paid          = accounting.CryptoPaid.ToString() + $" {paymentMethodId.CryptoCode}";

                var onchainMethod = data.GetPaymentMethodDetails() as Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod;
                if (onchainMethod != null)
                {
                    cryptoPayment.Address = onchainMethod.DepositAddress;
                }
                cryptoPayment.Rate       = FormatCurrency(data);
                cryptoPayment.PaymentUrl = cryptoInfo.PaymentUrls.BIP21;
                model.CryptoPayments.Add(cryptoPayment);
            }

            var payments = invoice
                           .GetPayments()
                           .Where(p => p.GetPaymentMethodId().PaymentType == PaymentTypes.BTCLike)
                           .Select(async payment =>
            {
                var paymentData    = (Payments.Bitcoin.BitcoinLikePaymentData)payment.GetCryptoPaymentData();
                var m              = new InvoiceDetailsModel.Payment();
                var paymentNetwork = _NetworkProvider.GetNetwork(payment.GetCryptoCode());
                m.PaymentMethod    = ToString(payment.GetPaymentMethodId());
                m.DepositAddress   = paymentData.Output.ScriptPubKey.GetDestinationAddress(paymentNetwork.NBitcoinNetwork);

                int confirmationCount = 0;
                if ((paymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted) &&
                    (paymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow))         // The confirmation count in the paymentData is not up to date
                {
                    confirmationCount             = (await((ExplorerClientProvider)_ServiceProvider.GetService(typeof(ExplorerClientProvider))).GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(paymentData.Outpoint.Hash))?.Confirmations ?? 0;
                    paymentData.ConfirmationCount = confirmationCount;
                    payment.SetCryptoPaymentData(paymentData);
                    await _InvoiceRepository.UpdatePayments(new List <PaymentEntity> {
                        payment
                    });
                }
                else
                {
                    confirmationCount = paymentData.ConfirmationCount;
                }
                if (confirmationCount >= paymentNetwork.MaxTrackedConfirmation)
                {
                    m.Confirmations = "At least " + (paymentNetwork.MaxTrackedConfirmation);
                }
                else
                {
                    m.Confirmations = confirmationCount.ToString(CultureInfo.InvariantCulture);
                }

                m.TransactionId   = paymentData.Outpoint.Hash.ToString();
                m.ReceivedTime    = payment.ReceivedTime;
                m.TransactionLink = string.Format(CultureInfo.InvariantCulture, paymentNetwork.BlockExplorerLink, m.TransactionId);
                m.Replaced        = !payment.Accounted;
                return(m);
            })
                           .ToArray();
            await Task.WhenAll(payments);

            model.Addresses = invoice.HistoricalAddresses.Select(h => new InvoiceDetailsModel.AddressModel
            {
                Destination   = h.GetAddress(),
                PaymentMethod = ToString(h.GetPaymentMethodId()),
                Current       = !h.UnAssigned.HasValue
            }).ToArray();
            model.Payments      = payments.Select(p => p.GetAwaiter().GetResult()).ToList();
            model.StatusMessage = StatusMessage;
            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> Invoice(string invoiceId)
        {
            var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery()
            {
                UserId = GetUserId(),
                InvoiceId = invoiceId,
                IncludeAddresses = true
            })).FirstOrDefault();

            if (invoice == null)
            {
                return(NotFound());
            }

            var dto   = invoice.EntityToDTO(_NetworkProvider);
            var store = await _StoreRepository.FindStore(invoice.StoreId);

            InvoiceDetailsModel model = new InvoiceDetailsModel()
            {
                StoreName          = store.StoreName,
                StoreLink          = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
                Id                 = invoice.Id,
                Status             = invoice.Status,
                RefundEmail        = invoice.RefundMail,
                CreatedDate        = invoice.InvoiceTime,
                ExpirationDate     = invoice.ExpirationTime,
                MonitoringDate     = invoice.MonitoringExpiration,
                OrderId            = invoice.OrderId,
                BuyerInformation   = invoice.BuyerInformation,
                Fiat               = FormatCurrency((decimal)dto.Price, dto.Currency),
                NotificationUrl    = invoice.NotificationURL,
                ProductInformation = invoice.ProductInformation,
                StatusException    = invoice.ExceptionStatus
            };

            foreach (var data in invoice.GetCryptoData())
            {
                var cryptoInfo     = dto.CryptoInfo.First(o => o.CryptoCode.Equals(data.Key, StringComparison.OrdinalIgnoreCase));
                var accounting     = data.Value.Calculate();
                var paymentNetwork = _NetworkProvider.GetNetwork(data.Key);
                var cryptoPayment  = new InvoiceDetailsModel.CryptoPayment();
                cryptoPayment.CryptoCode = paymentNetwork.CryptoCode;
                cryptoPayment.Due        = accounting.Due.ToString() + $" {paymentNetwork.CryptoCode}";
                cryptoPayment.Paid       = accounting.CryptoPaid.ToString() + $" {paymentNetwork.CryptoCode}";
                cryptoPayment.Address    = data.Value.DepositAddress.ToString();
                cryptoPayment.Rate       = FormatCurrency(data.Value);
                cryptoPayment.PaymentUrl = cryptoInfo.PaymentUrls.BIP21;
                model.CryptoPayments.Add(cryptoPayment);
            }

            var payments = invoice
                           .GetPayments()
                           .Select(async payment =>
            {
                var m = new InvoiceDetailsModel.Payment();
                var paymentNetwork = _NetworkProvider.GetNetwork(payment.GetCryptoCode());
                m.CryptoCode       = payment.GetCryptoCode();
                m.DepositAddress   = payment.GetScriptPubKey().GetDestinationAddress(paymentNetwork.NBitcoinNetwork);
                m.Confirmations    = (await _ExplorerClients.GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(payment.Outpoint.Hash))?.Confirmations ?? 0;
                m.TransactionId    = payment.Outpoint.Hash.ToString();
                m.ReceivedTime     = payment.ReceivedTime;
                m.TransactionLink  = string.Format(paymentNetwork.BlockExplorerLink, m.TransactionId);
                m.Replaced         = !payment.Accounted;
                return(m);
            })
                           .ToArray();
            await Task.WhenAll(payments);

            model.Addresses     = invoice.HistoricalAddresses;
            model.Payments      = payments.Select(p => p.GetAwaiter().GetResult()).ToList();
            model.StatusMessage = StatusMessage;
            return(View(model));
        }
コード例 #5
0
        public async Task <IActionResult> Invoice(string invoiceId, string cryptoCode = null)
        {
            if (cryptoCode == null)
            {
                cryptoCode = "BTC";
            }
            var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery()
            {
                UserId = GetUserId(),
                InvoiceId = invoiceId
            })).FirstOrDefault();

            if (invoice == null)
            {
                return(NotFound());
            }

            var network = _NetworkProvider.GetNetwork(cryptoCode);

            if (network == null || !invoice.Support(network))
            {
                return(NotFound());
            }

            var cryptoData = invoice.GetCryptoData(network);

            var dto        = invoice.EntityToDTO(_NetworkProvider);
            var cryptoInfo = dto.CryptoInfo.First(o => o.CryptoCode.Equals(cryptoCode, StringComparison.OrdinalIgnoreCase));
            var store      = await _StoreRepository.FindStore(invoice.StoreId);

            var accounting            = cryptoData.Calculate();
            InvoiceDetailsModel model = new InvoiceDetailsModel()
            {
                StoreName          = store.StoreName,
                StoreLink          = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
                Id                 = invoice.Id,
                Status             = invoice.Status,
                RefundEmail        = invoice.RefundMail,
                CreatedDate        = invoice.InvoiceTime,
                ExpirationDate     = invoice.ExpirationTime,
                OrderId            = invoice.OrderId,
                BuyerInformation   = invoice.BuyerInformation,
                Rate               = cryptoData.Rate,
                Fiat               = dto.Price + " " + dto.Currency,
                BTC                = accounting.TotalDue.ToString() + $" {network.CryptoCode}",
                BTCDue             = accounting.Due.ToString() + $" {network.CryptoCode}",
                BTCPaid            = accounting.Paid.ToString() + $" {network.CryptoCode}",
                NetworkFee         = accounting.NetworkFee.ToString() + $" {network.CryptoCode}",
                NotificationUrl    = invoice.NotificationURL,
                ProductInformation = invoice.ProductInformation,
                BitcoinAddress     = BitcoinAddress.Create(cryptoInfo.Address, network.NBitcoinNetwork),
                PaymentUrl         = cryptoInfo.PaymentUrls.BIP72
            };

            var payments = invoice
                           .Payments
                           .Select(async payment =>
            {
                var m             = new InvoiceDetailsModel.Payment();
                m.DepositAddress  = payment.GetScriptPubKey().GetDestinationAddress(network.NBitcoinNetwork);
                m.Confirmations   = (await _Explorer.GetTransactionAsync(payment.Outpoint.Hash))?.Confirmations ?? 0;
                m.TransactionId   = payment.Outpoint.Hash.ToString();
                m.ReceivedTime    = payment.ReceivedTime;
                m.TransactionLink = string.Format(network.BlockExplorerLink, m.TransactionId);
                return(m);
            })
                           .ToArray();
            await Task.WhenAll(payments);

            model.Payments      = payments.Select(p => p.GetAwaiter().GetResult()).ToList();
            model.StatusMessage = StatusMessage;
            return(View(model));
        }