mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
51690b47a3
* Automated Transfer processors This PR introduces a few things: * Payouts can now be directly nested under a store instead of through a pull payment. * The Wallet Send screen now has an option to "schedule" instead of simply creating a transaction. When you click on schedule, all transaction destinations are converted into approved payouts. Any options relating to fees or coin selection are discarded. * There is a new concept introduced, called "Transfer Processors". Transfer Processors are services for stores that process payouts that are awaiting payment. Each processor specifies which payment methods it can handle. BTCPay Server will have some forms of transfer processors baked in but it has been designed to allow the Plugin System to provide additional processors. * The initial transfer processors provided are "automated processors", for on chain and lightning payment methods. They can be configured to process payouts every X amount of minutes. For on-chain, this means payments are batched into one transaction, resulting in more efficient and cheaper fees for processing. * * fix build * extract * remove magic string stuff * fix error message when scheduling * Paginate migration * add payout count to payment method tab * remove unused var * add protip * optimzie payout migration dramatically * Remove useless double condition * Fix bunch of warnings * Remove warning * Remove warnigns * Rename to Payout processors * fix typo Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
73 lines
2.9 KiB
C#
73 lines
2.9 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Abstractions.Constants;
|
|
using BTCPayServer.Client;
|
|
using BTCPayServer.Client.Models;
|
|
using BTCPayServer.PayoutProcessors;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServer.Controllers.Greenfield
|
|
{
|
|
[ApiController]
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public class GreenfieldStorePayoutProcessorsController : ControllerBase
|
|
{
|
|
private readonly PayoutProcessorService _payoutProcessorService;
|
|
private readonly IEnumerable<IPayoutProcessorFactory> _factories;
|
|
public GreenfieldStorePayoutProcessorsController(PayoutProcessorService payoutProcessorService, IEnumerable<IPayoutProcessorFactory> factories)
|
|
{
|
|
_payoutProcessorService = payoutProcessorService;
|
|
_factories = factories;
|
|
}
|
|
|
|
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
[HttpGet("~/api/v1/stores/{storeId}/payout-processors")]
|
|
public async Task<IActionResult> GetStorePayoutProcessors(
|
|
string storeId)
|
|
{
|
|
var configured =
|
|
(await _payoutProcessorService.GetProcessors(
|
|
new PayoutProcessorService.PayoutProcessorQuery() { Stores = new[] { storeId } }))
|
|
.GroupBy(data => data.Processor).Select(datas => new PayoutProcessorData()
|
|
{
|
|
Name = datas.Key,
|
|
FriendlyName = _factories.FirstOrDefault(factory => factory.Processor == datas.Key)?.FriendlyName,
|
|
PaymentMethods = datas.Select(data => data.PaymentMethod).ToArray()
|
|
});
|
|
return Ok(configured);
|
|
|
|
}
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
[HttpDelete("~/api/v1/stores/{storeId}/payout-processors/{processor}/{paymentMethod}")]
|
|
public async Task<IActionResult> RemoveStorePayoutProcessor(
|
|
string storeId,string processor,string paymentMethod)
|
|
{
|
|
var matched =
|
|
(await _payoutProcessorService.GetProcessors(
|
|
new PayoutProcessorService.PayoutProcessorQuery()
|
|
{
|
|
Stores = new[] { storeId },
|
|
Processors = new []{ processor},
|
|
PaymentMethods = new []{paymentMethod}
|
|
})).FirstOrDefault();
|
|
if (matched is null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var tcs = new TaskCompletionSource();
|
|
_payoutProcessorService.EventAggregator.Publish(new PayoutProcessorUpdated()
|
|
{
|
|
Id = matched.Id,
|
|
Processed = tcs
|
|
});
|
|
await tcs.Task;
|
|
return Ok();
|
|
|
|
}
|
|
}
|
|
}
|