stripe_core/event/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListEventBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    created: Option<stripe_types::RangeQueryTs>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    delivery_success: Option<bool>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    ending_before: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    expand: Option<Vec<String>>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    limit: Option<i64>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    starting_after: Option<String>,
19    #[serde(rename = "type")]
20    #[serde(skip_serializing_if = "Option::is_none")]
21    type_: Option<String>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    types: Option<Vec<String>>,
24}
25impl ListEventBuilder {
26    fn new() -> Self {
27        Self {
28            created: None,
29            delivery_success: None,
30            ending_before: None,
31            expand: None,
32            limit: None,
33            starting_after: None,
34            type_: None,
35            types: None,
36        }
37    }
38}
39/// List events, going back up to 30 days.
40/// Each event data is rendered according to Stripe API version at its creation time, specified in [event object](https://docs.stripe.com/api/events/object) `api_version` attribute (not according to your current Stripe API version or `Stripe-Version` header).
41#[derive(Clone, Debug, serde::Serialize)]
42pub struct ListEvent {
43    inner: ListEventBuilder,
44}
45impl ListEvent {
46    /// Construct a new `ListEvent`.
47    pub fn new() -> Self {
48        Self { inner: ListEventBuilder::new() }
49    }
50    /// Only return events that were created during the given date interval.
51    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
52        self.inner.created = Some(created.into());
53        self
54    }
55    /// Filter events by whether all webhooks were successfully delivered.
56    /// If false, events which are still pending or have failed all delivery attempts to a webhook endpoint will be returned.
57    pub fn delivery_success(mut self, delivery_success: impl Into<bool>) -> Self {
58        self.inner.delivery_success = Some(delivery_success.into());
59        self
60    }
61    /// A cursor for use in pagination.
62    /// `ending_before` is an object ID that defines your place in the list.
63    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
64    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
65        self.inner.ending_before = Some(ending_before.into());
66        self
67    }
68    /// Specifies which fields in the response should be expanded.
69    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
70        self.inner.expand = Some(expand.into());
71        self
72    }
73    /// A limit on the number of objects to be returned.
74    /// Limit can range between 1 and 100, and the default is 10.
75    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
76        self.inner.limit = Some(limit.into());
77        self
78    }
79    /// A cursor for use in pagination.
80    /// `starting_after` is an object ID that defines your place in the list.
81    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
82    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
83        self.inner.starting_after = Some(starting_after.into());
84        self
85    }
86    /// A string containing a specific event name, or group of events using * as a wildcard.
87    /// The list will be filtered to include only events with a matching event property.
88    pub fn type_(mut self, type_: impl Into<String>) -> Self {
89        self.inner.type_ = Some(type_.into());
90        self
91    }
92    /// An array of up to 20 strings containing specific event names.
93    /// The list will be filtered to include only events with a matching event property.
94    /// You may pass either `type` or `types`, but not both.
95    pub fn types(mut self, types: impl Into<Vec<String>>) -> Self {
96        self.inner.types = Some(types.into());
97        self
98    }
99}
100impl Default for ListEvent {
101    fn default() -> Self {
102        Self::new()
103    }
104}
105impl ListEvent {
106    /// Send the request and return the deserialized response.
107    pub async fn send<C: StripeClient>(
108        &self,
109        client: &C,
110    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
111        self.customize().send(client).await
112    }
113
114    /// Send the request and return the deserialized response, blocking until completion.
115    pub fn send_blocking<C: StripeBlockingClient>(
116        &self,
117        client: &C,
118    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
119        self.customize().send_blocking(client)
120    }
121
122    pub fn paginate(
123        &self,
124    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::Event>> {
125        stripe_client_core::ListPaginator::new_list("/events", &self.inner)
126    }
127}
128
129impl StripeRequest for ListEvent {
130    type Output = stripe_types::List<stripe_shared::Event>;
131
132    fn build(&self) -> RequestBuilder {
133        RequestBuilder::new(StripeMethod::Get, "/events").query(&self.inner)
134    }
135}
136#[derive(Clone, Debug, serde::Serialize)]
137struct RetrieveEventBuilder {
138    #[serde(skip_serializing_if = "Option::is_none")]
139    expand: Option<Vec<String>>,
140}
141impl RetrieveEventBuilder {
142    fn new() -> Self {
143        Self { expand: None }
144    }
145}
146/// Retrieves the details of an event if it was created in the last 30 days.
147/// Supply the unique identifier of the event, which you might have received in a webhook.
148#[derive(Clone, Debug, serde::Serialize)]
149pub struct RetrieveEvent {
150    inner: RetrieveEventBuilder,
151    id: stripe_shared::EventId,
152}
153impl RetrieveEvent {
154    /// Construct a new `RetrieveEvent`.
155    pub fn new(id: impl Into<stripe_shared::EventId>) -> Self {
156        Self { id: id.into(), inner: RetrieveEventBuilder::new() }
157    }
158    /// Specifies which fields in the response should be expanded.
159    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
160        self.inner.expand = Some(expand.into());
161        self
162    }
163}
164impl RetrieveEvent {
165    /// Send the request and return the deserialized response.
166    pub async fn send<C: StripeClient>(
167        &self,
168        client: &C,
169    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
170        self.customize().send(client).await
171    }
172
173    /// Send the request and return the deserialized response, blocking until completion.
174    pub fn send_blocking<C: StripeBlockingClient>(
175        &self,
176        client: &C,
177    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
178        self.customize().send_blocking(client)
179    }
180}
181
182impl StripeRequest for RetrieveEvent {
183    type Output = stripe_shared::Event;
184
185    fn build(&self) -> RequestBuilder {
186        let id = &self.id;
187        RequestBuilder::new(StripeMethod::Get, format!("/events/{id}")).query(&self.inner)
188    }
189}