Skip to main content

pretix_webhook/
handler.rs

1use std::{fmt::Display, future::Future};
2
3use pretix_webhook_events::WebhookEvent;
4
5/// Processes authenticated, parsed webhook events that passed their filters.
6pub trait WebhookHandler: Send + Sync + 'static {
7    /// The failure returned when an accepted event cannot be processed.
8    type Error: Display + Send + Sync + 'static;
9
10    /// Processes one accepted event.
11    ///
12    /// # Errors
13    ///
14    /// Returning an error produces a `500 Internal Server Error` response so
15    /// pretix can retry the delivery.
16    fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send;
17}
18
19impl<F, Fut, E> WebhookHandler for F
20where
21    F: Fn(WebhookEvent) -> Fut + Send + Sync + 'static,
22    Fut: Future<Output = Result<(), E>> + Send,
23    E: Display + Send + Sync + 'static,
24{
25    type Error = E;
26
27    fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send {
28        (self)(event)
29    }
30}