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::{make_place, Deserialize, Result};
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
121                _ => <dyn Visitor>::ignore(),
122            })
123        }
124
125        fn deser_default() -> Self {
126            Self {
127                billing: Deserialize::default(),
128                company: Deserialize::default(),
129                created: Deserialize::default(),
130                email: Deserialize::default(),
131                id: Deserialize::default(),
132                individual: Deserialize::default(),
133                livemode: Deserialize::default(),
134                metadata: Deserialize::default(),
135                name: Deserialize::default(),
136                phone_number: Deserialize::default(),
137                preferred_locales: Deserialize::default(),
138                requirements: Deserialize::default(),
139                spending_controls: Deserialize::default(),
140                status: Deserialize::default(),
141                type_: Deserialize::default(),
142            }
143        }
144
145        fn take_out(&mut self) -> Option<Self::Out> {
146            let (
147                Some(billing),
148                Some(company),
149                Some(created),
150                Some(email),
151                Some(id),
152                Some(individual),
153                Some(livemode),
154                Some(metadata),
155                Some(name),
156                Some(phone_number),
157                Some(preferred_locales),
158                Some(requirements),
159                Some(spending_controls),
160                Some(status),
161                Some(type_),
162            ) = (
163                self.billing.take(),
164                self.company,
165                self.created,
166                self.email.take(),
167                self.id.take(),
168                self.individual.take(),
169                self.livemode,
170                self.metadata.take(),
171                self.name.take(),
172                self.phone_number.take(),
173                self.preferred_locales.take(),
174                self.requirements.take(),
175                self.spending_controls.take(),
176                self.status,
177                self.type_,
178            )
179            else {
180                return None;
181            };
182            Some(Self::Out {
183                billing,
184                company,
185                created,
186                email,
187                id,
188                individual,
189                livemode,
190                metadata,
191                name,
192                phone_number,
193                preferred_locales,
194                requirements,
195                spending_controls,
196                status,
197                type_,
198            })
199        }
200    }
201
202    impl Map for Builder<'_> {
203        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
204            self.builder.key(k)
205        }
206
207        fn finish(&mut self) -> Result<()> {
208            *self.out = self.builder.take_out();
209            Ok(())
210        }
211    }
212
213    impl ObjectDeser for IssuingCardholder {
214        type Builder = IssuingCardholderBuilder;
215    }
216
217    impl FromValueOpt for IssuingCardholder {
218        fn from_value(v: Value) -> Option<Self> {
219            let Value::Object(obj) = v else {
220                return None;
221            };
222            let mut b = IssuingCardholderBuilder::deser_default();
223            for (k, v) in obj {
224                match k.as_str() {
225                    "billing" => b.billing = FromValueOpt::from_value(v),
226                    "company" => b.company = FromValueOpt::from_value(v),
227                    "created" => b.created = FromValueOpt::from_value(v),
228                    "email" => b.email = FromValueOpt::from_value(v),
229                    "id" => b.id = FromValueOpt::from_value(v),
230                    "individual" => b.individual = FromValueOpt::from_value(v),
231                    "livemode" => b.livemode = FromValueOpt::from_value(v),
232                    "metadata" => b.metadata = FromValueOpt::from_value(v),
233                    "name" => b.name = FromValueOpt::from_value(v),
234                    "phone_number" => b.phone_number = FromValueOpt::from_value(v),
235                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
236                    "requirements" => b.requirements = FromValueOpt::from_value(v),
237                    "spending_controls" => b.spending_controls = FromValueOpt::from_value(v),
238                    "status" => b.status = FromValueOpt::from_value(v),
239                    "type" => b.type_ = FromValueOpt::from_value(v),
240
241                    _ => {}
242                }
243            }
244            b.take_out()
245        }
246    }
247};
248#[cfg(feature = "serialize")]
249impl serde::Serialize for IssuingCardholder {
250    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
251        use serde::ser::SerializeStruct;
252        let mut s = s.serialize_struct("IssuingCardholder", 16)?;
253        s.serialize_field("billing", &self.billing)?;
254        s.serialize_field("company", &self.company)?;
255        s.serialize_field("created", &self.created)?;
256        s.serialize_field("email", &self.email)?;
257        s.serialize_field("id", &self.id)?;
258        s.serialize_field("individual", &self.individual)?;
259        s.serialize_field("livemode", &self.livemode)?;
260        s.serialize_field("metadata", &self.metadata)?;
261        s.serialize_field("name", &self.name)?;
262        s.serialize_field("phone_number", &self.phone_number)?;
263        s.serialize_field("preferred_locales", &self.preferred_locales)?;
264        s.serialize_field("requirements", &self.requirements)?;
265        s.serialize_field("spending_controls", &self.spending_controls)?;
266        s.serialize_field("status", &self.status)?;
267        s.serialize_field("type", &self.type_)?;
268
269        s.serialize_field("object", "issuing.cardholder")?;
270        s.end()
271    }
272}
273impl stripe_types::Object for IssuingCardholder {
274    type Id = stripe_shared::IssuingCardholderId;
275    fn id(&self) -> &Self::Id {
276        &self.id
277    }
278
279    fn into_id(self) -> Self::Id {
280        self.id
281    }
282}
283stripe_types::def_id!(IssuingCardholderId);
284#[derive(Copy, Clone, Eq, PartialEq)]
285pub enum IssuingCardholderPreferredLocales {
286    De,
287    En,
288    Es,
289    Fr,
290    It,
291}
292impl IssuingCardholderPreferredLocales {
293    pub fn as_str(self) -> &'static str {
294        use IssuingCardholderPreferredLocales::*;
295        match self {
296            De => "de",
297            En => "en",
298            Es => "es",
299            Fr => "fr",
300            It => "it",
301        }
302    }
303}
304
305impl std::str::FromStr for IssuingCardholderPreferredLocales {
306    type Err = stripe_types::StripeParseError;
307    fn from_str(s: &str) -> Result<Self, Self::Err> {
308        use IssuingCardholderPreferredLocales::*;
309        match s {
310            "de" => Ok(De),
311            "en" => Ok(En),
312            "es" => Ok(Es),
313            "fr" => Ok(Fr),
314            "it" => Ok(It),
315            _ => Err(stripe_types::StripeParseError),
316        }
317    }
318}
319impl std::fmt::Display for IssuingCardholderPreferredLocales {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324
325impl std::fmt::Debug for IssuingCardholderPreferredLocales {
326    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327        f.write_str(self.as_str())
328    }
329}
330impl serde::Serialize for IssuingCardholderPreferredLocales {
331    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
332    where
333        S: serde::Serializer,
334    {
335        serializer.serialize_str(self.as_str())
336    }
337}
338impl miniserde::Deserialize for IssuingCardholderPreferredLocales {
339    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
340        crate::Place::new(out)
341    }
342}
343
344impl miniserde::de::Visitor for crate::Place<IssuingCardholderPreferredLocales> {
345    fn string(&mut self, s: &str) -> miniserde::Result<()> {
346        use std::str::FromStr;
347        self.out =
348            Some(IssuingCardholderPreferredLocales::from_str(s).map_err(|_| miniserde::Error)?);
349        Ok(())
350    }
351}
352
353stripe_types::impl_from_val_with_from_str!(IssuingCardholderPreferredLocales);
354#[cfg(feature = "deserialize")]
355impl<'de> serde::Deserialize<'de> for IssuingCardholderPreferredLocales {
356    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
357        use std::str::FromStr;
358        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
359        Self::from_str(&s).map_err(|_| {
360            serde::de::Error::custom("Unknown value for IssuingCardholderPreferredLocales")
361        })
362    }
363}
364#[derive(Copy, Clone, Eq, PartialEq)]
365pub enum IssuingCardholderStatus {
366    Active,
367    Blocked,
368    Inactive,
369}
370impl IssuingCardholderStatus {
371    pub fn as_str(self) -> &'static str {
372        use IssuingCardholderStatus::*;
373        match self {
374            Active => "active",
375            Blocked => "blocked",
376            Inactive => "inactive",
377        }
378    }
379}
380
381impl std::str::FromStr for IssuingCardholderStatus {
382    type Err = stripe_types::StripeParseError;
383    fn from_str(s: &str) -> Result<Self, Self::Err> {
384        use IssuingCardholderStatus::*;
385        match s {
386            "active" => Ok(Active),
387            "blocked" => Ok(Blocked),
388            "inactive" => Ok(Inactive),
389            _ => Err(stripe_types::StripeParseError),
390        }
391    }
392}
393impl std::fmt::Display for IssuingCardholderStatus {
394    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
395        f.write_str(self.as_str())
396    }
397}
398
399impl std::fmt::Debug for IssuingCardholderStatus {
400    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
401        f.write_str(self.as_str())
402    }
403}
404impl serde::Serialize for IssuingCardholderStatus {
405    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
406    where
407        S: serde::Serializer,
408    {
409        serializer.serialize_str(self.as_str())
410    }
411}
412impl miniserde::Deserialize for IssuingCardholderStatus {
413    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
414        crate::Place::new(out)
415    }
416}
417
418impl miniserde::de::Visitor for crate::Place<IssuingCardholderStatus> {
419    fn string(&mut self, s: &str) -> miniserde::Result<()> {
420        use std::str::FromStr;
421        self.out = Some(IssuingCardholderStatus::from_str(s).map_err(|_| miniserde::Error)?);
422        Ok(())
423    }
424}
425
426stripe_types::impl_from_val_with_from_str!(IssuingCardholderStatus);
427#[cfg(feature = "deserialize")]
428impl<'de> serde::Deserialize<'de> for IssuingCardholderStatus {
429    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
430        use std::str::FromStr;
431        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
432        Self::from_str(&s)
433            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingCardholderStatus"))
434    }
435}
436#[derive(Copy, Clone, Eq, PartialEq)]
437pub enum IssuingCardholderType {
438    Company,
439    Individual,
440}
441impl IssuingCardholderType {
442    pub fn as_str(self) -> &'static str {
443        use IssuingCardholderType::*;
444        match self {
445            Company => "company",
446            Individual => "individual",
447        }
448    }
449}
450
451impl std::str::FromStr for IssuingCardholderType {
452    type Err = stripe_types::StripeParseError;
453    fn from_str(s: &str) -> Result<Self, Self::Err> {
454        use IssuingCardholderType::*;
455        match s {
456            "company" => Ok(Company),
457            "individual" => Ok(Individual),
458            _ => Err(stripe_types::StripeParseError),
459        }
460    }
461}
462impl std::fmt::Display for IssuingCardholderType {
463    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
464        f.write_str(self.as_str())
465    }
466}
467
468impl std::fmt::Debug for IssuingCardholderType {
469    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
470        f.write_str(self.as_str())
471    }
472}
473impl serde::Serialize for IssuingCardholderType {
474    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
475    where
476        S: serde::Serializer,
477    {
478        serializer.serialize_str(self.as_str())
479    }
480}
481impl miniserde::Deserialize for IssuingCardholderType {
482    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
483        crate::Place::new(out)
484    }
485}
486
487impl miniserde::de::Visitor for crate::Place<IssuingCardholderType> {
488    fn string(&mut self, s: &str) -> miniserde::Result<()> {
489        use std::str::FromStr;
490        self.out = Some(IssuingCardholderType::from_str(s).map_err(|_| miniserde::Error)?);
491        Ok(())
492    }
493}
494
495stripe_types::impl_from_val_with_from_str!(IssuingCardholderType);
496#[cfg(feature = "deserialize")]
497impl<'de> serde::Deserialize<'de> for IssuingCardholderType {
498    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
499        use std::str::FromStr;
500        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
501        Self::from_str(&s)
502            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingCardholderType"))
503    }
504}