stripe_shared/
issuing_cardholder_requirements.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardholderRequirements {
5    /// If `disabled_reason` is present, all cards will decline authorizations with `cardholder_verification_required` reason.
6    pub disabled_reason: Option<IssuingCardholderRequirementsDisabledReason>,
7    /// Array of fields that need to be collected in order to verify and re-enable the cardholder.
8    pub past_due: Option<Vec<IssuingCardholderRequirementsPastDue>>,
9}
10#[doc(hidden)]
11pub struct IssuingCardholderRequirementsBuilder {
12    disabled_reason: Option<Option<IssuingCardholderRequirementsDisabledReason>>,
13    past_due: Option<Option<Vec<IssuingCardholderRequirementsPastDue>>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for IssuingCardholderRequirements {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<IssuingCardholderRequirements>,
40        builder: IssuingCardholderRequirementsBuilder,
41    }
42
43    impl Visitor for Place<IssuingCardholderRequirements> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: IssuingCardholderRequirementsBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for IssuingCardholderRequirementsBuilder {
53        type Out = IssuingCardholderRequirements;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "disabled_reason" => Deserialize::begin(&mut self.disabled_reason),
57                "past_due" => Deserialize::begin(&mut self.past_due),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { disabled_reason: Deserialize::default(), past_due: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(disabled_reason), Some(past_due)) =
68                (self.disabled_reason.take(), self.past_due.take())
69            else {
70                return None;
71            };
72            Some(Self::Out { disabled_reason, past_due })
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 IssuingCardholderRequirements {
88        type Builder = IssuingCardholderRequirementsBuilder;
89    }
90
91    impl FromValueOpt for IssuingCardholderRequirements {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = IssuingCardholderRequirementsBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
100                    "past_due" => b.past_due = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// If `disabled_reason` is present, all cards will decline authorizations with `cardholder_verification_required` reason.
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum IssuingCardholderRequirementsDisabledReason {
112    Listed,
113    RejectedListed,
114    RequirementsPastDue,
115    UnderReview,
116    /// An unrecognized value from Stripe. Should not be used as a request parameter.
117    Unknown(String),
118}
119impl IssuingCardholderRequirementsDisabledReason {
120    pub fn as_str(&self) -> &str {
121        use IssuingCardholderRequirementsDisabledReason::*;
122        match self {
123            Listed => "listed",
124            RejectedListed => "rejected.listed",
125            RequirementsPastDue => "requirements.past_due",
126            UnderReview => "under_review",
127            Unknown(v) => v,
128        }
129    }
130}
131
132impl std::str::FromStr for IssuingCardholderRequirementsDisabledReason {
133    type Err = std::convert::Infallible;
134    fn from_str(s: &str) -> Result<Self, Self::Err> {
135        use IssuingCardholderRequirementsDisabledReason::*;
136        match s {
137            "listed" => Ok(Listed),
138            "rejected.listed" => Ok(RejectedListed),
139            "requirements.past_due" => Ok(RequirementsPastDue),
140            "under_review" => Ok(UnderReview),
141            v => {
142                tracing::warn!(
143                    "Unknown value '{}' for enum '{}'",
144                    v,
145                    "IssuingCardholderRequirementsDisabledReason"
146                );
147                Ok(Unknown(v.to_owned()))
148            }
149        }
150    }
151}
152impl std::fmt::Display for IssuingCardholderRequirementsDisabledReason {
153    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154        f.write_str(self.as_str())
155    }
156}
157
158impl std::fmt::Debug for IssuingCardholderRequirementsDisabledReason {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160        f.write_str(self.as_str())
161    }
162}
163#[cfg(feature = "serialize")]
164impl serde::Serialize for IssuingCardholderRequirementsDisabledReason {
165    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
166    where
167        S: serde::Serializer,
168    {
169        serializer.serialize_str(self.as_str())
170    }
171}
172impl miniserde::Deserialize for IssuingCardholderRequirementsDisabledReason {
173    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
174        crate::Place::new(out)
175    }
176}
177
178impl miniserde::de::Visitor for crate::Place<IssuingCardholderRequirementsDisabledReason> {
179    fn string(&mut self, s: &str) -> miniserde::Result<()> {
180        use std::str::FromStr;
181        self.out =
182            Some(IssuingCardholderRequirementsDisabledReason::from_str(s).expect("infallible"));
183        Ok(())
184    }
185}
186
187stripe_types::impl_from_val_with_from_str!(IssuingCardholderRequirementsDisabledReason);
188#[cfg(feature = "deserialize")]
189impl<'de> serde::Deserialize<'de> for IssuingCardholderRequirementsDisabledReason {
190    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
191        use std::str::FromStr;
192        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
193        Ok(Self::from_str(&s).expect("infallible"))
194    }
195}
196/// Array of fields that need to be collected in order to verify and re-enable the cardholder.
197#[derive(Clone, Eq, PartialEq)]
198#[non_exhaustive]
199pub enum IssuingCardholderRequirementsPastDue {
200    CompanyTaxId,
201    IndividualCardIssuingUserTermsAcceptanceDate,
202    IndividualCardIssuingUserTermsAcceptanceIp,
203    IndividualDobDay,
204    IndividualDobMonth,
205    IndividualDobYear,
206    IndividualFirstName,
207    IndividualLastName,
208    IndividualVerificationDocument,
209    /// An unrecognized value from Stripe. Should not be used as a request parameter.
210    Unknown(String),
211}
212impl IssuingCardholderRequirementsPastDue {
213    pub fn as_str(&self) -> &str {
214        use IssuingCardholderRequirementsPastDue::*;
215        match self {
216            CompanyTaxId => "company.tax_id",
217            IndividualCardIssuingUserTermsAcceptanceDate => {
218                "individual.card_issuing.user_terms_acceptance.date"
219            }
220            IndividualCardIssuingUserTermsAcceptanceIp => {
221                "individual.card_issuing.user_terms_acceptance.ip"
222            }
223            IndividualDobDay => "individual.dob.day",
224            IndividualDobMonth => "individual.dob.month",
225            IndividualDobYear => "individual.dob.year",
226            IndividualFirstName => "individual.first_name",
227            IndividualLastName => "individual.last_name",
228            IndividualVerificationDocument => "individual.verification.document",
229            Unknown(v) => v,
230        }
231    }
232}
233
234impl std::str::FromStr for IssuingCardholderRequirementsPastDue {
235    type Err = std::convert::Infallible;
236    fn from_str(s: &str) -> Result<Self, Self::Err> {
237        use IssuingCardholderRequirementsPastDue::*;
238        match s {
239            "company.tax_id" => Ok(CompanyTaxId),
240            "individual.card_issuing.user_terms_acceptance.date" => {
241                Ok(IndividualCardIssuingUserTermsAcceptanceDate)
242            }
243            "individual.card_issuing.user_terms_acceptance.ip" => {
244                Ok(IndividualCardIssuingUserTermsAcceptanceIp)
245            }
246            "individual.dob.day" => Ok(IndividualDobDay),
247            "individual.dob.month" => Ok(IndividualDobMonth),
248            "individual.dob.year" => Ok(IndividualDobYear),
249            "individual.first_name" => Ok(IndividualFirstName),
250            "individual.last_name" => Ok(IndividualLastName),
251            "individual.verification.document" => Ok(IndividualVerificationDocument),
252            v => {
253                tracing::warn!(
254                    "Unknown value '{}' for enum '{}'",
255                    v,
256                    "IssuingCardholderRequirementsPastDue"
257                );
258                Ok(Unknown(v.to_owned()))
259            }
260        }
261    }
262}
263impl std::fmt::Display for IssuingCardholderRequirementsPastDue {
264    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265        f.write_str(self.as_str())
266    }
267}
268
269impl std::fmt::Debug for IssuingCardholderRequirementsPastDue {
270    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271        f.write_str(self.as_str())
272    }
273}
274#[cfg(feature = "serialize")]
275impl serde::Serialize for IssuingCardholderRequirementsPastDue {
276    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
277    where
278        S: serde::Serializer,
279    {
280        serializer.serialize_str(self.as_str())
281    }
282}
283impl miniserde::Deserialize for IssuingCardholderRequirementsPastDue {
284    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
285        crate::Place::new(out)
286    }
287}
288
289impl miniserde::de::Visitor for crate::Place<IssuingCardholderRequirementsPastDue> {
290    fn string(&mut self, s: &str) -> miniserde::Result<()> {
291        use std::str::FromStr;
292        self.out = Some(IssuingCardholderRequirementsPastDue::from_str(s).expect("infallible"));
293        Ok(())
294    }
295}
296
297stripe_types::impl_from_val_with_from_str!(IssuingCardholderRequirementsPastDue);
298#[cfg(feature = "deserialize")]
299impl<'de> serde::Deserialize<'de> for IssuingCardholderRequirementsPastDue {
300    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
301        use std::str::FromStr;
302        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
303        Ok(Self::from_str(&s).expect("infallible"))
304    }
305}