mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
Allow invoice creation to only allow specific payment methods in UI (#792)
* allow invoice creation to only allow specific payment methods * add test * reuse existing feature * final fixes
This commit is contained in:
parent
4bc03fbf06
commit
b5f4739ae5
@ -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<string, InvoiceSupportedTransactionCurrency>()
|
||||
{
|
||||
{"BTC", new InvoiceSupportedTransactionCurrency()
|
||||
{
|
||||
Enabled = true
|
||||
}}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Equal(1, invoice.SupportedTransactionCurrencies.Count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
|
@ -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!";
|
||||
|
@ -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))
|
||||
|
@ -70,5 +70,16 @@ namespace BTCPayServer.Models.InvoicingModels
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public List<string> SupportedTransactionCurrencies
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public SelectList AvailablePaymentMethods
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,11 @@
|
||||
<select asp-for="StoreId" asp-items="Model.Stores" class="form-control"></select>
|
||||
<span asp-validation-for="StoreId" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="SupportedTransactionCurrencies" class="control-label"></label>
|
||||
<select asp-for="SupportedTransactionCurrencies" asp-items="Model.AvailablePaymentMethods" class="form-control" multiple="multiple"></select>
|
||||
<span asp-validation-for="SupportedTransactionCurrencies" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user