mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
* wip * Local GreenField Client for Plugins * support notification handlers being missing * Initial support for scoped btcpay client * test out scoped local client * wip * small fix * Throw exception if using local greenfield client and it has not been implemented yet * adapt based on new changes in BTCPay * update * fix tests * Allow Local client to bypass authorization handler * Add Misc endpoints to Local API Client * Add new endpoints * Apply code review changes
46 lines
1.9 KiB
C#
46 lines
1.9 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BTCPayServer.Abstractions.Constants;
|
|
using BTCPayServer.Client;
|
|
using BTCPayServer.Client.Models;
|
|
using BTCPayServer.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using StoreData = BTCPayServer.Data.StoreData;
|
|
|
|
namespace BTCPayServer.Controllers.GreenField
|
|
{
|
|
[ApiController]
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public class StorePaymentMethodsController : ControllerBase
|
|
{
|
|
private StoreData Store => HttpContext.GetStoreData();
|
|
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
|
|
|
public StorePaymentMethodsController(BTCPayNetworkProvider btcPayNetworkProvider)
|
|
{
|
|
_btcPayNetworkProvider = btcPayNetworkProvider;
|
|
}
|
|
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
[HttpGet("~/api/v1/stores/{storeId}/payment-methods")]
|
|
public ActionResult<Dictionary<string, GenericPaymentMethodData>> GetStorePaymentMethods(
|
|
string storeId,
|
|
[FromQuery] bool? enabled)
|
|
{
|
|
var storeBlob = Store.GetStoreBlob();
|
|
var excludedPaymentMethods = storeBlob.GetExcludedPaymentMethods();
|
|
return Ok(Store.GetSupportedPaymentMethods(_btcPayNetworkProvider)
|
|
.Where(method =>
|
|
enabled is null || (enabled is false && excludedPaymentMethods.Match(method.PaymentId)))
|
|
.ToDictionary(
|
|
method => method.PaymentId.ToStringNormalized(),
|
|
method => new GenericPaymentMethodData()
|
|
{
|
|
Enabled = enabled.GetValueOrDefault(!excludedPaymentMethods.Match(method.PaymentId)),
|
|
Data = method.PaymentId.PaymentType.GetGreenfieldData(method)
|
|
}));
|
|
}
|
|
}
|
|
}
|