1use serde::{Deserialize, Serialize};
4use url::Url;
5
6use crate::serde_utils::{opt_serde_timestamp, opt_serde_url, serde_url};
7
8#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
10pub enum WebhookEvent {
11 #[serde(rename = "new")]
12 New,
13 #[serde(rename = "pending_confirmation")]
14 PendingConfirmation,
15 #[serde(rename = "paid")]
16 Paid,
17 #[serde(rename = "expired")]
18 Expired,
19 #[serde(rename = "cancelled")]
20 Cancelled,
21 #[serde(rename = "underpaid")]
22 Underpaid,
23 #[serde(rename = "overpaid")]
24 Overpaid,
25 #[serde(rename = "in_flight")]
26 InFlight,
27}
28
29#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
31pub enum WebHookType {
32 #[serde(rename = "store")]
33 Store,
34 #[serde(rename = "donation_page")]
35 DonationPage,
36 #[serde(rename = "paywall")]
37 Paywall,
38 #[serde(rename = "inbox")]
39 Inbox,
40}
41
42#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
44pub enum WebhookStatus {
45 #[serde(rename = "active")]
46 Active,
47 #[serde(rename = "inactive")]
48 Inactive,
49}
50
51#[derive(Clone, Debug, Deserialize, Serialize)]
53pub struct CreateWebhook {
54 #[serde(rename = "type")]
55 pub type_: WebHookType,
56 #[serde(with = "serde_url")]
57 pub url: Url,
58 pub events: Vec<WebhookEvent>,
59 pub secret: String,
60 pub status: WebhookStatus,
61}
62
63#[derive(Clone, Debug, Deserialize, Serialize)]
65pub struct Webhook {
66 pub id: Option<String>,
67 pub secret: Option<String>,
68 pub status: Option<WebhookStatus>,
69 pub events: Option<Vec<WebhookEvent>>,
70 #[serde(with = "opt_serde_url")]
71 pub url: Option<Url>,
72 #[serde(with = "opt_serde_timestamp")]
73 #[serde(rename = "createdAt")]
74 pub created_at: Option<i64>,
75 #[serde(with = "opt_serde_timestamp")]
76 #[serde(rename = "lastDeliveryAt")]
77 pub last_delivery_at: Option<i64>,
78}