stripe_shared/
issuing_authorization_authentication_exemption.rs

1#[derive(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.take(), self.type_.take())
69            else {
70                return None;
71            };
72            Some(Self::Out { claimed_by, type_ })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for IssuingAuthorizationAuthenticationExemption {
88        type Builder = IssuingAuthorizationAuthenticationExemptionBuilder;
89    }
90
91    impl FromValueOpt for IssuingAuthorizationAuthenticationExemption {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = IssuingAuthorizationAuthenticationExemptionBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "claimed_by" => b.claimed_by = FromValueOpt::from_value(v),
100                    "type" => b.type_ = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// The entity that requested the exemption, either the acquiring merchant or the Issuing user.
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum IssuingAuthorizationAuthenticationExemptionClaimedBy {
112    Acquirer,
113    Issuer,
114    /// An unrecognized value from Stripe. Should not be used as a request parameter.
115    Unknown(String),
116}
117impl IssuingAuthorizationAuthenticationExemptionClaimedBy {
118    pub fn as_str(&self) -> &str {
119        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
120        match self {
121            Acquirer => "acquirer",
122            Issuer => "issuer",
123            Unknown(v) => v,
124        }
125    }
126}
127
128impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionClaimedBy {
129    type Err = std::convert::Infallible;
130    fn from_str(s: &str) -> Result<Self, Self::Err> {
131        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
132        match s {
133            "acquirer" => Ok(Acquirer),
134            "issuer" => Ok(Issuer),
135            v => {
136                tracing::warn!(
137                    "Unknown value '{}' for enum '{}'",
138                    v,
139                    "IssuingAuthorizationAuthenticationExemptionClaimedBy"
140                );
141                Ok(Unknown(v.to_owned()))
142            }
143        }
144    }
145}
146impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionClaimedBy {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        f.write_str(self.as_str())
149    }
150}
151
152impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionClaimedBy {
153    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154        f.write_str(self.as_str())
155    }
156}
157#[cfg(feature = "serialize")]
158impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
159    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
160    where
161        S: serde::Serializer,
162    {
163        serializer.serialize_str(self.as_str())
164    }
165}
166impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
167    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
168        crate::Place::new(out)
169    }
170}
171
172impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionClaimedBy> {
173    fn string(&mut self, s: &str) -> miniserde::Result<()> {
174        use std::str::FromStr;
175        self.out = Some(
176            IssuingAuthorizationAuthenticationExemptionClaimedBy::from_str(s).expect("infallible"),
177        );
178        Ok(())
179    }
180}
181
182stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionClaimedBy);
183#[cfg(feature = "deserialize")]
184impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionClaimedBy {
185    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
186        use std::str::FromStr;
187        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
188        Ok(Self::from_str(&s).expect("infallible"))
189    }
190}
191/// The specific exemption claimed for this authorization.
192#[derive(Clone, Eq, PartialEq)]
193#[non_exhaustive]
194pub enum IssuingAuthorizationAuthenticationExemptionType {
195    LowValueTransaction,
196    TransactionRiskAnalysis,
197    Unknown,
198    /// An unrecognized value from Stripe. Should not be used as a request parameter.
199    /// This variant is prefixed with an underscore to avoid conflicts with Stripe's 'Unknown' variant.
200    _Unknown(String),
201}
202impl IssuingAuthorizationAuthenticationExemptionType {
203    pub fn as_str(&self) -> &str {
204        use IssuingAuthorizationAuthenticationExemptionType::*;
205        match self {
206            LowValueTransaction => "low_value_transaction",
207            TransactionRiskAnalysis => "transaction_risk_analysis",
208            Unknown => "unknown",
209            _Unknown(v) => v,
210        }
211    }
212}
213
214impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionType {
215    type Err = std::convert::Infallible;
216    fn from_str(s: &str) -> Result<Self, Self::Err> {
217        use IssuingAuthorizationAuthenticationExemptionType::*;
218        match s {
219            "low_value_transaction" => Ok(LowValueTransaction),
220            "transaction_risk_analysis" => Ok(TransactionRiskAnalysis),
221            "unknown" => Ok(Unknown),
222            v => {
223                tracing::warn!(
224                    "Unknown value '{}' for enum '{}'",
225                    v,
226                    "IssuingAuthorizationAuthenticationExemptionType"
227                );
228                Ok(_Unknown(v.to_owned()))
229            }
230        }
231    }
232}
233impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionType {
234    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
235        f.write_str(self.as_str())
236    }
237}
238
239impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionType {
240    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
241        f.write_str(self.as_str())
242    }
243}
244#[cfg(feature = "serialize")]
245impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionType {
246    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
247    where
248        S: serde::Serializer,
249    {
250        serializer.serialize_str(self.as_str())
251    }
252}
253impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionType {
254    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
255        crate::Place::new(out)
256    }
257}
258
259impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionType> {
260    fn string(&mut self, s: &str) -> miniserde::Result<()> {
261        use std::str::FromStr;
262        self.out =
263            Some(IssuingAuthorizationAuthenticationExemptionType::from_str(s).expect("infallible"));
264        Ok(())
265    }
266}
267
268stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionType);
269#[cfg(feature = "deserialize")]
270impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionType {
271    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
272        use std::str::FromStr;
273        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
274        Ok(Self::from_str(&s).expect("infallible"))
275    }
276}