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::{make_place, Deserialize, Result};
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
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { claimed_by: Deserialize::default(), type_: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(claimed_by), Some(type_)) = (self.claimed_by, self.type_) else {
70                return None;
71            };
72            Some(Self::Out { claimed_by, type_ })
73        }
74    }
75
76    impl<'a> Map for Builder<'a> {
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            }
105            b.take_out()
106        }
107    }
108};
109/// The entity that requested the exemption, either the acquiring merchant or the Issuing user.
110#[derive(Copy, Clone, Eq, PartialEq)]
111pub enum IssuingAuthorizationAuthenticationExemptionClaimedBy {
112    Acquirer,
113    Issuer,
114}
115impl IssuingAuthorizationAuthenticationExemptionClaimedBy {
116    pub fn as_str(self) -> &'static str {
117        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
118        match self {
119            Acquirer => "acquirer",
120            Issuer => "issuer",
121        }
122    }
123}
124
125impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionClaimedBy {
126    type Err = stripe_types::StripeParseError;
127    fn from_str(s: &str) -> Result<Self, Self::Err> {
128        use IssuingAuthorizationAuthenticationExemptionClaimedBy::*;
129        match s {
130            "acquirer" => Ok(Acquirer),
131            "issuer" => Ok(Issuer),
132            _ => Err(stripe_types::StripeParseError),
133        }
134    }
135}
136impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionClaimedBy {
137    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
138        f.write_str(self.as_str())
139    }
140}
141
142impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionClaimedBy {
143    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
144        f.write_str(self.as_str())
145    }
146}
147#[cfg(feature = "serialize")]
148impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
149    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
150    where
151        S: serde::Serializer,
152    {
153        serializer.serialize_str(self.as_str())
154    }
155}
156impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionClaimedBy {
157    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
158        crate::Place::new(out)
159    }
160}
161
162impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionClaimedBy> {
163    fn string(&mut self, s: &str) -> miniserde::Result<()> {
164        use std::str::FromStr;
165        self.out = Some(
166            IssuingAuthorizationAuthenticationExemptionClaimedBy::from_str(s)
167                .map_err(|_| miniserde::Error)?,
168        );
169        Ok(())
170    }
171}
172
173stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionClaimedBy);
174#[cfg(feature = "deserialize")]
175impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionClaimedBy {
176    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
177        use std::str::FromStr;
178        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
179        Self::from_str(&s).map_err(|_| {
180            serde::de::Error::custom(
181                "Unknown value for IssuingAuthorizationAuthenticationExemptionClaimedBy",
182            )
183        })
184    }
185}
186/// The specific exemption claimed for this authorization.
187#[derive(Copy, Clone, Eq, PartialEq)]
188pub enum IssuingAuthorizationAuthenticationExemptionType {
189    LowValueTransaction,
190    TransactionRiskAnalysis,
191    Unknown,
192}
193impl IssuingAuthorizationAuthenticationExemptionType {
194    pub fn as_str(self) -> &'static str {
195        use IssuingAuthorizationAuthenticationExemptionType::*;
196        match self {
197            LowValueTransaction => "low_value_transaction",
198            TransactionRiskAnalysis => "transaction_risk_analysis",
199            Unknown => "unknown",
200        }
201    }
202}
203
204impl std::str::FromStr for IssuingAuthorizationAuthenticationExemptionType {
205    type Err = stripe_types::StripeParseError;
206    fn from_str(s: &str) -> Result<Self, Self::Err> {
207        use IssuingAuthorizationAuthenticationExemptionType::*;
208        match s {
209            "low_value_transaction" => Ok(LowValueTransaction),
210            "transaction_risk_analysis" => Ok(TransactionRiskAnalysis),
211            "unknown" => Ok(Unknown),
212            _ => Err(stripe_types::StripeParseError),
213        }
214    }
215}
216impl std::fmt::Display for IssuingAuthorizationAuthenticationExemptionType {
217    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
218        f.write_str(self.as_str())
219    }
220}
221
222impl std::fmt::Debug for IssuingAuthorizationAuthenticationExemptionType {
223    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
224        f.write_str(self.as_str())
225    }
226}
227#[cfg(feature = "serialize")]
228impl serde::Serialize for IssuingAuthorizationAuthenticationExemptionType {
229    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
230    where
231        S: serde::Serializer,
232    {
233        serializer.serialize_str(self.as_str())
234    }
235}
236impl miniserde::Deserialize for IssuingAuthorizationAuthenticationExemptionType {
237    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
238        crate::Place::new(out)
239    }
240}
241
242impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationAuthenticationExemptionType> {
243    fn string(&mut self, s: &str) -> miniserde::Result<()> {
244        use std::str::FromStr;
245        self.out = Some(
246            IssuingAuthorizationAuthenticationExemptionType::from_str(s)
247                .map_err(|_| miniserde::Error)?,
248        );
249        Ok(())
250    }
251}
252
253stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationAuthenticationExemptionType);
254#[cfg(feature = "deserialize")]
255impl<'de> serde::Deserialize<'de> for IssuingAuthorizationAuthenticationExemptionType {
256    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
257        use std::str::FromStr;
258        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
259        Self::from_str(&s).map_err(|_| {
260            serde::de::Error::custom(
261                "Unknown value for IssuingAuthorizationAuthenticationExemptionType",
262            )
263        })
264    }
265}