mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
Pull payment code improvements (#3756)
* Controller syntax improvements * Improve Payout Processors protip
This commit is contained in:
parent
533ae0ea89
commit
421a2b0cd9
@ -21,21 +21,18 @@ namespace BTCPayServer.Controllers
|
||||
public class UIPullPaymentController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContextFactory _dbContextFactory;
|
||||
private readonly BTCPayNetworkProvider _networkProvider;
|
||||
private readonly CurrencyNameTable _currencyNameTable;
|
||||
private readonly PullPaymentHostedService _pullPaymentHostedService;
|
||||
private readonly BTCPayNetworkJsonSerializerSettings _serializerSettings;
|
||||
private readonly IEnumerable<IPayoutHandler> _payoutHandlers;
|
||||
|
||||
public UIPullPaymentController(ApplicationDbContextFactory dbContextFactory,
|
||||
BTCPayNetworkProvider networkProvider,
|
||||
CurrencyNameTable currencyNameTable,
|
||||
PullPaymentHostedService pullPaymentHostedService,
|
||||
BTCPayNetworkJsonSerializerSettings serializerSettings,
|
||||
IEnumerable<IPayoutHandler> payoutHandlers)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
_networkProvider = networkProvider;
|
||||
_currencyNameTable = currencyNameTable;
|
||||
_pullPaymentHostedService = pullPaymentHostedService;
|
||||
_serializerSettings = serializerSettings;
|
||||
@ -64,7 +61,7 @@ namespace BTCPayServer.Controllers
|
||||
var totalPaid = payouts.Where(p => p.Entity.State != PayoutState.Cancelled).Select(p => p.Blob.Amount).Sum();
|
||||
var amountDue = blob.Limit - totalPaid;
|
||||
|
||||
ViewPullPaymentModel vm = new ViewPullPaymentModel(pp, DateTimeOffset.UtcNow)
|
||||
ViewPullPaymentModel vm = new (pp, DateTimeOffset.UtcNow)
|
||||
{
|
||||
AmountFormatted = _currencyNameTable.FormatCurrency(blob.Limit, blob.Currency),
|
||||
AmountCollected = totalPaid,
|
||||
@ -85,8 +82,8 @@ namespace BTCPayServer.Controllers
|
||||
Status = entity.Entity.State,
|
||||
Destination = entity.Blob.Destination,
|
||||
PaymentMethod = PaymentMethodId.Parse(entity.Entity.PaymentMethodId),
|
||||
Link = entity.ProofBlob?.Link,
|
||||
TransactionId = entity.ProofBlob?.Id
|
||||
Link = entity.ProofBlob.Link,
|
||||
TransactionId = entity.ProofBlob.Id
|
||||
}).ToList()
|
||||
};
|
||||
vm.IsPending &= vm.AmountDue > 0.0m;
|
||||
@ -111,10 +108,10 @@ namespace BTCPayServer.Controllers
|
||||
var payoutHandler = paymentMethodId is null ? null : _payoutHandlers.FindPayoutHandler(paymentMethodId);
|
||||
if (payoutHandler is null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.SelectedPaymentMethod), $"Invalid destination with selected payment method");
|
||||
ModelState.AddModelError(nameof(vm.SelectedPaymentMethod), "Invalid destination with selected payment method");
|
||||
return await ViewPullPayment(pullPaymentId);
|
||||
}
|
||||
var destination = await payoutHandler?.ParseAndValidateClaimDestination(paymentMethodId, vm.Destination, ppBlob);
|
||||
var destination = await payoutHandler.ParseAndValidateClaimDestination(paymentMethodId, vm.Destination, ppBlob);
|
||||
if (destination.destination is null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.Destination), destination.error ?? "Invalid destination with selected payment method");
|
||||
@ -123,8 +120,7 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
if (vm.ClaimedAmount == 0)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.ClaimedAmount),
|
||||
$"Amount is required");
|
||||
ModelState.AddModelError(nameof(vm.ClaimedAmount), "Amount is required");
|
||||
}
|
||||
else if (vm.ClaimedAmount != 0 && destination.destination.Amount != null && vm.ClaimedAmount != destination.destination.Amount)
|
||||
{
|
||||
@ -157,15 +153,14 @@ namespace BTCPayServer.Controllers
|
||||
}
|
||||
return await ViewPullPayment(pullPaymentId);
|
||||
}
|
||||
else
|
||||
|
||||
TempData.SetStatusMessageModel(new StatusMessageModel
|
||||
{
|
||||
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||
{
|
||||
Message = $"Your claim request of {_currencyNameTable.DisplayFormatCurrency(vm.ClaimedAmount, ppBlob.Currency)} to {vm.Destination} has been submitted and is awaiting {(result.PayoutData.State == PayoutState.AwaitingApproval? "approval": "payment")}.",
|
||||
Severity = StatusMessageModel.StatusSeverity.Success
|
||||
});
|
||||
}
|
||||
return RedirectToAction(nameof(ViewPullPayment), new { pullPaymentId = pullPaymentId });
|
||||
Message = $"Your claim request of {_currencyNameTable.DisplayFormatCurrency(vm.ClaimedAmount, ppBlob.Currency)} to {vm.Destination} has been submitted and is awaiting {(result.PayoutData.State == PayoutState.AwaitingApproval? "approval": "payment")}.",
|
||||
Severity = StatusMessageModel.StatusSeverity.Success
|
||||
});
|
||||
|
||||
return RedirectToAction(nameof(ViewPullPayment), new { pullPaymentId });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +62,9 @@
|
||||
PaymentMethods = new[] {Model.PaymentMethodId}
|
||||
})).Any())
|
||||
{
|
||||
<div class="alert alert-info text-break" role="alert">
|
||||
protip: BTCPay Server has detected that there are supported but unconfigured Payout Processors for this payout payment method. Payout processors can potentially help automate the the workflow of these payouts so that you do not need to manually handle them.
|
||||
<div class="alert alert-info mb-5" role="alert">
|
||||
<strong>Protip:</strong> BTCPay Server has detected that there are supported but unconfigured Payout Processors for this payout payment method.<br/>
|
||||
Payout Processors can help automate the the workflow of these 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>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user