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::{make_place, Deserialize, Result};
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
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self { id: Deserialize::default(), idempotency_key: Deserialize::default() }
68        }
69
70        fn take_out(&mut self) -> Option<Self::Out> {
71            let (Some(id), Some(idempotency_key)) = (self.id.take(), self.idempotency_key.take())
72            else {
73                return None;
74            };
75            Some(Self::Out { id, idempotency_key })
76        }
77    }
78
79    impl<'a> Map for Builder<'a> {
80        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81            self.builder.key(k)
82        }
83
84        fn finish(&mut self) -> Result<()> {
85            *self.out = self.builder.take_out();
86            Ok(())
87        }
88    }
89
90    impl ObjectDeser for NotificationEventRequest {
91        type Builder = NotificationEventRequestBuilder;
92    }
93
94    impl FromValueOpt for NotificationEventRequest {
95        fn from_value(v: Value) -> Option<Self> {
96            let Value::Object(obj) = v else {
97                return None;
98            };
99            let mut b = NotificationEventRequestBuilder::deser_default();
100            for (k, v) in obj {
101                match k.as_str() {
102                    "id" => b.id = FromValueOpt::from_value(v),
103                    "idempotency_key" => b.idempotency_key = FromValueOpt::from_value(v),
104
105                    _ => {}
106                }
107            }
108            b.take_out()
109        }
110    }
111};