stripe_shared/
issuing_authorization_authentication_exemption.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingAuthorizationAuthenticationExemption {
5    /// The entity that requested the exemption, either the acquiring merchant or the Issuing user.
6    pub claimed_by: IssuingAuthorizationAuthenticationExemptionClaimedBy,
7    /// The specific exemption claimed for this authorization.
8    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
9    pub type_: IssuingAuthorizationAuthenticationExemptionType,
10}
11#[doc(hidden)]
12pub struct IssuingAuthorizationAuthenticationExemptionBuilder {
13    claimed_by: Option<IssuingAuthorizationAuthenticationExemptionClaimedBy>,
14    type_: Option<IssuingAuthorizationAuthenticationExemptionType>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for IssuingAuthorizationAuthenticationExemption {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<IssuingAuthorizationAuthenticationExemption>,
41        builder: IssuingAuthorizationAuthenticationExemptionBuilder,
42    }
43
44    impl Visitor for Place<IssuingAuthorizationAuthenticationExemption> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: IssuingAuthorizationAuthenticationExemptionBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for IssuingAuthorizationAuthenticationExemptionBuilder {
54        type Out = IssuingAuthorizationAuthenticationExemption;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "claimed_by" => Deserialize::begin(&mut self.claimed_by),
58                "type" => Deserialize::begin(&mut self.type_),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { claimed_by: Deserialize::default(), type_: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(claimed_by), Some(type_)) = (self.claimed_by, self.type_) else {
69                return None;
70            };
71            Some(Self::Out { claimed_by, type_ })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for IssuingAuthorizationAuthenticationExemption {
87        type Builder = IssuingAuthorizationAuthenticationExemptionBuilder;
88    }
89
90    impl FromValueOpt for IssuingAuthorizationAuthenticationExemption {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = IssuingAuthorizationAuthenticationExemptionBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "claimed_by" => b.claimed_by = FromValueOpt::from_value(v),
99                    "type" => b.type_ = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// The entity that requested the exemption, either the acquiring merchant or the Issuing user.
108#[derive(Copy, Clone, Eq, PartialEq)]
109pub enum IssuingAuthorizationAuthenticationExemptionClaimedBy {
110    Acquirer,
111    Issuer,
112}
113impl IssuingAuthorizationAuthenticationExemptionClaimedBy {
114    pub fn as_str(self) -> &'static str {
115        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
116        match self {
117            Acquirer => "acquirer",
118            Issuer => "issuer",
119        }
120    }
121}
122
123impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionClaimedBy {
124    type Err = stripe_types::StripeParseError;
125    fn from_str(s: &str) -> Result<Self, Self::Err> {
126        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
127        match s {
128            "acquirer" => Ok(Acquirer),
129            "issuer" => Ok(Issuer),
130            _ => Err(stripe_types::StripeParseError),
131        }
132    }
133}
134impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionClaimedBy {
135    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
136        f.write_str(self.as_str())
137    }
138}
139
140impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionClaimedBy {
141    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142        f.write_str(self.as_str())
143    }
144}
145#[cfg(feature = "serialize")]
146impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
147    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
148    where
149        S: serde::Serializer,
150    {
151        serializer.serialize_str(self.as_str())
152    }
153}
154impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
155    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
156        crate::Place::new(out)
157    }
158}
159
160impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionClaimedBy> {
161    fn string(&mut self, s: &str) -> miniserde::Result<()> {
162        use std::str::FromStr;
163        self.out = Some(
164            IssuingAuthorizationAuthenticationExemptionClaimedBy::from_str(s)
165                .map_err(|_| miniserde::Error)?,
166        );
167        Ok(())
168    }
169}
170
171stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionClaimedBy);
172#[cfg(feature = "deserialize")]
173impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionClaimedBy {
174    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
175        use std::str::FromStr;
176        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
177        Self::from_str(&s).map_err(|_| {
178            serde::de::Error::custom(
179                "Unknown value for IssuingAuthorizationAuthenticationExemptionClaimedBy",
180            )
181        })
182    }
183}
184/// The specific exemption claimed for this authorization.
185#[derive(Copy, Clone, Eq, PartialEq)]
186pub enum IssuingAuthorizationAuthenticationExemptionType {
187    LowValueTransaction,
188    TransactionRiskAnalysis,
189    Unknown,
190}
191impl IssuingAuthorizationAuthenticationExemptionType {
192    pub fn as_str(self) -> &'static str {
193        use IssuingAuthorizationAuthenticationExemptionType::*;
194        match self {
195            LowValueTransaction => "low_value_transaction",
196            TransactionRiskAnalysis => "transaction_risk_analysis",
197            Unknown => "unknown",
198        }
199    }
200}
201
202impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionType {
203    type Err = stripe_types::StripeParseError;
204    fn from_str(s: &str) -> Result<Self, Self::Err> {
205        use IssuingAuthorizationAuthenticationExemptionType::*;
206        match s {
207            "low_value_transaction" => Ok(LowValueTransaction),
208            "transaction_risk_analysis" => Ok(TransactionRiskAnalysis),
209            "unknown" => Ok(Unknown),
210            _ => Err(stripe_types::StripeParseError),
211        }
212    }
213}
214impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionType {
215    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
216        f.write_str(self.as_str())
217    }
218}
219
220impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionType {
221    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
222        f.write_str(self.as_str())
223    }
224}
225#[cfg(feature = "serialize")]
226impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionType {
227    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
228    where
229        S: serde::Serializer,
230    {
231        serializer.serialize_str(self.as_str())
232    }
233}
234impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionType {
235    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
236        crate::Place::new(out)
237    }
238}
239
240impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionType> {
241    fn string(&mut self, s: &str) -> miniserde::Result<()> {
242        use std::str::FromStr;
243        self.out = Some(
244            IssuingAuthorizationAuthenticationExemptionType::from_str(s)
245                .map_err(|_| miniserde::Error)?,
246        );
247        Ok(())
248    }
249}
250
251stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionType);
252#[cfg(feature = "deserialize")]
253impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionType {
254    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
255        use std::str::FromStr;
256        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
257        Self::from_str(&s).map_err(|_| {
258            serde::de::Error::custom(
259                "Unknown value for IssuingAuthorizationAuthenticationExemptionType",
260            )
261        })
262    }
263}