mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Refactoring of Webhooks and Email Rules (#6954)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.HostedServices;
|
||||
using BTCPayServer.Services;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Plugins.Webhooks.TriggerProviders;
|
||||
|
||||
public class PayoutTriggerProvider(BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings) : WebhookTriggerProvider<PayoutEvent>
|
||||
{
|
||||
protected override async Task<JObject> GetEmailModel(WebhookTriggerContext<PayoutEvent> webhookTriggerContext)
|
||||
{
|
||||
var evt = webhookTriggerContext.Event;
|
||||
var blob = evt.Payout.GetBlob(btcPayNetworkJsonSerializerSettings);
|
||||
var model = await base.GetEmailModel(webhookTriggerContext);
|
||||
model["Payout"] = new JObject()
|
||||
{
|
||||
["Id"] = evt.Payout.Id,
|
||||
["PullPaymentId"] = evt.Payout.PullPaymentDataId,
|
||||
["Destination"] = evt.Payout.DedupId ?? blob.Destination,
|
||||
["State"] = evt.Payout.State.ToString(),
|
||||
["Metadata"] = blob.Metadata
|
||||
};
|
||||
return model;
|
||||
}
|
||||
protected override StoreWebhookEvent? GetWebhookEvent(PayoutEvent payoutEvent)
|
||||
{
|
||||
var webhookEvt = payoutEvent.Type switch
|
||||
{
|
||||
PayoutEvent.PayoutEventType.Created => new WebhookPayoutEvent(WebhookEventType.PayoutCreated, payoutEvent.Payout.StoreDataId),
|
||||
PayoutEvent.PayoutEventType.Approved => new WebhookPayoutEvent(WebhookEventType.PayoutApproved, payoutEvent.Payout.StoreDataId),
|
||||
PayoutEvent.PayoutEventType.Updated => new WebhookPayoutEvent(WebhookEventType.PayoutUpdated, payoutEvent.Payout.StoreDataId),
|
||||
_ => null
|
||||
};
|
||||
if (webhookEvt is null)
|
||||
return null;
|
||||
webhookEvt.PayoutId = payoutEvent.Payout.Id;
|
||||
webhookEvt.PayoutState = payoutEvent.Payout.State;
|
||||
webhookEvt.PullPaymentId = payoutEvent.Payout.PullPaymentDataId;
|
||||
return webhookEvt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user