Skip to main content

stripe_shared/
radar_radar_options.rs

1/// Options to configure Radar.
2/// See [Radar Session](https://docs.stripe.com/radar/radar-session) for more information.
3#[derive(Clone, Eq, PartialEq)]
4#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
5#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
6#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
7pub struct RadarRadarOptions {
8    /// A [Radar Session](https://docs.stripe.com/radar/radar-session) is a snapshot of the browser metadata and device details that help Radar make more accurate predictions on your payments.
9    pub session: Option<String>,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for RadarRadarOptions {
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        f.debug_struct("RadarRadarOptions").finish_non_exhaustive()
15    }
16}
17#[doc(hidden)]
18pub struct RadarRadarOptionsBuilder {
19    session: Option<Option<String>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for RadarRadarOptions {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<RadarRadarOptions>,
46        builder: RadarRadarOptionsBuilder,
47    }
48
49    impl Visitor for Place<RadarRadarOptions> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: RadarRadarOptionsBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for RadarRadarOptionsBuilder {
59        type Out = RadarRadarOptions;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "session" => Deserialize::begin(&mut self.session),
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self { session: Some(None) }
69        }
70
71        fn take_out(&mut self) -> Option<Self::Out> {
72            let (Some(session),) = (self.session.take(),) else {
73                return None;
74            };
75            Some(Self::Out { session })
76        }
77    }
78
79    impl Map for Builder<'_> {
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 RadarRadarOptions {
91        type Builder = RadarRadarOptionsBuilder;
92    }
93
94    impl FromValueOpt for RadarRadarOptions {
95        fn from_value(v: Value) -> Option<Self> {
96            let Value::Object(obj) = v else {
97                return None;
98            };
99            let mut b = RadarRadarOptionsBuilder::deser_default();
100            for (k, v) in obj {
101                match k.as_str() {
102                    "session" => b.session = FromValueOpt::from_value(v),
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};