btcpayserver/BTCPayServer/Views/UIStorePullPayments/Payouts.cshtml
2022-09-09 14:27:49 +09:00

209 lines
9.2 KiB
Plaintext

@using BTCPayServer.Client.Models
@using BTCPayServer.Payments
@using BTCPayServer.Views.Stores
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Client
@using BTCPayServer.PayoutProcessors
@model BTCPayServer.Models.WalletViewModels.PayoutsModel
@inject IEnumerable<IPayoutHandler> PayoutHandlers;
@inject PayoutProcessorService _payoutProcessorService;
@inject IEnumerable<IPayoutProcessorFactory> _payoutProcessorFactories;
@{
var storeId = Context.GetRouteValue("storeId") as string;
ViewData.SetActivePage(StoreNavPages.Payouts, $"Payouts{(string.IsNullOrEmpty(Model.PullPaymentName) ? string.Empty : " for pull payment " + Model.PullPaymentName)}", Context.GetStoreData().Id);
Model.PaginationQuery ??= new Dictionary<string, object>();
Model.PaginationQuery.Add("pullPaymentId", Model.PullPaymentId);
Model.PaginationQuery.Add("paymentMethodId", Model.PaymentMethodId);
Model.PaginationQuery.Add("payoutState", Model.PayoutState);
var stateActions = new List<(string Action, string Text)>();
if (PaymentMethodId.TryParse(Model.PaymentMethodId, out var paymentMethodId))
{
var payoutHandler = PayoutHandlers.FindPayoutHandler(paymentMethodId);
if (payoutHandler is null)
return;
stateActions.AddRange(payoutHandler.GetPayoutSpecificActions().Where(pair => pair.Key == Model.PayoutState).SelectMany(pair => pair.Value));
}
switch (Model.PayoutState)
{
case PayoutState.AwaitingApproval:
stateActions.Add(("approve", "Approve selected payouts"));
stateActions.Add(("approve-pay", "Approve & Send selected payouts"));
stateActions.Add(("cancel", "Cancel selected payouts"));
break;
case PayoutState.AwaitingPayment:
stateActions.Add(("pay", "Send selected payouts"));
stateActions.Add(("cancel", "Cancel selected payouts"));
stateActions.Add(("mark-paid", "Mark selected payouts as already paid"));
break;
}
}
@section PageHeadContent {
<style>
#Payouts .badge.rounded-pill {
font-size: var(--btcpay-font-size-s);
color: inherit;
}
</style>
}
@section PageFootContent {
<script>
delegate('click', '.selectAll', e => {
const { payoutState } = e.target.dataset;
document.querySelectorAll(`.selection-item-${payoutState}`).forEach(checkbox => {
checkbox.checked = e.target.checked;
});
});
</script>
}
<partial name="_StatusMessage"/>
@if (_payoutProcessorFactories.Any(factory => factory.GetSupportedPaymentMethods().Contains(paymentMethodId)) && !(await _payoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery()
{
Stores = new[] {storeId},
PaymentMethods = new[] {Model.PaymentMethodId}
})).Any())
{
<div class="alert alert-info mb-5" role="alert">
<strong>Pro tip:</strong> There are supported but unconfigured Payout Processors for this payout payment method.<br/>
Payout Processors help automate payouts so that you do not need to manually handle them.
<a class="alert-link p-0" asp-action="ConfigureStorePayoutProcessors" asp-controller="UIPayoutProcessors" asp-route-storeId="@storeId">Configure now</a>
</div>
}
<h2 class="mt-1 mb-4">
@ViewData["Title"]
<small>
<a href="https://docs.btcpayserver.org/Payouts/" target="_blank" rel="noreferrer noopener">
<span class="fa fa-question-circle-o text-secondary" title="More information..."></span>
</a>
</small>
</h2>
<form method="post" id="Payouts">
<input type="hidden" asp-for="PaymentMethodId"/>
<input type="hidden" asp-for="PayoutState"/>
<div class="d-flex justify-content-between mb-4">
<ul class="nav mb-1">
@foreach (var state in Model.PaymentMethods)
{
<li class="nav-item py-0">
<a asp-action="Payouts" asp-route-storeId="@Context.GetRouteValue("storeId")"
asp-route-payoutState="@Model.PayoutState"
asp-route-paymentMethodId="@state.ToString()"
asp-route-pullPaymentId="@Model.PullPaymentId"
class="btcpay-pill position-relative @(state.ToString() == Model.PaymentMethodId ? "active" : "")"
id="@state.ToString()-view"
role="tab">
@state.ToPrettyString()
@if (Model.PaymentMethodCount.TryGetValue(state.ToString(), out var count) && count > 0)
{
<span class="badge rounded-pill fw-semibold pe-0">@count</span>
}
</a>
</li>
}
</ul>
@if (Model.Payouts.Any() && stateActions.Any())
{
<div class="dropdown ms-xl-auto mt-xl-0" permission="@Policies.CanModifyStoreSettings">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" id="@Model.PayoutState-actions">Actions</button>
<div class="dropdown-menu" aria-labelledby="@Model.PayoutState-actions">
@foreach (var action in stateActions)
{
<button type="submit" id="@Model.PayoutState-@action.Action" name="Command" class="dropdown-item" role="button" value="@Model.PayoutState-@action.Action">@action.Text</button>
}
</div>
</div>
}
</div>
<nav id="SectionNav" class="mb-3">
<div class="nav">
@foreach (var state in Model.PayoutStateCount)
{
<a id="@state.Key-view"
asp-action="Payouts"
asp-route-storeId="@Context.GetRouteValue("storeId")"
asp-route-payoutState="@state.Key"
asp-route-pullPaymentId="@Model.PullPaymentId"
asp-route-paymentMethodId="@Model.PaymentMethodId"
class="nav-link @(state.Key == Model.PayoutState ? "active" : "")" role="tab">
@state.Key.GetStateString()
@if (state.Value > 0)
{
<span class="badge rounded-pill fw-semibold ms-1 bg-medium">@state.Value</span>
}
</a>
}
</div>
</nav>
@if (Model.Payouts.Any())
{
<div class="table-responsive">
<table class="table table-hover">
<thead class="thead-inverse">
<tr>
<th permission="@Policies.CanModifyStoreSettings">
<input id="@Model.PayoutState-selectAllCheckbox" type="checkbox" class="form-check-input selectAll" data-payout-state="@Model.PayoutState.ToString()"/>
</th>
<th style="min-width: 90px;" class="col-md-auto">
Date
</th>
<th class="text-start">Source</th>
<th class="text-start">Destination</th>
<th class="text-end">Amount</th>
@if (Model.PayoutState != PayoutState.AwaitingApproval)
{
<th class="text-end">Transaction</th>
}
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Payouts.Count; i++)
{
var pp = Model.Payouts[i];
<tr class="payout">
<td permission="@Policies.CanModifyStoreSettings">
<span>
<input type="checkbox" class="selection-item-@Model.PayoutState.ToString() form-check-input" asp-for="Payouts[i].Selected"/>
<input type="hidden" asp-for="Payouts[i].PayoutId"/>
</span>
</td>
<td>
<span>@pp.Date.ToBrowserDate()</span>
</td>
<td class="mw-100">
<span>@pp.PullPaymentName</span>
</td>
<td title="@pp.Destination">
<span class="text-break">@pp.Destination</span>
</td>
<td class="text-end text-nowrap">
<span>@pp.Amount</span>
</td>
@if (Model.PayoutState != PayoutState.AwaitingApproval)
{
<td class="text-end">
@if (!(pp.ProofLink is null))
{
<a class="transaction-link" href="@pp.ProofLink" rel="noreferrer noopener">Link</a>
}
</td>
}
</tr>
}
</tbody>
</table>
</div>
<vc:pager view-model="Model"/>
}
else
{
<p class="text-muted mb-0" id="@Model.PayoutState-no-payouts">There are no payouts matching this criteria.</p>
}
</form>