Skip to main content

stripe_shared/
card.rs

1/// You can store multiple cards on a customer in order to charge the customer
2/// later. You can also store multiple debit cards on a recipient in order to
3/// transfer to those cards later.
4///
5/// Related guide: [Card payments with Sources](https://docs.stripe.com/sources/cards)
6///
7/// For more details see <<https://stripe.com/docs/api/cards/object>>.
8#[derive(Clone)]
9#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
10#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
11pub struct Card {
12    pub account: Option<stripe_types::Expandable<stripe_shared::Account>>,
13    /// City/District/Suburb/Town/Village.
14    pub address_city: Option<String>,
15    /// Billing address country, if provided when creating card.
16    pub address_country: Option<String>,
17    /// Address line 1 (Street address/PO Box/Company name).
18    pub address_line1: Option<String>,
19    /// If `address_line1` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
20    pub address_line1_check: Option<String>,
21    /// Address line 2 (Apartment/Suite/Unit/Building).
22    pub address_line2: Option<String>,
23    /// State/County/Province/Region.
24    pub address_state: Option<String>,
25    /// ZIP or postal code.
26    pub address_zip: Option<String>,
27    /// If `address_zip` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
28    pub address_zip_check: Option<String>,
29    /// This field indicates whether this payment method can be shown again to its customer in a checkout flow.
30    /// Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow.
31    /// The field defaults to “unspecified”.
32    pub allow_redisplay: Option<CardAllowRedisplay>,
33    /// A set of available payout methods for this card.
34    /// Only values from this set should be passed as the `method` when creating a payout.
35    pub available_payout_methods: Option<Vec<CardAvailablePayoutMethods>>,
36    /// Card brand.
37    /// Can be `American Express`, `Cartes Bancaires`, `Diners Club`, `Discover`, `Eftpos Australia`, `Girocard`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
38    pub brand: String,
39    /// Two-letter ISO code representing the country of the card.
40    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
41    pub country: Option<String>,
42    /// Three-letter [ISO code for currency](https://www.iso.org/iso-4217-currency-codes.html) in lowercase.
43    /// Must be a [supported currency](https://docs.stripe.com/currencies).
44    /// Only applicable on accounts (not customers or recipients).
45    /// The card can be used as a transfer destination for funds in this currency.
46    /// This property is only available when returned as an [External Account](/api/external_account_cards/object) where [controller.is_controller](/api/accounts/object#account_object-controller-is_controller) is `true`.
47    pub currency: Option<stripe_types::Currency>,
48    /// The customer that this card belongs to.
49    /// This attribute will not be in the card object if the card belongs to an account or recipient instead.
50    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
51    /// If a CVC was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
52    /// A result of unchecked indicates that CVC was provided but hasn't been checked yet.
53    /// Checks are typically performed when attaching a card to a Customer object, or when creating a charge.
54    /// For more details, see [Check if a card is valid without a charge](https://support.stripe.com/questions/check-if-a-card-is-valid-without-a-charge).
55    pub cvc_check: Option<String>,
56    /// Whether this card is the default external account for its currency.
57    /// This property is only available for accounts where [controller.requirement_collection](/api/accounts/object#account_object-controller-requirement_collection) is `application`, which includes Custom accounts.
58    pub default_for_currency: Option<bool>,
59    /// A high-level description of the type of cards issued in this range.
60    /// (For internal use only and not typically available in standard API requests.).
61    pub description: Option<String>,
62    /// (For tokenized numbers only.) The last four digits of the device account number.
63    pub dynamic_last4: Option<String>,
64    /// Two-digit number representing the card's expiration month.
65    pub exp_month: i64,
66    /// Four-digit number representing the card's expiration year.
67    pub exp_year: i64,
68    /// Uniquely identifies this particular card number.
69    /// You can use this attribute to check whether two customers who’ve signed up with you are using the same card number, for example.
70    /// For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
71    ///
72    /// *As of May 1, 2021, card fingerprint in India for Connect changed to allow two fingerprints for the same card---one for India and one for the rest of the world.*.
73    pub fingerprint: Option<String>,
74    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
75    pub funding: String,
76    /// Unique identifier for the object.
77    pub id: stripe_shared::CardId,
78    /// Issuer identification number of the card.
79    /// (For internal use only and not typically available in standard API requests.).
80    pub iin: Option<String>,
81    /// The name of the card's issuing bank.
82    /// (For internal use only and not typically available in standard API requests.).
83    pub issuer: Option<String>,
84    /// The last four digits of the card.
85    pub last4: String,
86    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
87    /// This can be useful for storing additional information about the object in a structured format.
88    pub metadata: Option<std::collections::HashMap<String, String>>,
89    /// Cardholder name.
90    pub name: Option<String>,
91    pub networks: Option<stripe_shared::TokenCardNetworks>,
92    /// Status of a card based on the card issuer.
93    pub regulated_status: Option<CardRegulatedStatus>,
94    /// For external accounts that are cards, possible values are `new` and `errored`.
95    /// If a payout fails, the status is set to `errored` and [scheduled payouts](https://stripe.com/docs/payouts#payout-schedule) are stopped until account details are updated.
96    pub status: Option<String>,
97    /// If the card number is tokenized, this is the method that was used.
98    /// Can be `android_pay` (includes Google Pay), `apple_pay`, `masterpass`, `visa_checkout`, or null.
99    pub tokenization_method: Option<String>,
100}
101#[cfg(feature = "redact-generated-debug")]
102impl std::fmt::Debug for Card {
103    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
104        f.debug_struct("Card").finish_non_exhaustive()
105    }
106}
107#[doc(hidden)]
108pub struct CardBuilder {
109    account: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
110    address_city: Option<Option<String>>,
111    address_country: Option<Option<String>>,
112    address_line1: Option<Option<String>>,
113    address_line1_check: Option<Option<String>>,
114    address_line2: Option<Option<String>>,
115    address_state: Option<Option<String>>,
116    address_zip: Option<Option<String>>,
117    address_zip_check: Option<Option<String>>,
118    allow_redisplay: Option<Option<CardAllowRedisplay>>,
119    available_payout_methods: Option<Option<Vec<CardAvailablePayoutMethods>>>,
120    brand: Option<String>,
121    country: Option<Option<String>>,
122    currency: Option<Option<stripe_types::Currency>>,
123    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
124    cvc_check: Option<Option<String>>,
125    default_for_currency: Option<Option<bool>>,
126    description: Option<Option<String>>,
127    dynamic_last4: Option<Option<String>>,
128    exp_month: Option<i64>,
129    exp_year: Option<i64>,
130    fingerprint: Option<Option<String>>,
131    funding: Option<String>,
132    id: Option<stripe_shared::CardId>,
133    iin: Option<Option<String>>,
134    issuer: Option<Option<String>>,
135    last4: Option<String>,
136    metadata: Option<Option<std::collections::HashMap<String, String>>>,
137    name: Option<Option<String>>,
138    networks: Option<Option<stripe_shared::TokenCardNetworks>>,
139    regulated_status: Option<Option<CardRegulatedStatus>>,
140    status: Option<Option<String>>,
141    tokenization_method: Option<Option<String>>,
142}
143
144#[allow(
145    unused_variables,
146    irrefutable_let_patterns,
147    clippy::let_unit_value,
148    clippy::match_single_binding,
149    clippy::single_match
150)]
151const _: () = {
152    use miniserde::de::{Map, Visitor};
153    use miniserde::json::Value;
154    use miniserde::{Deserialize, Result, make_place};
155    use stripe_types::miniserde_helpers::FromValueOpt;
156    use stripe_types::{MapBuilder, ObjectDeser};
157
158    make_place!(Place);
159
160    impl Deserialize for Card {
161        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
162            Place::new(out)
163        }
164    }
165
166    struct Builder<'a> {
167        out: &'a mut Option<Card>,
168        builder: CardBuilder,
169    }
170
171    impl Visitor for Place<Card> {
172        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
173            Ok(Box::new(Builder { out: &mut self.out, builder: CardBuilder::deser_default() }))
174        }
175    }
176
177    impl MapBuilder for CardBuilder {
178        type Out = Card;
179        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
180            Ok(match k {
181                "account" => Deserialize::begin(&mut self.account),
182                "address_city" => Deserialize::begin(&mut self.address_city),
183                "address_country" => Deserialize::begin(&mut self.address_country),
184                "address_line1" => Deserialize::begin(&mut self.address_line1),
185                "address_line1_check" => Deserialize::begin(&mut self.address_line1_check),
186                "address_line2" => Deserialize::begin(&mut self.address_line2),
187                "address_state" => Deserialize::begin(&mut self.address_state),
188                "address_zip" => Deserialize::begin(&mut self.address_zip),
189                "address_zip_check" => Deserialize::begin(&mut self.address_zip_check),
190                "allow_redisplay" => Deserialize::begin(&mut self.allow_redisplay),
191                "available_payout_methods" => {
192                    Deserialize::begin(&mut self.available_payout_methods)
193                }
194                "brand" => Deserialize::begin(&mut self.brand),
195                "country" => Deserialize::begin(&mut self.country),
196                "currency" => Deserialize::begin(&mut self.currency),
197                "customer" => Deserialize::begin(&mut self.customer),
198                "cvc_check" => Deserialize::begin(&mut self.cvc_check),
199                "default_for_currency" => Deserialize::begin(&mut self.default_for_currency),
200                "description" => Deserialize::begin(&mut self.description),
201                "dynamic_last4" => Deserialize::begin(&mut self.dynamic_last4),
202                "exp_month" => Deserialize::begin(&mut self.exp_month),
203                "exp_year" => Deserialize::begin(&mut self.exp_year),
204                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
205                "funding" => Deserialize::begin(&mut self.funding),
206                "id" => Deserialize::begin(&mut self.id),
207                "iin" => Deserialize::begin(&mut self.iin),
208                "issuer" => Deserialize::begin(&mut self.issuer),
209                "last4" => Deserialize::begin(&mut self.last4),
210                "metadata" => Deserialize::begin(&mut self.metadata),
211                "name" => Deserialize::begin(&mut self.name),
212                "networks" => Deserialize::begin(&mut self.networks),
213                "regulated_status" => Deserialize::begin(&mut self.regulated_status),
214                "status" => Deserialize::begin(&mut self.status),
215                "tokenization_method" => Deserialize::begin(&mut self.tokenization_method),
216                _ => <dyn Visitor>::ignore(),
217            })
218        }
219
220        fn deser_default() -> Self {
221            Self {
222                account: Some(None),
223                address_city: Some(None),
224                address_country: Some(None),
225                address_line1: Some(None),
226                address_line1_check: Some(None),
227                address_line2: Some(None),
228                address_state: Some(None),
229                address_zip: Some(None),
230                address_zip_check: Some(None),
231                allow_redisplay: Some(None),
232                available_payout_methods: Some(None),
233                brand: None,
234                country: Some(None),
235                currency: Some(None),
236                customer: Some(None),
237                cvc_check: Some(None),
238                default_for_currency: Some(None),
239                description: Some(None),
240                dynamic_last4: Some(None),
241                exp_month: None,
242                exp_year: None,
243                fingerprint: Some(None),
244                funding: None,
245                id: None,
246                iin: Some(None),
247                issuer: Some(None),
248                last4: None,
249                metadata: Some(None),
250                name: Some(None),
251                networks: Some(None),
252                regulated_status: Some(None),
253                status: Some(None),
254                tokenization_method: Some(None),
255            }
256        }
257
258        fn take_out(&mut self) -> Option<Self::Out> {
259            let (
260                Some(account),
261                Some(address_city),
262                Some(address_country),
263                Some(address_line1),
264                Some(address_line1_check),
265                Some(address_line2),
266                Some(address_state),
267                Some(address_zip),
268                Some(address_zip_check),
269                Some(allow_redisplay),
270                Some(available_payout_methods),
271                Some(brand),
272                Some(country),
273                Some(currency),
274                Some(customer),
275                Some(cvc_check),
276                Some(default_for_currency),
277                Some(description),
278                Some(dynamic_last4),
279                Some(exp_month),
280                Some(exp_year),
281                Some(fingerprint),
282                Some(funding),
283                Some(id),
284                Some(iin),
285                Some(issuer),
286                Some(last4),
287                Some(metadata),
288                Some(name),
289                Some(networks),
290                Some(regulated_status),
291                Some(status),
292                Some(tokenization_method),
293            ) = (
294                self.account.take(),
295                self.address_city.take(),
296                self.address_country.take(),
297                self.address_line1.take(),
298                self.address_line1_check.take(),
299                self.address_line2.take(),
300                self.address_state.take(),
301                self.address_zip.take(),
302                self.address_zip_check.take(),
303                self.allow_redisplay.take(),
304                self.available_payout_methods.take(),
305                self.brand.take(),
306                self.country.take(),
307                self.currency.take(),
308                self.customer.take(),
309                self.cvc_check.take(),
310                self.default_for_currency,
311                self.description.take(),
312                self.dynamic_last4.take(),
313                self.exp_month,
314                self.exp_year,
315                self.fingerprint.take(),
316                self.funding.take(),
317                self.id.take(),
318                self.iin.take(),
319                self.issuer.take(),
320                self.last4.take(),
321                self.metadata.take(),
322                self.name.take(),
323                self.networks.take(),
324                self.regulated_status.take(),
325                self.status.take(),
326                self.tokenization_method.take(),
327            )
328            else {
329                return None;
330            };
331            Some(Self::Out {
332                account,
333                address_city,
334                address_country,
335                address_line1,
336                address_line1_check,
337                address_line2,
338                address_state,
339                address_zip,
340                address_zip_check,
341                allow_redisplay,
342                available_payout_methods,
343                brand,
344                country,
345                currency,
346                customer,
347                cvc_check,
348                default_for_currency,
349                description,
350                dynamic_last4,
351                exp_month,
352                exp_year,
353                fingerprint,
354                funding,
355                id,
356                iin,
357                issuer,
358                last4,
359                metadata,
360                name,
361                networks,
362                regulated_status,
363                status,
364                tokenization_method,
365            })
366        }
367    }
368
369    impl Map for Builder<'_> {
370        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
371            self.builder.key(k)
372        }
373
374        fn finish(&mut self) -> Result<()> {
375            *self.out = self.builder.take_out();
376            Ok(())
377        }
378    }
379
380    impl ObjectDeser for Card {
381        type Builder = CardBuilder;
382    }
383
384    impl FromValueOpt for Card {
385        fn from_value(v: Value) -> Option<Self> {
386            let Value::Object(obj) = v else {
387                return None;
388            };
389            let mut b = CardBuilder::deser_default();
390            for (k, v) in obj {
391                match k.as_str() {
392                    "account" => b.account = FromValueOpt::from_value(v),
393                    "address_city" => b.address_city = FromValueOpt::from_value(v),
394                    "address_country" => b.address_country = FromValueOpt::from_value(v),
395                    "address_line1" => b.address_line1 = FromValueOpt::from_value(v),
396                    "address_line1_check" => b.address_line1_check = FromValueOpt::from_value(v),
397                    "address_line2" => b.address_line2 = FromValueOpt::from_value(v),
398                    "address_state" => b.address_state = FromValueOpt::from_value(v),
399                    "address_zip" => b.address_zip = FromValueOpt::from_value(v),
400                    "address_zip_check" => b.address_zip_check = FromValueOpt::from_value(v),
401                    "allow_redisplay" => b.allow_redisplay = FromValueOpt::from_value(v),
402                    "available_payout_methods" => {
403                        b.available_payout_methods = FromValueOpt::from_value(v)
404                    }
405                    "brand" => b.brand = FromValueOpt::from_value(v),
406                    "country" => b.country = FromValueOpt::from_value(v),
407                    "currency" => b.currency = FromValueOpt::from_value(v),
408                    "customer" => b.customer = FromValueOpt::from_value(v),
409                    "cvc_check" => b.cvc_check = FromValueOpt::from_value(v),
410                    "default_for_currency" => b.default_for_currency = FromValueOpt::from_value(v),
411                    "description" => b.description = FromValueOpt::from_value(v),
412                    "dynamic_last4" => b.dynamic_last4 = FromValueOpt::from_value(v),
413                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
414                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
415                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
416                    "funding" => b.funding = FromValueOpt::from_value(v),
417                    "id" => b.id = FromValueOpt::from_value(v),
418                    "iin" => b.iin = FromValueOpt::from_value(v),
419                    "issuer" => b.issuer = FromValueOpt::from_value(v),
420                    "last4" => b.last4 = FromValueOpt::from_value(v),
421                    "metadata" => b.metadata = FromValueOpt::from_value(v),
422                    "name" => b.name = FromValueOpt::from_value(v),
423                    "networks" => b.networks = FromValueOpt::from_value(v),
424                    "regulated_status" => b.regulated_status = FromValueOpt::from_value(v),
425                    "status" => b.status = FromValueOpt::from_value(v),
426                    "tokenization_method" => b.tokenization_method = FromValueOpt::from_value(v),
427                    _ => {}
428                }
429            }
430            b.take_out()
431        }
432    }
433};
434#[cfg(feature = "serialize")]
435impl serde::Serialize for Card {
436    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
437        use serde::ser::SerializeStruct;
438        let mut s = s.serialize_struct("Card", 34)?;
439        s.serialize_field("account", &self.account)?;
440        s.serialize_field("address_city", &self.address_city)?;
441        s.serialize_field("address_country", &self.address_country)?;
442        s.serialize_field("address_line1", &self.address_line1)?;
443        s.serialize_field("address_line1_check", &self.address_line1_check)?;
444        s.serialize_field("address_line2", &self.address_line2)?;
445        s.serialize_field("address_state", &self.address_state)?;
446        s.serialize_field("address_zip", &self.address_zip)?;
447        s.serialize_field("address_zip_check", &self.address_zip_check)?;
448        s.serialize_field("allow_redisplay", &self.allow_redisplay)?;
449        s.serialize_field("available_payout_methods", &self.available_payout_methods)?;
450        s.serialize_field("brand", &self.brand)?;
451        s.serialize_field("country", &self.country)?;
452        s.serialize_field("currency", &self.currency)?;
453        s.serialize_field("customer", &self.customer)?;
454        s.serialize_field("cvc_check", &self.cvc_check)?;
455        s.serialize_field("default_for_currency", &self.default_for_currency)?;
456        s.serialize_field("description", &self.description)?;
457        s.serialize_field("dynamic_last4", &self.dynamic_last4)?;
458        s.serialize_field("exp_month", &self.exp_month)?;
459        s.serialize_field("exp_year", &self.exp_year)?;
460        s.serialize_field("fingerprint", &self.fingerprint)?;
461        s.serialize_field("funding", &self.funding)?;
462        s.serialize_field("id", &self.id)?;
463        s.serialize_field("iin", &self.iin)?;
464        s.serialize_field("issuer", &self.issuer)?;
465        s.serialize_field("last4", &self.last4)?;
466        s.serialize_field("metadata", &self.metadata)?;
467        s.serialize_field("name", &self.name)?;
468        s.serialize_field("networks", &self.networks)?;
469        s.serialize_field("regulated_status", &self.regulated_status)?;
470        s.serialize_field("status", &self.status)?;
471        s.serialize_field("tokenization_method", &self.tokenization_method)?;
472
473        s.serialize_field("object", "card")?;
474        s.end()
475    }
476}
477/// This field indicates whether this payment method can be shown again to its customer in a checkout flow.
478/// Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow.
479/// The field defaults to “unspecified”.
480#[derive(Clone, Eq, PartialEq)]
481#[non_exhaustive]
482pub enum CardAllowRedisplay {
483    Always,
484    Limited,
485    Unspecified,
486    /// An unrecognized value from Stripe. Should not be used as a request parameter.
487    Unknown(String),
488}
489impl CardAllowRedisplay {
490    pub fn as_str(&self) -> &str {
491        use CardAllowRedisplay::*;
492        match self {
493            Always => "always",
494            Limited => "limited",
495            Unspecified => "unspecified",
496            Unknown(v) => v,
497        }
498    }
499}
500
501impl std::str::FromStr for CardAllowRedisplay {
502    type Err = std::convert::Infallible;
503    fn from_str(s: &str) -> Result<Self, Self::Err> {
504        use CardAllowRedisplay::*;
505        match s {
506            "always" => Ok(Always),
507            "limited" => Ok(Limited),
508            "unspecified" => Ok(Unspecified),
509            v => {
510                tracing::warn!("Unknown value '{}' for enum '{}'", v, "CardAllowRedisplay");
511                Ok(Unknown(v.to_owned()))
512            }
513        }
514    }
515}
516impl std::fmt::Display for CardAllowRedisplay {
517    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
518        f.write_str(self.as_str())
519    }
520}
521
522#[cfg(not(feature = "redact-generated-debug"))]
523impl std::fmt::Debug for CardAllowRedisplay {
524    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
525        f.write_str(self.as_str())
526    }
527}
528#[cfg(feature = "redact-generated-debug")]
529impl std::fmt::Debug for CardAllowRedisplay {
530    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
531        f.debug_struct(stringify!(CardAllowRedisplay)).finish_non_exhaustive()
532    }
533}
534#[cfg(feature = "serialize")]
535impl serde::Serialize for CardAllowRedisplay {
536    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
537    where
538        S: serde::Serializer,
539    {
540        serializer.serialize_str(self.as_str())
541    }
542}
543impl miniserde::Deserialize for CardAllowRedisplay {
544    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
545        crate::Place::new(out)
546    }
547}
548
549impl miniserde::de::Visitor for crate::Place<CardAllowRedisplay> {
550    fn string(&mut self, s: &str) -> miniserde::Result<()> {
551        use std::str::FromStr;
552        self.out = Some(CardAllowRedisplay::from_str(s).expect("infallible"));
553        Ok(())
554    }
555}
556
557stripe_types::impl_from_val_with_from_str!(CardAllowRedisplay);
558#[cfg(feature = "deserialize")]
559impl<'de> serde::Deserialize<'de> for CardAllowRedisplay {
560    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
561        use std::str::FromStr;
562        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
563        Ok(Self::from_str(&s).expect("infallible"))
564    }
565}
566/// A set of available payout methods for this card.
567/// Only values from this set should be passed as the `method` when creating a payout.
568#[derive(Clone, Eq, PartialEq)]
569#[non_exhaustive]
570pub enum CardAvailablePayoutMethods {
571    Instant,
572    Standard,
573    /// An unrecognized value from Stripe. Should not be used as a request parameter.
574    Unknown(String),
575}
576impl CardAvailablePayoutMethods {
577    pub fn as_str(&self) -> &str {
578        use CardAvailablePayoutMethods::*;
579        match self {
580            Instant => "instant",
581            Standard => "standard",
582            Unknown(v) => v,
583        }
584    }
585}
586
587impl std::str::FromStr for CardAvailablePayoutMethods {
588    type Err = std::convert::Infallible;
589    fn from_str(s: &str) -> Result<Self, Self::Err> {
590        use CardAvailablePayoutMethods::*;
591        match s {
592            "instant" => Ok(Instant),
593            "standard" => Ok(Standard),
594            v => {
595                tracing::warn!("Unknown value '{}' for enum '{}'", v, "CardAvailablePayoutMethods");
596                Ok(Unknown(v.to_owned()))
597            }
598        }
599    }
600}
601impl std::fmt::Display for CardAvailablePayoutMethods {
602    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
603        f.write_str(self.as_str())
604    }
605}
606
607#[cfg(not(feature = "redact-generated-debug"))]
608impl std::fmt::Debug for CardAvailablePayoutMethods {
609    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
610        f.write_str(self.as_str())
611    }
612}
613#[cfg(feature = "redact-generated-debug")]
614impl std::fmt::Debug for CardAvailablePayoutMethods {
615    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
616        f.debug_struct(stringify!(CardAvailablePayoutMethods)).finish_non_exhaustive()
617    }
618}
619#[cfg(feature = "serialize")]
620impl serde::Serialize for CardAvailablePayoutMethods {
621    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
622    where
623        S: serde::Serializer,
624    {
625        serializer.serialize_str(self.as_str())
626    }
627}
628impl miniserde::Deserialize for CardAvailablePayoutMethods {
629    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
630        crate::Place::new(out)
631    }
632}
633
634impl miniserde::de::Visitor for crate::Place<CardAvailablePayoutMethods> {
635    fn string(&mut self, s: &str) -> miniserde::Result<()> {
636        use std::str::FromStr;
637        self.out = Some(CardAvailablePayoutMethods::from_str(s).expect("infallible"));
638        Ok(())
639    }
640}
641
642stripe_types::impl_from_val_with_from_str!(CardAvailablePayoutMethods);
643#[cfg(feature = "deserialize")]
644impl<'de> serde::Deserialize<'de> for CardAvailablePayoutMethods {
645    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
646        use std::str::FromStr;
647        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
648        Ok(Self::from_str(&s).expect("infallible"))
649    }
650}
651/// Status of a card based on the card issuer.
652#[derive(Clone, Eq, PartialEq)]
653#[non_exhaustive]
654pub enum CardRegulatedStatus {
655    Regulated,
656    Unregulated,
657    /// An unrecognized value from Stripe. Should not be used as a request parameter.
658    Unknown(String),
659}
660impl CardRegulatedStatus {
661    pub fn as_str(&self) -> &str {
662        use CardRegulatedStatus::*;
663        match self {
664            Regulated => "regulated",
665            Unregulated => "unregulated",
666            Unknown(v) => v,
667        }
668    }
669}
670
671impl std::str::FromStr for CardRegulatedStatus {
672    type Err = std::convert::Infallible;
673    fn from_str(s: &str) -> Result<Self, Self::Err> {
674        use CardRegulatedStatus::*;
675        match s {
676            "regulated" => Ok(Regulated),
677            "unregulated" => Ok(Unregulated),
678            v => {
679                tracing::warn!("Unknown value '{}' for enum '{}'", v, "CardRegulatedStatus");
680                Ok(Unknown(v.to_owned()))
681            }
682        }
683    }
684}
685impl std::fmt::Display for CardRegulatedStatus {
686    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
687        f.write_str(self.as_str())
688    }
689}
690
691#[cfg(not(feature = "redact-generated-debug"))]
692impl std::fmt::Debug for CardRegulatedStatus {
693    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
694        f.write_str(self.as_str())
695    }
696}
697#[cfg(feature = "redact-generated-debug")]
698impl std::fmt::Debug for CardRegulatedStatus {
699    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
700        f.debug_struct(stringify!(CardRegulatedStatus)).finish_non_exhaustive()
701    }
702}
703#[cfg(feature = "serialize")]
704impl serde::Serialize for CardRegulatedStatus {
705    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
706    where
707        S: serde::Serializer,
708    {
709        serializer.serialize_str(self.as_str())
710    }
711}
712impl miniserde::Deserialize for CardRegulatedStatus {
713    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
714        crate::Place::new(out)
715    }
716}
717
718impl miniserde::de::Visitor for crate::Place<CardRegulatedStatus> {
719    fn string(&mut self, s: &str) -> miniserde::Result<()> {
720        use std::str::FromStr;
721        self.out = Some(CardRegulatedStatus::from_str(s).expect("infallible"));
722        Ok(())
723    }
724}
725
726stripe_types::impl_from_val_with_from_str!(CardRegulatedStatus);
727#[cfg(feature = "deserialize")]
728impl<'de> serde::Deserialize<'de> for CardRegulatedStatus {
729    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
730        use std::str::FromStr;
731        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
732        Ok(Self::from_str(&s).expect("infallible"))
733    }
734}
735impl stripe_types::Object for Card {
736    type Id = stripe_shared::CardId;
737    fn id(&self) -> &Self::Id {
738        &self.id
739    }
740
741    fn into_id(self) -> Self::Id {
742        self.id
743    }
744}
745stripe_types::def_id!(CardId);