stripe_shared/
notification_event_request.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct NotificationEventRequest {
5    /// ID of the API request that caused the event.
6    /// If null, the event was automatic (e.g., Stripe's automatic subscription handling).
7    /// Request logs are available in the [dashboard](https://dashboard.stripe.com/logs), but currently not in the API.
8    pub id: Option<String>,
9    /// The idempotency key transmitted during the request, if any.
10    /// *Note: This property is populated only for events on or after May 23, 2017*.
11    pub idempotency_key: Option<String>,
12}
13#[doc(hidden)]
14pub struct NotificationEventRequestBuilder {
15    id: Option<Option<String>>,
16    idempotency_key: Option<Option<String>>,
17}
18
19#[allow(
20    unused_variables,
21    irrefutable_let_patterns,
22    clippy::let_unit_value,
23    clippy::match_single_binding,
24    clippy::single_match
25)]
26const _: () = {
27    use miniserde::de::{Map, Visitor};
28    use miniserde::json::Value;
29    use miniserde::{Deserialize, Result, make_place};
30    use stripe_types::miniserde_helpers::FromValueOpt;
31    use stripe_types::{MapBuilder, ObjectDeser};
32
33    make_place!(Place);
34
35    impl Deserialize for NotificationEventRequest {
36        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37            Place::new(out)
38        }
39    }
40
41    struct Builder<'a> {
42        out: &'a mut Option<NotificationEventRequest>,
43        builder: NotificationEventRequestBuilder,
44    }
45
46    impl Visitor for Place<NotificationEventRequest> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: NotificationEventRequestBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for NotificationEventRequestBuilder {
56        type Out = NotificationEventRequest;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "id" => Deserialize::begin(&mut self.id),
60                "idempotency_key" => Deserialize::begin(&mut self.idempotency_key),
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self { id: Deserialize::default(), idempotency_key: Deserialize::default() }
67        }
68
69        fn take_out(&mut self) -> Option<Self::Out> {
70            let (Some(id), Some(idempotency_key)) = (self.id.take(), self.idempotency_key.take())
71            else {
72                return None;
73            };
74            Some(Self::Out { id, idempotency_key })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for NotificationEventRequest {
90        type Builder = NotificationEventRequestBuilder;
91    }
92
93    impl FromValueOpt for NotificationEventRequest {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = NotificationEventRequestBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "id" => b.id = FromValueOpt::from_value(v),
102                    "idempotency_key" => b.idempotency_key = FromValueOpt::from_value(v),
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};