mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
make prism extendable in a different way
This commit is contained in:
@@ -26,7 +26,7 @@ else
|
||||
@if (NoPayoutProcessors)
|
||||
{
|
||||
<div class="alert alert-warning mb-5" role="alert">
|
||||
An automated payout procesor for Lightning is required in order to automate prism payouts.
|
||||
An automated payout processor for Lightning is required in order to automate prism payouts.
|
||||
<a class="alert-link p-0" href="@PayoutProcessorLink">Configure now</a>
|
||||
</div>
|
||||
}
|
||||
@@ -133,6 +133,10 @@ else
|
||||
<button type="button" class="btn btn-primary mx-2" id="add-prism" @onclick="CreateNewPrism">Add Prism</button>
|
||||
<button type="button" class="btn btn-primary mx-2" id="add-destination" @onclick="AddDestination">Add Destination</button>
|
||||
<button type="submit" class="btn btn-primary mx-2">Save</button>
|
||||
@if (PrismEditButtonsFilter is not null)
|
||||
{
|
||||
@((MarkupString)PrismEditButtonsFilter)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
@@ -181,10 +185,12 @@ else
|
||||
public PaymentMethodId pmi { get; set; } = new("BTC", LightningPaymentType.Instance);
|
||||
public bool NoPayoutProcessors { get; set; }
|
||||
|
||||
private string PrismEditButtonsFilter { get; set; }
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
PrismEditButtonsFilter = (await PluginHookService.ApplyFilter("prism-edit-buttons", "")) as string;
|
||||
PayoutProcessorLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "ConfigureStorePayoutProcessors", "UIPayoutProcessors", new {StoreId});
|
||||
LNAddressLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "EditLightningAddress", "UILNURL", new {StoreId});
|
||||
PayoutsLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "Payouts", "UIStorePullPayments", new {StoreId, payoutState = PayoutState.AwaitingPayment, paymentMethodId = pmi.ToString()});
|
||||
|
||||
@@ -406,36 +406,34 @@ namespace BTCPayServer.Plugins.Prism
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IClaimDestination dest = null;
|
||||
var dest2 = await _pluginHookService.ApplyFilter("prism-claim-destination", destinationSettings?.Destination??destination);
|
||||
|
||||
dest = dest2 switch
|
||||
{
|
||||
IClaimDestination claimDestination => claimDestination,
|
||||
string destStr when !string.IsNullOrEmpty(destStr) => new LNURLPayClaimDestinaton(destStr),
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (dest is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pmi = string.IsNullOrEmpty(destinationSettings?.PaymentMethodId) ||
|
||||
!PaymentMethodId.TryParse(destinationSettings?.PaymentMethodId, out var pmi2)
|
||||
? new PaymentMethodId("BTC", LightningPaymentType.Instance)
|
||||
: pmi2;
|
||||
var payout = await _pullPaymentHostedService.Claim(new ClaimRequest()
|
||||
|
||||
var claimRequest = new ClaimRequest()
|
||||
{
|
||||
Destination = dest,
|
||||
Destination = new LNURLPayClaimDestinaton(destinationSettings?.Destination??destination),
|
||||
PreApprove = true,
|
||||
StoreId = storeId,
|
||||
PaymentMethodId = pmi,
|
||||
Value = Money.Satoshis(payoutAmount).ToDecimal(MoneyUnit.BTC),
|
||||
});
|
||||
if (payout.Result == ClaimRequest.ClaimResult.Ok)
|
||||
Metadata = JObject.FromObject(new
|
||||
{
|
||||
prismSettings.PendingPayouts ??= new();
|
||||
Source = "Prism"
|
||||
})
|
||||
};
|
||||
claimRequest = (await _pluginHookService.ApplyFilter("prism-claim-create", claimRequest)) as ClaimRequest;
|
||||
|
||||
if (claimRequest is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var payout = await _pullPaymentHostedService.Claim(claimRequest);
|
||||
if (payout.Result != ClaimRequest.ClaimResult.Ok) continue;
|
||||
prismSettings.PendingPayouts ??= new Dictionary<string, PendingPayout>();
|
||||
prismSettings.PendingPayouts.Add(payout.PayoutData.Id,
|
||||
new PendingPayout(payoutAmount, reserveFee));
|
||||
var newAmount = amtMsats - (payoutAmount + reserveFee) * 1000;
|
||||
@@ -448,7 +446,6 @@ namespace BTCPayServer.Plugins.Prism
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user