creat payouts on cancel

This commit is contained in:
Kukks
2023-04-14 15:18:30 +02:00
parent d9dbee1347
commit db3917b60f
2 changed files with 14 additions and 4 deletions

View File

@@ -11,7 +11,7 @@
<PropertyGroup> <PropertyGroup>
<Product>LN Prism</Product> <Product>LN Prism</Product>
<Description>Automated value splits for lightning.</Description> <Description>Automated value splits for lightning.</Description>
<Version>1.0.4</Version> <Version>1.0.5</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->
<PropertyGroup> <PropertyGroup>

View File

@@ -262,6 +262,10 @@ namespace BTCPayServer.Plugins.Prism
} }
await UpdatePrismSettingsForStore(creditDestination.StoreId, prismSettings, true); await UpdatePrismSettingsForStore(creditDestination.StoreId, prismSettings, true);
if (await CreatePayouts(creditDestination.StoreId, prismSettings))
{
await UpdatePrismSettingsForStore(creditDestination.StoreId, prismSettings, true);
}
} }
} }
@@ -314,10 +318,12 @@ namespace BTCPayServer.Plugins.Prism
} }
await UpdatePrismSettingsForStore(address.StoreDataId, prismSettings, true); await UpdatePrismSettingsForStore(address.StoreDataId, prismSettings, true);
await CreatePayouts(address.StoreDataId, prismSettings); if (await CreatePayouts(address.StoreDataId, prismSettings))
{
await UpdatePrismSettingsForStore(address.StoreDataId, prismSettings, true); await UpdatePrismSettingsForStore(address.StoreDataId, prismSettings, true);
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
Logs.PayServer.LogWarning(e, "Error while processing prism event"); Logs.PayServer.LogWarning(e, "Error while processing prism event");
@@ -328,8 +334,9 @@ namespace BTCPayServer.Plugins.Prism
} }
} }
private async Task CreatePayouts(string storeId, PrismSettings prismSettings) private async Task<bool> CreatePayouts(string storeId, PrismSettings prismSettings)
{ {
var result = false;
foreach (var (destination, amtMsats) in prismSettings.DestinationBalance) foreach (var (destination, amtMsats) in prismSettings.DestinationBalance)
{ {
var amt = amtMsats / 1000; var amt = amtMsats / 1000;
@@ -357,9 +364,12 @@ namespace BTCPayServer.Plugins.Prism
new PendingPayout(payoutAmount, reserveFee)); new PendingPayout(payoutAmount, reserveFee));
prismSettings.DestinationBalance.AddOrReplace(destination, prismSettings.DestinationBalance.AddOrReplace(destination,
amtMsats - (payoutAmount + reserveFee) * 1000); amtMsats - (payoutAmount + reserveFee) * 1000);
result = true;
} }
} }
} }
return result;
} }
} }
} }