mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Greenfield: Rename enabledOnly to enabled?
Allows the filter to work in both directions instead
This commit is contained in:
parent
4d538c61b1
commit
f4df850d25
9 changed files with 94 additions and 41 deletions
|
@ -9,13 +9,19 @@ namespace BTCPayServer.Client
|
|||
public partial class BTCPayServerClient
|
||||
{
|
||||
public virtual async Task<IEnumerable<LightningNetworkPaymentMethodData>>
|
||||
GetStoreLightningNetworkPaymentMethods(string storeId, bool enabledOnly = false,
|
||||
GetStoreLightningNetworkPaymentMethods(string storeId, bool? enabled = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var query = new Dictionary<string, object>();
|
||||
if (enabled != null)
|
||||
{
|
||||
query.Add(nameof(enabled), enabled);
|
||||
}
|
||||
|
||||
var response =
|
||||
await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/LightningNetwork",
|
||||
new Dictionary<string, object>() {{nameof(enabledOnly), enabledOnly}}), token);
|
||||
query), token);
|
||||
return await HandleResponse<IEnumerable<LightningNetworkPaymentMethodData>>(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,19 @@ namespace BTCPayServer.Client
|
|||
public partial class BTCPayServerClient
|
||||
{
|
||||
public virtual async Task<IEnumerable<OnChainPaymentMethodData>> GetStoreOnChainPaymentMethods(string storeId,
|
||||
bool enabledOnly = false,
|
||||
bool? enabled = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var query = new Dictionary<string, object>();
|
||||
if (enabled != null)
|
||||
{
|
||||
query.Add(nameof(enabled), enabled);
|
||||
}
|
||||
|
||||
var response =
|
||||
await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/Onchain",
|
||||
new Dictionary<string, object>() {{nameof(enabledOnly), enabledOnly}}), token);
|
||||
query), token);
|
||||
return await HandleResponse<IEnumerable<OnChainPaymentMethodData>>(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,19 @@ namespace BTCPayServer.Client
|
|||
public partial class BTCPayServerClient
|
||||
{
|
||||
public virtual async Task<Dictionary<string, GenericPaymentMethodData>> GetStorePaymentMethods(string storeId,
|
||||
bool enabledOnly = false,
|
||||
bool? enabled = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var query = new Dictionary<string, object>();
|
||||
if (enabled != null)
|
||||
{
|
||||
query.Add(nameof(enabled), enabled);
|
||||
}
|
||||
|
||||
var response =
|
||||
await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods",
|
||||
new Dictionary<string, object>() {{nameof(enabledOnly), enabledOnly}}), token);
|
||||
query), token);
|
||||
return await HandleResponse<Dictionary<string, GenericPaymentMethodData>>(response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
_cssThemeManager = cssThemeManager;
|
||||
}
|
||||
|
||||
public static IEnumerable<LightningNetworkPaymentMethodData> GetLightningPaymentMethods(StoreData store, BTCPayNetworkProvider networkProvider, bool enabledOnly = false)
|
||||
public static IEnumerable<LightningNetworkPaymentMethodData> GetLightningPaymentMethods(StoreData store,
|
||||
BTCPayNetworkProvider networkProvider, bool? enabled)
|
||||
{
|
||||
var blob = store.GetStoreBlob();
|
||||
var excludedPaymentMethods = blob.GetExcludedPaymentMethods();
|
||||
|
@ -53,20 +54,21 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
.Select(paymentMethod =>
|
||||
new LightningNetworkPaymentMethodData(
|
||||
paymentMethod.PaymentId.CryptoCode,
|
||||
paymentMethod.GetExternalLightningUrl()?.ToString() ?? paymentMethod.GetDisplayableConnectionString(),
|
||||
paymentMethod.GetExternalLightningUrl()?.ToString() ??
|
||||
paymentMethod.GetDisplayableConnectionString(),
|
||||
!excludedPaymentMethods.Match(paymentMethod.PaymentId)
|
||||
)
|
||||
)
|
||||
.Where((result) => !enabledOnly || result.Enabled)
|
||||
.Where((result) => enabled is null || enabled == result.Enabled)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/stores/{storeId}/payment-methods/LightningNetwork")]
|
||||
public ActionResult<IEnumerable<LightningNetworkPaymentMethodData>> GetLightningPaymentMethods(
|
||||
[FromQuery] bool enabledOnly = false)
|
||||
[FromQuery] bool? enabled)
|
||||
{
|
||||
return Ok(GetLightningPaymentMethods(Store, _btcPayNetworkProvider, enabledOnly));
|
||||
return Ok(GetLightningPaymentMethods(Store, _btcPayNetworkProvider, enabled));
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
|
@ -83,6 +85,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(method);
|
||||
}
|
||||
|
||||
|
@ -132,9 +135,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
if (!await CanUseInternalLightning())
|
||||
{
|
||||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString), $"You are not authorized to use the internal lightning node");
|
||||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
|
||||
$"You are not authorized to use the internal lightning node");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
|
||||
paymentMethod = new Payments.Lightning.LightningSupportedPaymentMethod()
|
||||
{
|
||||
CryptoCode = paymentMethodId.CryptoCode
|
||||
|
@ -149,17 +154,21 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString), $"Invalid URL ({error})");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
|
||||
if (connectionString.ConnectionType == LightningConnectionType.LndGRPC)
|
||||
{
|
||||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
|
||||
$"BTCPay does not support gRPC connections");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
|
||||
if (!await CanManageServer() && !connectionString.IsSafe())
|
||||
{
|
||||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString), $"You do not have 'btcpay.server.canmodifyserversettings' rights, so the connection string should not contain 'cookiefilepath', 'macaroondirectorypath', 'macaroonfilepath', and should not point to a local ip or to a dns name ending with '.internal', '.local', '.lan' or '.'.");
|
||||
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
|
||||
$"You do not have 'btcpay.server.canmodifyserversettings' rights, so the connection string should not contain 'cookiefilepath', 'macaroondirectorypath', 'macaroonfilepath', and should not point to a local ip or to a dns name ending with '.internal', '.local', '.lan' or '.'.");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
|
||||
paymentMethod = new Payments.Lightning.LightningSupportedPaymentMethod()
|
||||
{
|
||||
CryptoCode = paymentMethodId.CryptoCode
|
||||
|
@ -177,7 +186,8 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
return Ok(GetExistingLightningLikePaymentMethod(cryptoCode, store));
|
||||
}
|
||||
|
||||
private LightningNetworkPaymentMethodData GetExistingLightningLikePaymentMethod(string cryptoCode, StoreData store = null)
|
||||
private LightningNetworkPaymentMethodData GetExistingLightningLikePaymentMethod(string cryptoCode,
|
||||
StoreData store = null)
|
||||
{
|
||||
store ??= Store;
|
||||
var storeBlob = store.GetStoreBlob();
|
||||
|
@ -204,9 +214,10 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
private async Task<bool> CanUseInternalLightning()
|
||||
{
|
||||
return _cssThemeManager.AllowLightningInternalNodeForAll ||
|
||||
(await _authorizationService.AuthorizeAsync(User, null,
|
||||
new PolicyRequirement(Policies.CanUseInternalLightningNode))).Succeeded;
|
||||
(await _authorizationService.AuthorizeAsync(User, null,
|
||||
new PolicyRequirement(Policies.CanUseInternalLightningNode))).Succeeded;
|
||||
}
|
||||
|
||||
private async Task<bool> CanManageServer()
|
||||
{
|
||||
return
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
_walletProvider = walletProvider;
|
||||
}
|
||||
|
||||
public static IEnumerable<OnChainPaymentMethodData> GetOnChainPaymentMethods(StoreData store, BTCPayNetworkProvider networkProvider, bool enabledOnly = false)
|
||||
public static IEnumerable<OnChainPaymentMethodData> GetOnChainPaymentMethods(StoreData store,
|
||||
BTCPayNetworkProvider networkProvider, bool? enabled)
|
||||
{
|
||||
var blob = store.GetStoreBlob();
|
||||
var excludedPaymentMethods = blob.GetExcludedPaymentMethods();
|
||||
|
@ -46,16 +47,16 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
.Select(strategy =>
|
||||
new OnChainPaymentMethodData(strategy.PaymentId.CryptoCode,
|
||||
strategy.AccountDerivation.ToString(), !excludedPaymentMethods.Match(strategy.PaymentId)))
|
||||
.Where((result) => !enabledOnly || result.Enabled)
|
||||
.Where((result) => enabled is null || enabled == result.Enabled)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/stores/{storeId}/payment-methods/onchain")]
|
||||
public ActionResult<IEnumerable<OnChainPaymentMethodData>> GetOnChainPaymentMethods(
|
||||
[FromQuery] bool enabledOnly = false)
|
||||
[FromQuery] bool? enabled)
|
||||
{
|
||||
return Ok(GetOnChainPaymentMethods(Store, _btcPayNetworkProvider, enabledOnly));
|
||||
return Ok(GetOnChainPaymentMethods(Store, _btcPayNetworkProvider, enabled));
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
|
@ -72,6 +73,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(method);
|
||||
}
|
||||
|
||||
|
@ -91,6 +93,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var strategy = DerivationSchemeSettings.Parse(paymentMethod.DerivationScheme, network);
|
||||
|
@ -118,11 +121,10 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
"Invalid Derivation Scheme");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpPost("~/api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/preview")]
|
||||
public IActionResult GetProposedOnChainPaymentMethodPreview(string cryptoCode,
|
||||
[FromBody] OnChainPaymentMethodData paymentMethodData,
|
||||
|
@ -132,11 +134,13 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(paymentMethodData?.DerivationScheme))
|
||||
{
|
||||
ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme),
|
||||
"Missing derivationScheme");
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return this.CreateValidationError(ModelState);
|
||||
DerivationSchemeSettings strategy;
|
||||
|
@ -207,6 +211,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme),
|
||||
"Missing derivationScheme");
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return this.CreateValidationError(ModelState);
|
||||
|
||||
|
@ -229,6 +234,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
signing.AccountKeyPath = null;
|
||||
signing.RootFingerprint = null;
|
||||
}
|
||||
|
||||
store.SetSupportedPaymentMethod(id, strategy);
|
||||
storeBlob.SetExcluded(id, !paymentMethodData.Enabled);
|
||||
store.SetStoreBlob(storeBlob);
|
||||
|
|
|
@ -26,20 +26,20 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/stores/{storeId}/payment-methods")]
|
||||
public ActionResult<Dictionary<string, GenericPaymentMethodData>> GetStorePaymentMethods(
|
||||
[FromQuery] bool enabledOnly = false
|
||||
)
|
||||
[FromQuery] bool? enabled)
|
||||
{
|
||||
var storeBlob = Store.GetStoreBlob();
|
||||
var excludedPaymentMethods = storeBlob.GetExcludedPaymentMethods();
|
||||
return Ok(Store.GetSupportedPaymentMethods(_btcPayNetworkProvider)
|
||||
.Where(method => !enabledOnly || !excludedPaymentMethods.Match(method.PaymentId))
|
||||
.Where(method =>
|
||||
enabled is null || (enabled is false && excludedPaymentMethods.Match(method.PaymentId)))
|
||||
.ToDictionary(
|
||||
method => method.PaymentId.ToStringNormalized(),
|
||||
method => new GenericPaymentMethodData()
|
||||
{
|
||||
Enabled = enabledOnly || !excludedPaymentMethods.Match(method.PaymentId),
|
||||
Data = method.PaymentId.PaymentType.GetGreenfieldData(method)
|
||||
}));
|
||||
method => method.PaymentId.ToStringNormalized(),
|
||||
method => new GenericPaymentMethodData()
|
||||
{
|
||||
Enabled = enabled.GetValueOrDefault(!excludedPaymentMethods.Match(method.PaymentId)),
|
||||
Data = method.PaymentId.PaymentType.GetGreenfieldData(method)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "enabledOnly",
|
||||
"name": "enabled",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Fetch payment methods that are enable only",
|
||||
"description": "Fetch payment methods that are enabled/disabled only",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
|
|
|
@ -15,6 +15,15 @@
|
|||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "enabled",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Fetch payment methods that are enabled/disabled only",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
],
|
||||
"description": "View information about the stores' configured Lightning Network payment methods",
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "enabled",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Fetch payment methods that are enabled/disabled only",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
|
Loading…
Add table
Reference in a new issue