Skip to main content

stripe_misc/webhook_endpoint/
types.rs

1/// You can configure [webhook endpoints](https://docs.stripe.com/webhooks/) via the API to be
2/// notified about events that happen in your Stripe account or connected
3/// accounts.
4///
5/// Most users configure webhooks from [the dashboard](https://dashboard.stripe.com/webhooks), which provides a user interface for registering and testing your webhook endpoints.
6///
7/// Related guide: [Setting up webhooks](https://docs.stripe.com/webhooks/configure)
8///
9/// For more details see <<https://stripe.com/docs/api/webhook_endpoints/object>>.
10#[derive(Clone)]
11#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
12#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
13pub struct WebhookEndpoint {
14    /// The API version events are rendered as for this webhook endpoint.
15    pub api_version: Option<String>,
16    /// The ID of the associated Connect application.
17    pub application: Option<String>,
18    /// Time at which the object was created. Measured in seconds since the Unix epoch.
19    pub created: stripe_types::Timestamp,
20    /// An optional description of what the webhook is used for.
21    pub description: Option<String>,
22    /// The list of events to enable for this endpoint.
23    /// `['*']` indicates that all events are enabled, except those that require explicit selection.
24    pub enabled_events: Vec<String>,
25    /// Unique identifier for the object.
26    pub id: stripe_misc::WebhookEndpointId,
27    /// If the object exists in live mode, the value is `true`.
28    /// If the object exists in test mode, the value is `false`.
29    pub livemode: bool,
30    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
31    /// This can be useful for storing additional information about the object in a structured format.
32    pub metadata: std::collections::HashMap<String, String>,
33    /// The endpoint's secret, used to generate [webhook signatures](https://docs.stripe.com/webhooks/signatures).
34    /// Only returned at creation.
35    pub secret: Option<String>,
36    /// The status of the webhook. It can be `enabled` or `disabled`.
37    pub status: String,
38    /// The URL of the webhook endpoint.
39    pub url: String,
40}
41#[cfg(feature = "redact-generated-debug")]
42impl std::fmt::Debug for WebhookEndpoint {
43    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
44        f.debug_struct("WebhookEndpoint").finish_non_exhaustive()
45    }
46}
47#[doc(hidden)]
48pub struct WebhookEndpointBuilder {
49    api_version: Option<Option<String>>,
50    application: Option<Option<String>>,
51    created: Option<stripe_types::Timestamp>,
52    description: Option<Option<String>>,
53    enabled_events: Option<Vec<String>>,
54    id: Option<stripe_misc::WebhookEndpointId>,
55    livemode: Option<bool>,
56    metadata: Option<std::collections::HashMap<String, String>>,
57    secret: Option<Option<String>>,
58    status: Option<String>,
59    url: Option<String>,
60}
61
62#[allow(
63    unused_variables,
64    irrefutable_let_patterns,
65    clippy::let_unit_value,
66    clippy::match_single_binding,
67    clippy::single_match
68)]
69const _: () = {
70    use miniserde::de::{Map, Visitor};
71    use miniserde::json::Value;
72    use miniserde::{Deserialize, Result, make_place};
73    use stripe_types::miniserde_helpers::FromValueOpt;
74    use stripe_types::{MapBuilder, ObjectDeser};
75
76    make_place!(Place);
77
78    impl Deserialize for WebhookEndpoint {
79        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
80            Place::new(out)
81        }
82    }
83
84    struct Builder<'a> {
85        out: &'a mut Option<WebhookEndpoint>,
86        builder: WebhookEndpointBuilder,
87    }
88
89    impl Visitor for Place<WebhookEndpoint> {
90        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
91            Ok(Box::new(Builder {
92                out: &mut self.out,
93                builder: WebhookEndpointBuilder::deser_default(),
94            }))
95        }
96    }
97
98    impl MapBuilder for WebhookEndpointBuilder {
99        type Out = WebhookEndpoint;
100        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
101            Ok(match k {
102                "api_version" => Deserialize::begin(&mut self.api_version),
103                "application" => Deserialize::begin(&mut self.application),
104                "created" => Deserialize::begin(&mut self.created),
105                "description" => Deserialize::begin(&mut self.description),
106                "enabled_events" => Deserialize::begin(&mut self.enabled_events),
107                "id" => Deserialize::begin(&mut self.id),
108                "livemode" => Deserialize::begin(&mut self.livemode),
109                "metadata" => Deserialize::begin(&mut self.metadata),
110                "secret" => Deserialize::begin(&mut self.secret),
111                "status" => Deserialize::begin(&mut self.status),
112                "url" => Deserialize::begin(&mut self.url),
113                _ => <dyn Visitor>::ignore(),
114            })
115        }
116
117        fn deser_default() -> Self {
118            Self {
119                api_version: Some(None),
120                application: Some(None),
121                created: None,
122                description: Some(None),
123                enabled_events: None,
124                id: None,
125                livemode: None,
126                metadata: None,
127                secret: Some(None),
128                status: None,
129                url: None,
130            }
131        }
132
133        fn take_out(&mut self) -> Option<Self::Out> {
134            let (
135                Some(api_version),
136                Some(application),
137                Some(created),
138                Some(description),
139                Some(enabled_events),
140                Some(id),
141                Some(livemode),
142                Some(metadata),
143                Some(secret),
144                Some(status),
145                Some(url),
146            ) = (
147                self.api_version.take(),
148                self.application.take(),
149                self.created,
150                self.description.take(),
151                self.enabled_events.take(),
152                self.id.take(),
153                self.livemode,
154                self.metadata.take(),
155                self.secret.take(),
156                self.status.take(),
157                self.url.take(),
158            )
159            else {
160                return None;
161            };
162            Some(Self::Out {
163                api_version,
164                application,
165                created,
166                description,
167                enabled_events,
168                id,
169                livemode,
170                metadata,
171                secret,
172                status,
173                url,
174            })
175        }
176    }
177
178    impl Map for Builder<'_> {
179        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
180            self.builder.key(k)
181        }
182
183        fn finish(&mut self) -> Result<()> {
184            *self.out = self.builder.take_out();
185            Ok(())
186        }
187    }
188
189    impl ObjectDeser for WebhookEndpoint {
190        type Builder = WebhookEndpointBuilder;
191    }
192
193    impl FromValueOpt for WebhookEndpoint {
194        fn from_value(v: Value) -> Option<Self> {
195            let Value::Object(obj) = v else {
196                return None;
197            };
198            let mut b = WebhookEndpointBuilder::deser_default();
199            for (k, v) in obj {
200                match k.as_str() {
201                    "api_version" => b.api_version = FromValueOpt::from_value(v),
202                    "application" => b.application = FromValueOpt::from_value(v),
203                    "created" => b.created = FromValueOpt::from_value(v),
204                    "description" => b.description = FromValueOpt::from_value(v),
205                    "enabled_events" => b.enabled_events = FromValueOpt::from_value(v),
206                    "id" => b.id = FromValueOpt::from_value(v),
207                    "livemode" => b.livemode = FromValueOpt::from_value(v),
208                    "metadata" => b.metadata = FromValueOpt::from_value(v),
209                    "secret" => b.secret = FromValueOpt::from_value(v),
210                    "status" => b.status = FromValueOpt::from_value(v),
211                    "url" => b.url = FromValueOpt::from_value(v),
212                    _ => {}
213                }
214            }
215            b.take_out()
216        }
217    }
218};
219#[cfg(feature = "serialize")]
220impl serde::Serialize for WebhookEndpoint {
221    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
222        use serde::ser::SerializeStruct;
223        let mut s = s.serialize_struct("WebhookEndpoint", 12)?;
224        s.serialize_field("api_version", &self.api_version)?;
225        s.serialize_field("application", &self.application)?;
226        s.serialize_field("created", &self.created)?;
227        s.serialize_field("description", &self.description)?;
228        s.serialize_field("enabled_events", &self.enabled_events)?;
229        s.serialize_field("id", &self.id)?;
230        s.serialize_field("livemode", &self.livemode)?;
231        s.serialize_field("metadata", &self.metadata)?;
232        s.serialize_field("secret", &self.secret)?;
233        s.serialize_field("status", &self.status)?;
234        s.serialize_field("url", &self.url)?;
235
236        s.serialize_field("object", "webhook_endpoint")?;
237        s.end()
238    }
239}
240impl stripe_types::Object for WebhookEndpoint {
241    type Id = stripe_misc::WebhookEndpointId;
242    fn id(&self) -> &Self::Id {
243        &self.id
244    }
245
246    fn into_id(self) -> Self::Id {
247        self.id
248    }
249}
250stripe_types::def_id!(WebhookEndpointId);