stripe_shared/
issuing_cardholder.rs

1/// An Issuing `Cardholder` object represents an individual or business entity who is [issued](https://stripe.com/docs/issuing) cards.
2///
3/// Related guide: [How to create a cardholder](https://stripe.com/docs/issuing/cards/virtual/issue-cards#create-cardholder).
4///
5/// For more details see <<https://stripe.com/docs/api/issuing/cardholders/object>>.
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
8pub struct IssuingCardholder {
9    pub billing: stripe_shared::IssuingCardholderAddress,
10    /// Additional information about a `company` cardholder.
11    pub company: Option<stripe_shared::IssuingCardholderCompany>,
12    /// Time at which the object was created. Measured in seconds since the Unix epoch.
13    pub created: stripe_types::Timestamp,
14    /// The cardholder's email address.
15    pub email: Option<String>,
16    /// Unique identifier for the object.
17    pub id: stripe_shared::IssuingCardholderId,
18    /// Additional information about an `individual` cardholder.
19    pub individual: Option<stripe_shared::IssuingCardholderIndividual>,
20    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
21    pub livemode: bool,
22    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
23    /// This can be useful for storing additional information about the object in a structured format.
24    pub metadata: std::collections::HashMap<String, String>,
25    /// The cardholder's name. This will be printed on cards issued to them.
26    pub name: String,
27    /// The cardholder's phone number.
28    /// This is required for all cardholders who will be creating EU cards.
29    /// See the [3D Secure documentation](https://stripe.com/docs/issuing/3d-secure#when-is-3d-secure-applied) for more details.
30    pub phone_number: Option<String>,
31    /// The cardholder’s preferred locales (languages), ordered by preference.
32    /// Locales can be `de`, `en`, `es`, `fr`, or `it`.
33    /// This changes the language of the [3D Secure flow](https://stripe.com/docs/issuing/3d-secure) and one-time password messages sent to the cardholder.
34    pub preferred_locales: Option<Vec<stripe_shared::IssuingCardholderPreferredLocales>>,
35    pub requirements: stripe_shared::IssuingCardholderRequirements,
36    /// Rules that control spending across this cardholder's cards.
37    /// Refer to our [documentation](https://stripe.com/docs/issuing/controls/spending-controls) for more details.
38    pub spending_controls: Option<stripe_shared::IssuingCardholderAuthorizationControls>,
39    /// Specifies whether to permit authorizations on this cardholder's cards.
40    pub status: stripe_shared::IssuingCardholderStatus,
41    /// One of `individual` or `company`.
42    /// See [Choose a cardholder type](https://stripe.com/docs/issuing/other/choose-cardholder) for more details.
43    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
44    pub type_: stripe_shared::IssuingCardholderType,
45}
46#[doc(hidden)]
47pub struct IssuingCardholderBuilder {
48    billing: Option<stripe_shared::IssuingCardholderAddress>,
49    company: Option<Option<stripe_shared::IssuingCardholderCompany>>,
50    created: Option<stripe_types::Timestamp>,
51    email: Option<Option<String>>,
52    id: Option<stripe_shared::IssuingCardholderId>,
53    individual: Option<Option<stripe_shared::IssuingCardholderIndividual>>,
54    livemode: Option<bool>,
55    metadata: Option<std::collections::HashMap<String, String>>,
56    name: Option<String>,
57    phone_number: Option<Option<String>>,
58    preferred_locales: Option<Option<Vec<stripe_shared::IssuingCardholderPreferredLocales>>>,
59    requirements: Option<stripe_shared::IssuingCardholderRequirements>,
60    spending_controls: Option<Option<stripe_shared::IssuingCardholderAuthorizationControls>>,
61    status: Option<stripe_shared::IssuingCardholderStatus>,
62    type_: Option<stripe_shared::IssuingCardholderType>,
63}
64
65#[allow(
66    unused_variables,
67    irrefutable_let_patterns,
68    clippy::let_unit_value,
69    clippy::match_single_binding,
70    clippy::single_match
71)]
72const _: () = {
73    use miniserde::de::{Map, Visitor};
74    use miniserde::json::Value;
75    use miniserde::{Deserialize, Result, make_place};
76    use stripe_types::miniserde_helpers::FromValueOpt;
77    use stripe_types::{MapBuilder, ObjectDeser};
78
79    make_place!(Place);
80
81    impl Deserialize for IssuingCardholder {
82        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
83            Place::new(out)
84        }
85    }
86
87    struct Builder<'a> {
88        out: &'a mut Option<IssuingCardholder>,
89        builder: IssuingCardholderBuilder,
90    }
91
92    impl Visitor for Place<IssuingCardholder> {
93        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
94            Ok(Box::new(Builder {
95                out: &mut self.out,
96                builder: IssuingCardholderBuilder::deser_default(),
97            }))
98        }
99    }
100
101    impl MapBuilder for IssuingCardholderBuilder {
102        type Out = IssuingCardholder;
103        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
104            Ok(match k {
105                "billing" => Deserialize::begin(&mut self.billing),
106                "company" => Deserialize::begin(&mut self.company),
107                "created" => Deserialize::begin(&mut self.created),
108                "email" => Deserialize::begin(&mut self.email),
109                "id" => Deserialize::begin(&mut self.id),
110                "individual" => Deserialize::begin(&mut self.individual),
111                "livemode" => Deserialize::begin(&mut self.livemode),
112                "metadata" => Deserialize::begin(&mut self.metadata),
113                "name" => Deserialize::begin(&mut self.name),
114                "phone_number" => Deserialize::begin(&mut self.phone_number),
115                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
116                "requirements" => Deserialize::begin(&mut self.requirements),
117                "spending_controls" => Deserialize::begin(&mut self.spending_controls),
118                "status" => Deserialize::begin(&mut self.status),
119                "type" => Deserialize::begin(&mut self.type_),
120                _ => <dyn Visitor>::ignore(),
121            })
122        }
123
124        fn deser_default() -> Self {
125            Self {
126                billing: Deserialize::default(),
127                company: Deserialize::default(),
128                created: Deserialize::default(),
129                email: Deserialize::default(),
130                id: Deserialize::default(),
131                individual: Deserialize::default(),
132                livemode: Deserialize::default(),
133                metadata: Deserialize::default(),
134                name: Deserialize::default(),
135                phone_number: Deserialize::default(),
136                preferred_locales: Deserialize::default(),
137                requirements: Deserialize::default(),
138                spending_controls: Deserialize::default(),
139                status: Deserialize::default(),
140                type_: Deserialize::default(),
141            }
142        }
143
144        fn take_out(&mut self) -> Option<Self::Out> {
145            let (
146                Some(billing),
147                Some(company),
148                Some(created),
149                Some(email),
150                Some(id),
151                Some(individual),
152                Some(livemode),
153                Some(metadata),
154                Some(name),
155                Some(phone_number),
156                Some(preferred_locales),
157                Some(requirements),
158                Some(spending_controls),
159                Some(status),
160                Some(type_),
161            ) = (
162                self.billing.take(),
163                self.company,
164                self.created,
165                self.email.take(),
166                self.id.take(),
167                self.individual.take(),
168                self.livemode,
169                self.metadata.take(),
170                self.name.take(),
171                self.phone_number.take(),
172                self.preferred_locales.take(),
173                self.requirements.take(),
174                self.spending_controls.take(),
175                self.status,
176                self.type_,
177            )
178            else {
179                return None;
180            };
181            Some(Self::Out {
182                billing,
183                company,
184                created,
185                email,
186                id,
187                individual,
188                livemode,
189                metadata,
190                name,
191                phone_number,
192                preferred_locales,
193                requirements,
194                spending_controls,
195                status,
196                type_,
197            })
198        }
199    }
200
201    impl Map for Builder<'_> {
202        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
203            self.builder.key(k)
204        }
205
206        fn finish(&mut self) -> Result<()> {
207            *self.out = self.builder.take_out();
208            Ok(())
209        }
210    }
211
212    impl ObjectDeser for IssuingCardholder {
213        type Builder = IssuingCardholderBuilder;
214    }
215
216    impl FromValueOpt for IssuingCardholder {
217        fn from_value(v: Value) -> Option<Self> {
218            let Value::Object(obj) = v else {
219                return None;
220            };
221            let mut b = IssuingCardholderBuilder::deser_default();
222            for (k, v) in obj {
223                match k.as_str() {
224                    "billing" => b.billing = FromValueOpt::from_value(v),
225                    "company" => b.company = FromValueOpt::from_value(v),
226                    "created" => b.created = FromValueOpt::from_value(v),
227                    "email" => b.email = FromValueOpt::from_value(v),
228                    "id" => b.id = FromValueOpt::from_value(v),
229                    "individual" => b.individual = FromValueOpt::from_value(v),
230                    "livemode" => b.livemode = FromValueOpt::from_value(v),
231                    "metadata" => b.metadata = FromValueOpt::from_value(v),
232                    "name" => b.name = FromValueOpt::from_value(v),
233                    "phone_number" => b.phone_number = FromValueOpt::from_value(v),
234                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
235                    "requirements" => b.requirements = FromValueOpt::from_value(v),
236                    "spending_controls" => b.spending_controls = FromValueOpt::from_value(v),
237                    "status" => b.status = FromValueOpt::from_value(v),
238                    "type" => b.type_ = FromValueOpt::from_value(v),
239                    _ => {}
240                }
241            }
242            b.take_out()
243        }
244    }
245};
246#[cfg(feature = "serialize")]
247impl serde::Serialize for IssuingCardholder {
248    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
249        use serde::ser::SerializeStruct;
250        let mut s = s.serialize_struct("IssuingCardholder", 16)?;
251        s.serialize_field("billing", &self.billing)?;
252        s.serialize_field("company", &self.company)?;
253        s.serialize_field("created", &self.created)?;
254        s.serialize_field("email", &self.email)?;
255        s.serialize_field("id", &self.id)?;
256        s.serialize_field("individual", &self.individual)?;
257        s.serialize_field("livemode", &self.livemode)?;
258        s.serialize_field("metadata", &self.metadata)?;
259        s.serialize_field("name", &self.name)?;
260        s.serialize_field("phone_number", &self.phone_number)?;
261        s.serialize_field("preferred_locales", &self.preferred_locales)?;
262        s.serialize_field("requirements", &self.requirements)?;
263        s.serialize_field("spending_controls", &self.spending_controls)?;
264        s.serialize_field("status", &self.status)?;
265        s.serialize_field("type", &self.type_)?;
266
267        s.serialize_field("object", "issuing.cardholder")?;
268        s.end()
269    }
270}
271impl stripe_types::Object for IssuingCardholder {
272    type Id = stripe_shared::IssuingCardholderId;
273    fn id(&self) -> &Self::Id {
274        &self.id
275    }
276
277    fn into_id(self) -> Self::Id {
278        self.id
279    }
280}
281stripe_types::def_id!(IssuingCardholderId);
282#[derive(Copy, Clone, Eq, PartialEq)]
283pub enum IssuingCardholderPreferredLocales {
284    De,
285    En,
286    Es,
287    Fr,
288    It,
289}
290impl IssuingCardholderPreferredLocales {
291    pub fn as_str(self) -> &'static str {
292        use IssuingCardholderPreferredLocales::*;
293        match self {
294            De => "de",
295            En => "en",
296            Es => "es",
297            Fr => "fr",
298            It => "it",
299        }
300    }
301}
302
303impl std::str::FromStr for IssuingCardholderPreferredLocales {
304    type Err = stripe_types::StripeParseError;
305    fn from_str(s: &str) -> Result<Self, Self::Err> {
306        use IssuingCardholderPreferredLocales::*;
307        match s {
308            "de" => Ok(De),
309            "en" => Ok(En),
310            "es" => Ok(Es),
311            "fr" => Ok(Fr),
312            "it" => Ok(It),
313            _ => Err(stripe_types::StripeParseError),
314        }
315    }
316}
317impl std::fmt::Display for IssuingCardholderPreferredLocales {
318    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
319        f.write_str(self.as_str())
320    }
321}
322
323impl std::fmt::Debug for IssuingCardholderPreferredLocales {
324    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
325        f.write_str(self.as_str())
326    }
327}
328impl serde::Serialize for IssuingCardholderPreferredLocales {
329    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
330    where
331        S: serde::Serializer,
332    {
333        serializer.serialize_str(self.as_str())
334    }
335}
336impl miniserde::Deserialize for IssuingCardholderPreferredLocales {
337    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
338        crate::Place::new(out)
339    }
340}
341
342impl miniserde::de::Visitor for crate::Place<IssuingCardholderPreferredLocales> {
343    fn string(&mut self, s: &str) -> miniserde::Result<()> {
344        use std::str::FromStr;
345        self.out =
346            Some(IssuingCardholderPreferredLocales::from_str(s).map_err(|_| miniserde::Error)?);
347        Ok(())
348    }
349}
350
351stripe_types::impl_from_val_with_from_str!(IssuingCardholderPreferredLocales);
352#[cfg(feature = "deserialize")]
353impl<'de> serde::Deserialize<'de> for IssuingCardholderPreferredLocales {
354    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
355        use std::str::FromStr;
356        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
357        Self::from_str(&s).map_err(|_| {
358            serde::de::Error::custom("Unknown value for IssuingCardholderPreferredLocales")
359        })
360    }
361}
362#[derive(Copy, Clone, Eq, PartialEq)]
363pub enum IssuingCardholderStatus {
364    Active,
365    Blocked,
366    Inactive,
367}
368impl IssuingCardholderStatus {
369    pub fn as_str(self) -> &'static str {
370        use IssuingCardholderStatus::*;
371        match self {
372            Active => "active",
373            Blocked => "blocked",
374            Inactive => "inactive",
375        }
376    }
377}
378
379impl std::str::FromStr for IssuingCardholderStatus {
380    type Err = stripe_types::StripeParseError;
381    fn from_str(s: &str) -> Result<Self, Self::Err> {
382        use IssuingCardholderStatus::*;
383        match s {
384            "active" => Ok(Active),
385            "blocked" => Ok(Blocked),
386            "inactive" => Ok(Inactive),
387            _ => Err(stripe_types::StripeParseError),
388        }
389    }
390}
391impl std::fmt::Display for IssuingCardholderStatus {
392    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
393        f.write_str(self.as_str())
394    }
395}
396
397impl std::fmt::Debug for IssuingCardholderStatus {
398    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
399        f.write_str(self.as_str())
400    }
401}
402impl serde::Serialize for IssuingCardholderStatus {
403    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
404    where
405        S: serde::Serializer,
406    {
407        serializer.serialize_str(self.as_str())
408    }
409}
410impl miniserde::Deserialize for IssuingCardholderStatus {
411    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
412        crate::Place::new(out)
413    }
414}
415
416impl miniserde::de::Visitor for crate::Place<IssuingCardholderStatus> {
417    fn string(&mut self, s: &str) -> miniserde::Result<()> {
418        use std::str::FromStr;
419        self.out = Some(IssuingCardholderStatus::from_str(s).map_err(|_| miniserde::Error)?);
420        Ok(())
421    }
422}
423
424stripe_types::impl_from_val_with_from_str!(IssuingCardholderStatus);
425#[cfg(feature = "deserialize")]
426impl<'de> serde::Deserialize<'de> for IssuingCardholderStatus {
427    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
428        use std::str::FromStr;
429        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
430        Self::from_str(&s)
431            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingCardholderStatus"))
432    }
433}
434#[derive(Copy, Clone, Eq, PartialEq)]
435pub enum IssuingCardholderType {
436    Company,
437    Individual,
438}
439impl IssuingCardholderType {
440    pub fn as_str(self) -> &'static str {
441        use IssuingCardholderType::*;
442        match self {
443            Company => "company",
444            Individual => "individual",
445        }
446    }
447}
448
449impl std::str::FromStr for IssuingCardholderType {
450    type Err = stripe_types::StripeParseError;
451    fn from_str(s: &str) -> Result<Self, Self::Err> {
452        use IssuingCardholderType::*;
453        match s {
454            "company" => Ok(Company),
455            "individual" => Ok(Individual),
456            _ => Err(stripe_types::StripeParseError),
457        }
458    }
459}
460impl std::fmt::Display for IssuingCardholderType {
461    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
462        f.write_str(self.as_str())
463    }
464}
465
466impl std::fmt::Debug for IssuingCardholderType {
467    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
468        f.write_str(self.as_str())
469    }
470}
471impl serde::Serialize for IssuingCardholderType {
472    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
473    where
474        S: serde::Serializer,
475    {
476        serializer.serialize_str(self.as_str())
477    }
478}
479impl miniserde::Deserialize for IssuingCardholderType {
480    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
481        crate::Place::new(out)
482    }
483}
484
485impl miniserde::de::Visitor for crate::Place<IssuingCardholderType> {
486    fn string(&mut self, s: &str) -> miniserde::Result<()> {
487        use std::str::FromStr;
488        self.out = Some(IssuingCardholderType::from_str(s).map_err(|_| miniserde::Error)?);
489        Ok(())
490    }
491}
492
493stripe_types::impl_from_val_with_from_str!(IssuingCardholderType);
494#[cfg(feature = "deserialize")]
495impl<'de> serde::Deserialize<'de> for IssuingCardholderType {
496    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
497        use std::str::FromStr;
498        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
499        Self::from_str(&s)
500            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingCardholderType"))
501    }
502}