stripe/resources/generated/
event.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::EventId;
7use crate::params::{Expand, List, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::{EventType, NotificationEventData};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "NotificationEvent".
12///
13/// For more details see <https://stripe.com/docs/api/events/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Event {
16    /// Unique identifier for the object.
17    pub id: EventId,
18
19    /// The connected account that originates the event.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub account: Option<String>,
22
23    /// The Stripe API version used to render `data`.
24    ///
25    /// This property is populated only for events on or after October 31, 2014.
26    pub api_version: Option<String>,
27
28    /// Time at which the object was created.
29    ///
30    /// Measured in seconds since the Unix epoch.
31    pub created: Timestamp,
32
33    pub data: NotificationEventData,
34
35    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
36    pub livemode: bool,
37
38    /// Number of webhooks that haven't been successfully delivered (for example, to return a 20x response) to the URLs you specify.
39    pub pending_webhooks: i64,
40
41    /// Information on the API request that triggers the event.
42    pub request: Option<NotificationEventRequest>,
43
44    /// Description of the event (for example, `invoice.created` or `charge.refunded`).
45    #[serde(rename = "type")]
46    pub type_: EventType,
47}
48
49impl Event {
50    /// List events, going back up to 30 days.
51    ///
52    /// Each event data is rendered according to Stripe API version at its creation time, specified in [event object](https://stripe.com/docs/api/events/object) `api_version` attribute (not according to your current Stripe API version or `Stripe-Version` header).
53    pub fn list(client: &Client, params: &ListEvents<'_>) -> Response<List<Event>> {
54        client.get_query("/events", params)
55    }
56
57    /// Retrieves the details of an event.
58    ///
59    /// Supply the unique identifier of the event, which you might have received in a webhook.
60    pub fn retrieve(client: &Client, id: &EventId, expand: &[&str]) -> Response<Event> {
61        client.get_query(&format!("/events/{}", id), Expand { expand })
62    }
63}
64
65impl Object for Event {
66    type Id = EventId;
67    fn id(&self) -> Self::Id {
68        self.id.clone()
69    }
70    fn object(&self) -> &'static str {
71        "event"
72    }
73}
74
75#[derive(Clone, Debug, Default, Deserialize, Serialize)]
76pub struct NotificationEventRequest {
77    /// ID of the API request that caused the event.
78    ///
79    /// If null, the event was automatic (e.g., Stripe's automatic subscription handling).
80    /// Request logs are available in the [dashboard](https://dashboard.stripe.com/logs), but currently not in the API.
81    pub id: Option<String>,
82
83    /// The idempotency key transmitted during the request, if any.
84    ///
85    /// *Note: This property is populated only for events on or after May 23, 2017*.
86    pub idempotency_key: Option<String>,
87}
88
89/// The parameters for `Event::list`.
90#[derive(Clone, Debug, Serialize, Default)]
91pub struct ListEvents<'a> {
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub created: Option<RangeQuery<Timestamp>>,
94
95    /// Filter events by whether all webhooks were successfully delivered.
96    ///
97    /// If false, events which are still pending or have failed all delivery attempts to a webhook endpoint will be returned.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub delivery_success: Option<bool>,
100
101    /// A cursor for use in pagination.
102    ///
103    /// `ending_before` is an object ID that defines your place in the list.
104    /// 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.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub ending_before: Option<EventId>,
107
108    /// Specifies which fields in the response should be expanded.
109    #[serde(skip_serializing_if = "Expand::is_empty")]
110    pub expand: &'a [&'a str],
111
112    /// A limit on the number of objects to be returned.
113    ///
114    /// Limit can range between 1 and 100, and the default is 10.
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub limit: Option<u64>,
117
118    /// A cursor for use in pagination.
119    ///
120    /// `starting_after` is an object ID that defines your place in the list.
121    /// 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.
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub starting_after: Option<EventId>,
124
125    /// A string containing a specific event name, or group of events using * as a wildcard.
126    ///
127    /// The list will be filtered to include only events with a matching event property.
128    #[serde(rename = "type")]
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub type_: Option<&'a str>,
131
132    /// An array of up to 20 strings containing specific event names.
133    ///
134    /// The list will be filtered to include only events with a matching event property.
135    /// You may pass either `type` or `types`, but not both.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub types: Option<Vec<String>>,
138}
139
140impl<'a> ListEvents<'a> {
141    pub fn new() -> Self {
142        ListEvents {
143            created: Default::default(),
144            delivery_success: Default::default(),
145            ending_before: Default::default(),
146            expand: Default::default(),
147            limit: Default::default(),
148            starting_after: Default::default(),
149            type_: Default::default(),
150            types: Default::default(),
151        }
152    }
153}
154impl Paginable for ListEvents<'_> {
155    type O = Event;
156    fn set_last(&mut self, item: Self::O) {
157        self.starting_after = Some(item.id());
158    }
159}