Add "stores/{storeId}/payment-methods" endpoint

address #2545
This commit is contained in:
Umar Bolatov
2021-06-01 20:49:58 -07:00
committed by Andrew Camilleri
parent b7b2f16925
commit 17e6179fec
3 changed files with 65 additions and 16 deletions

View File

@@ -36,22 +36,27 @@ namespace BTCPayServer.Controllers.GreenField
_walletProvider = walletProvider;
}
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/stores/{storeId}/payment-methods/onchain")]
public ActionResult<IEnumerable<OnChainPaymentMethodData>> GetOnChainPaymentMethods(
[FromQuery] bool enabledOnly = false)
public static IEnumerable<OnChainPaymentMethodData> GetOnChainPaymentMethods(StoreData store, BTCPayNetworkProvider networkProvider, bool enabledOnly = false)
{
var blob = Store.GetStoreBlob();
var blob = store.GetStoreBlob();
var excludedPaymentMethods = blob.GetExcludedPaymentMethods();
return Ok(Store.GetSupportedPaymentMethods(_btcPayNetworkProvider)
return store.GetSupportedPaymentMethods(networkProvider)
.Where((method) => method.PaymentId.PaymentType == PaymentTypes.BTCLike)
.OfType<DerivationSchemeSettings>()
.Select(strategy =>
new OnChainPaymentMethodData(strategy.PaymentId.CryptoCode,
strategy.AccountDerivation.ToString(), !excludedPaymentMethods.Match(strategy.PaymentId)))
.Where((result) => !enabledOnly || result.Enabled)
.ToList()
);
.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)
{
return Ok(GetOnChainPaymentMethods(Store, _btcPayNetworkProvider, enabledOnly));
}
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]