Skip to main content

stripe_shared/
issuing_cardholder.rs

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