diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index b11a366e7..a0f36f3f4 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -2609,6 +2609,40 @@ donation: Assert.Equal(StatusMessageModel.StatusSeverity.Success, parsed.Severity); } + + [Fact] + [Trait("Integration", "Integration")] + public async Task CanCreateInvoiceWithSpecificPaymentMethods() + { + using (var tester = ServerTester.Create()) + { + tester.Start(); + await tester.EnsureChannelsSetup(); + var user = tester.NewAccount(); + user.GrantAccess(); + user.RegisterLightningNode("BTC", LightningConnectionType.Charge); + user.RegisterDerivationScheme("BTC"); + user.RegisterDerivationScheme("LTC"); + + var invoice = await user.BitPay.CreateInvoiceAsync(new Invoice(100, "BTC")); + Assert.Equal(2, invoice.SupportedTransactionCurrencies.Count); + + + invoice = await user.BitPay.CreateInvoiceAsync(new Invoice(100, "BTC") + { + SupportedTransactionCurrencies = new Dictionary() + { + {"BTC", new InvoiceSupportedTransactionCurrency() + { + Enabled = true + }} + } + }); + + Assert.Equal(1, invoice.SupportedTransactionCurrencies.Count); + } + } + [Fact] diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 6c6d80e00..320257ac9 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -571,7 +571,16 @@ namespace BTCPayServer.Controllers StatusMessage = "Error: You need to create at least one store before creating a transaction"; return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"); } - return View(new CreateInvoiceModel() { Stores = stores }); + + var paymentMethods = new SelectList(_NetworkProvider.GetAll().SelectMany(network => new[] + { + new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike), + new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike) + }).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))), + nameof(SelectListItem.Value), + nameof(SelectListItem.Text)); + + return View(new CreateInvoiceModel() { Stores = stores, AvailablePaymentMethods = paymentMethods}); } [HttpPost] @@ -582,6 +591,16 @@ namespace BTCPayServer.Controllers { var stores = await _StoreRepository.GetStoresByUserId(GetUserId()); model.Stores = new SelectList(stores, nameof(StoreData.Id), nameof(StoreData.StoreName), model.StoreId); + + var paymentMethods = new SelectList(_NetworkProvider.GetAll().SelectMany(network => new[] + { + new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike), + new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike) + }).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))), + nameof(SelectListItem.Value), + nameof(SelectListItem.Text)); + model.AvailablePaymentMethods = paymentMethods; + var store = stores.FirstOrDefault(s => s.Id == model.StoreId); if (store == null) { @@ -603,6 +622,7 @@ namespace BTCPayServer.Controllers ModelState.AddModelError(nameof(model.StoreId), "You need to configure the derivation scheme in order to create an invoice"); return View(model); } + if (StatusMessage != null) { @@ -626,6 +646,10 @@ namespace BTCPayServer.Controllers ItemDesc = model.ItemDesc, FullNotifications = true, BuyerEmail = model.BuyerEmail, + SupportedTransactionCurrencies = model.SupportedTransactionCurrencies?.ToDictionary(s => s, s => new InvoiceSupportedTransactionCurrency() + { + Enabled =true + }) }, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken); StatusMessage = $"Invoice {result.Data.Id} just created!"; diff --git a/BTCPayServer/Controllers/InvoiceController.cs b/BTCPayServer/Controllers/InvoiceController.cs index 64be2a1c5..4a64fe4d0 100644 --- a/BTCPayServer/Controllers/InvoiceController.cs +++ b/BTCPayServer/Controllers/InvoiceController.cs @@ -160,7 +160,6 @@ namespace BTCPayServer.Controllers var rateRules = storeBlob.GetRateRules(_NetworkProvider); var fetchingByCurrencyPair = _RateProvider.FetchRates(currencyPairsToFetch, rateRules, cancellationToken); - var fetchingAll = WhenAllFetched(logs, fetchingByCurrencyPair); var supportedPaymentMethods = store.GetSupportedPaymentMethods(_NetworkProvider) .Where(s => !excludeFilter.Match(s.PaymentId)) diff --git a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs index 8df1a47f9..9fd8b923e 100644 --- a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs +++ b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs @@ -70,5 +70,16 @@ namespace BTCPayServer.Models.InvoicingModels get; set; } + + public List SupportedTransactionCurrencies + { + get; + set; + } + public SelectList AvailablePaymentMethods + { + get; + set; + } } } diff --git a/BTCPayServer/Views/Invoice/CreateInvoice.cshtml b/BTCPayServer/Views/Invoice/CreateInvoice.cshtml index 5a8f5d158..e1f2a003b 100644 --- a/BTCPayServer/Views/Invoice/CreateInvoice.cshtml +++ b/BTCPayServer/Views/Invoice/CreateInvoice.cshtml @@ -67,6 +67,11 @@ +
+ + + +