Greenfield: Create Pull Request payoutMethods is now optional (#6396)

This commit is contained in:
Nicolas Dorier
2024-11-13 18:31:55 +09:00
committed by GitHub
parent 78f47516b8
commit fdbee350b8
3 changed files with 14 additions and 17 deletions

View File

@@ -131,26 +131,20 @@ namespace BTCPayServer.Controllers.Greenfield
{
ModelState.AddModelError(nameof(request.BOLT11Expiration), $"The BOLT11 expiration should be positive");
}
PayoutMethodId?[]? payoutMethods = null;
if (request.PayoutMethods is { } payoutMethodsStr)
var supported = _payoutHandlers.GetSupportedPayoutMethods(HttpContext.GetStoreData());
request.PayoutMethods ??= supported.Select(s => s.ToString()).ToArray();
for (int i = 0; i < request.PayoutMethods.Length; i++)
{
payoutMethods = payoutMethodsStr.Select(s =>
var pmi = request.PayoutMethods[i] is string pm ? PayoutMethodId.TryParse(pm) : null;
if (pmi is null || !supported.Contains(pmi))
{
PayoutMethodId.TryParse(s, out var pmi);
return pmi;
}).ToArray();
var supported = _payoutHandlers.GetSupportedPayoutMethods(HttpContext.GetStoreData());
for (int i = 0; i < payoutMethods.Length; i++)
{
if (!supported.Contains(payoutMethods[i]))
{
request.AddModelError(paymentRequest => paymentRequest.PayoutMethods[i], "Invalid or unsupported payment method", this);
}
request.AddModelError(paymentRequest => paymentRequest.PayoutMethods[i], "Invalid or unsupported payment method", this);
}
}
else
if (request.PayoutMethods.Length is 0)
{
ModelState.AddModelError(nameof(request.PayoutMethods), "This field is required");
ModelState.AddModelError(nameof(request.PayoutMethods), "At least one payout method is required");
}
if (!ModelState.IsValid)
return this.CreateValidationError(ModelState);

View File

@@ -112,6 +112,8 @@ namespace BTCPayServer.HostedServices
}
public Task<string> CreatePullPayment(string storeId, CreatePullPaymentRequest request)
{
if (request.PayoutMethods.Length == 0)
throw new InvalidOperationException("request.PayoutMethods should have at least one payout method");
return CreatePullPayment(new CreatePullPayment()
{
StartsAt = request.StartsAt,

View File

@@ -225,11 +225,12 @@
},
"payoutMethods": {
"type": "array",
"description": "The list of supported payout methods supported by this pull payment. Available options can be queried from the `StorePaymentMethods_GetStorePaymentMethods` endpoint",
"description": "The list of supported payout methods supported by this pull payment. Available options can be queried from the `StorePaymentMethods_GetStorePaymentMethods` endpoint. If `null`, all available payout methods will be supported.",
"items": {
"type": "string",
"example": "BTC"
}
},
"nullable": true
}
}
}