btcpayserver/BTCPayServer/PayoutProcessors/UIPayoutProcessorsController.cs
d11n d5d0be5824
Code formatting updates (#4502)
* Editorconfig: Add space_before_self_closing setting

This was a difference between the way dotnet-format and Rider format code. See https://www.jetbrains.com/help/rider/EditorConfig_Index.html

* Editorconfig: Keep 4 spaces indentation for Swagger JSON files

They are all formatted that way, let's keep it like that.

* Apply dotnet-format, mostly white-space related changes
2023-01-06 22:18:07 +09:00

90 lines
3.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Client;
using BTCPayServer.Data;
using BTCPayServer.Data.Data;
using BTCPayServer.Payments;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.PayoutProcessors;
public class UIPayoutProcessorsController : Controller
{
private readonly EventAggregator _eventAggregator;
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
private readonly IEnumerable<IPayoutProcessorFactory> _payoutProcessorFactories;
private readonly PayoutProcessorService _payoutProcessorService;
public UIPayoutProcessorsController(
EventAggregator eventAggregator,
BTCPayNetworkProvider btcPayNetworkProvider,
IEnumerable<IPayoutProcessorFactory> payoutProcessorFactories,
PayoutProcessorService payoutProcessorService)
{
_eventAggregator = eventAggregator;
_btcPayNetworkProvider = btcPayNetworkProvider;
_payoutProcessorFactories = payoutProcessorFactories;
_payoutProcessorService = payoutProcessorService;
;
}
[HttpGet("~/stores/{storeId}/payout-processors")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> ConfigureStorePayoutProcessors(string storeId)
{
var activeProcessors =
(await _payoutProcessorService.GetProcessors(
new PayoutProcessorService.PayoutProcessorQuery() { Stores = new[] { storeId } }))
.GroupBy(data => data.Processor);
var paymentMethods = HttpContext.GetStoreData().GetEnabledPaymentMethods(_btcPayNetworkProvider)
.Select(method => method.PaymentId).ToList();
return View(_payoutProcessorFactories.Select(factory =>
{
var conf = activeProcessors.FirstOrDefault(datas => datas.Key == factory.Processor)
?.ToDictionary(data => data.GetPaymentMethodId(), data => data) ??
new Dictionary<PaymentMethodId, PayoutProcessorData>();
foreach (PaymentMethodId supportedPaymentMethod in factory.GetSupportedPaymentMethods())
{
conf.TryAdd(supportedPaymentMethod, null);
}
return new StorePayoutProcessorsView() { Factory = factory, Configured = conf };
}).ToList());
}
[HttpPost("~/stores/{storeId}/payout-processors/{id}/remove")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> Remove(string storeId, string id)
{
var tcs = new TaskCompletionSource();
_eventAggregator.Publish(new PayoutProcessorUpdated()
{
Data = null,
Id = id,
Processed = tcs
});
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Severity = StatusMessageModel.StatusSeverity.Success,
Message = "Payout Processor removed"
});
await tcs.Task;
return RedirectToAction("ConfigureStorePayoutProcessors", new { storeId });
}
public class StorePayoutProcessorsView
{
public Dictionary<PaymentMethodId, PayoutProcessorData> Configured { get; set; }
public IPayoutProcessorFactory Factory { get; set; }
}
}