Add UpdateLightningNetworkPaymentMethodRequest

This commit is contained in:
Umar Bolatov 2021-08-29 21:38:57 -07:00 committed by Andrew Camilleri
parent d39ec97b9a
commit 2f4e610900
4 changed files with 44 additions and 12 deletions

View File

@ -0,0 +1,20 @@
namespace BTCPayServer.Client.Models
{
public class UpdateLightningNetworkPaymentMethodRequest: LightningNetworkPaymentMethodBaseData
{
/// <summary>
/// Whether the payment method is enabled
/// </summary>
public bool Enabled { get; set; }
public UpdateLightningNetworkPaymentMethodRequest()
{
}
public UpdateLightningNetworkPaymentMethodRequest(string connectionString, bool enabled)
{
Enabled = enabled;
ConnectionString = connectionString;
}
}
}

View File

@ -771,7 +771,7 @@ namespace BTCPayServer.Controllers.GreenField
{
return GetFromActionResult<LightningNetworkPaymentMethodData>(await
_storeLightningNetworkPaymentMethodsController.UpdateLightningNetworkPaymentMethod(storeId, cryptoCode,
paymentMethod));
new UpdateLightningNetworkPaymentMethodRequest(paymentMethod.ConnectionString, paymentMethod.Enabled)));
}
public override async Task<IEnumerable<InvoiceData>> GetInvoices(string storeId, string[] orderId = null,

View File

@ -114,7 +114,7 @@ namespace BTCPayServer.Controllers.GreenField
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpPut("~/api/v1/stores/{storeId}/payment-methods/LightningNetwork/{cryptoCode}")]
public async Task<IActionResult> UpdateLightningNetworkPaymentMethod(string storeId, string cryptoCode,
[FromBody] LightningNetworkPaymentMethodData paymentMethodData)
[FromBody] UpdateLightningNetworkPaymentMethodRequest request)
{
var paymentMethodId = new PaymentMethodId(cryptoCode, PaymentTypes.LightningLike);
@ -123,7 +123,7 @@ namespace BTCPayServer.Controllers.GreenField
return NotFound();
}
if (string.IsNullOrEmpty(paymentMethodData.ConnectionString))
if (string.IsNullOrEmpty(request.ConnectionString))
{
ModelState.AddModelError(nameof(LightningNetworkPaymentMethodData.ConnectionString),
"Missing connectionString");
@ -133,13 +133,13 @@ namespace BTCPayServer.Controllers.GreenField
return this.CreateValidationError(ModelState);
LightningSupportedPaymentMethod? paymentMethod = null;
if (!string.IsNullOrEmpty(paymentMethodData!.ConnectionString))
if (!string.IsNullOrEmpty(request!.ConnectionString))
{
if (paymentMethodData.ConnectionString == LightningSupportedPaymentMethod.InternalNode)
if (request.ConnectionString == LightningSupportedPaymentMethod.InternalNode)
{
if (!await CanUseInternalLightning())
{
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
ModelState.AddModelError(nameof(request.ConnectionString),
$"You are not authorized to use the internal lightning node");
return this.CreateValidationError(ModelState);
}
@ -152,23 +152,23 @@ namespace BTCPayServer.Controllers.GreenField
}
else
{
if (!LightningConnectionString.TryParse(paymentMethodData.ConnectionString, false,
if (!LightningConnectionString.TryParse(request.ConnectionString, false,
out var connectionString, out var error))
{
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString), $"Invalid URL ({error})");
ModelState.AddModelError(nameof(request.ConnectionString), $"Invalid URL ({error})");
return this.CreateValidationError(ModelState);
}
if (connectionString.ConnectionType == LightningConnectionType.LndGRPC)
{
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
ModelState.AddModelError(nameof(request.ConnectionString),
$"BTCPay does not support gRPC connections");
return this.CreateValidationError(ModelState);
}
if (!await CanManageServer() && !connectionString.IsSafe())
{
ModelState.AddModelError(nameof(paymentMethodData.ConnectionString),
ModelState.AddModelError(nameof(request.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);
}
@ -184,7 +184,7 @@ namespace BTCPayServer.Controllers.GreenField
var store = Store;
var storeBlob = store.GetStoreBlob();
store.SetSupportedPaymentMethod(paymentMethodId, paymentMethod);
storeBlob.SetExcluded(paymentMethodId, !paymentMethodData.Enabled);
storeBlob.SetExcluded(paymentMethodId, !request.Enabled);
store.SetStoreBlob(storeBlob);
await _storeRepository.UpdateStore(store);
return Ok(GetExistingLightningLikePaymentMethod(cryptoCode, store));

View File

@ -136,7 +136,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningNetworkPaymentMethodData"
"$ref": "#/components/schemas/UpdateLightningNetworkPaymentMethodRequest"
}
}
},
@ -273,6 +273,18 @@
"description": "Crypto code of the payment method"
}
}
},
"UpdateLightningNetworkPaymentMethodRequest": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/LightningNetworkPaymentMethodBaseData"
},
"properties": {
"enabled": {
"type": "boolean",
"description": "Whether the payment method is enabled"
}
}
}
}
},