Skip to main content

stripe_shared/
payment_method_card.rs

1#[derive(Clone)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentMethodCard {
6    /// Card brand.
7    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `jcb`, `link`, `mastercard`, `unionpay`, `visa` or `unknown`.
8    pub brand: String,
9    /// Checks on Card address and CVC if provided.
10    pub checks: Option<stripe_shared::PaymentMethodCardChecks>,
11    /// Two-letter ISO code representing the country of the card.
12    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
13    pub country: Option<String>,
14    /// A high-level description of the type of cards issued in this range.
15    /// (For internal use only and not typically available in standard API requests.).
16    pub description: Option<String>,
17    /// The brand to use when displaying the card, this accounts for customer's brand choice on dual-branded cards.
18    /// Can be `american_express`, `cartes_bancaires`, `diners_club`, `discover`, `eftpos_australia`, `interac`, `jcb`, `mastercard`, `union_pay`, `visa`, or `other` and may contain more values in the future.
19    pub display_brand: Option<String>,
20    /// Two-digit number representing the card's expiration month.
21    pub exp_month: i64,
22    /// Four-digit number representing the card's expiration year.
23    pub exp_year: i64,
24    /// Uniquely identifies this particular card number.
25    /// You can use this attribute to check whether two customers who’ve signed up with you are using the same card number, for example.
26    /// For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
27    ///
28    /// *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.*.
29    pub fingerprint: Option<String>,
30    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
31    pub funding: String,
32    /// Details of the original PaymentMethod that created this object.
33    pub generated_from: Option<stripe_shared::PaymentMethodCardGeneratedCard>,
34    /// Issuer identification number of the card.
35    /// (For internal use only and not typically available in standard API requests.).
36    pub iin: Option<String>,
37    /// The name of the card's issuing bank.
38    /// (For internal use only and not typically available in standard API requests.).
39    pub issuer: Option<String>,
40    /// The last four digits of the card.
41    pub last4: String,
42    /// Contains information about card networks that can be used to process the payment.
43    pub networks: Option<stripe_shared::Networks>,
44    /// Status of a card based on the card issuer.
45    pub regulated_status: Option<PaymentMethodCardRegulatedStatus>,
46    /// Contains details on how this Card may be used for 3D Secure authentication.
47    pub three_d_secure_usage: Option<stripe_shared::ThreeDSecureUsage>,
48    /// If this Card is part of a card wallet, this contains the details of the card wallet.
49    pub wallet: Option<stripe_shared::PaymentMethodCardWallet>,
50}
51#[cfg(feature = "redact-generated-debug")]
52impl std::fmt::Debug for PaymentMethodCard {
53    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54        f.debug_struct("PaymentMethodCard").finish_non_exhaustive()
55    }
56}
57#[doc(hidden)]
58pub struct PaymentMethodCardBuilder {
59    brand: Option<String>,
60    checks: Option<Option<stripe_shared::PaymentMethodCardChecks>>,
61    country: Option<Option<String>>,
62    description: Option<Option<String>>,
63    display_brand: Option<Option<String>>,
64    exp_month: Option<i64>,
65    exp_year: Option<i64>,
66    fingerprint: Option<Option<String>>,
67    funding: Option<String>,
68    generated_from: Option<Option<stripe_shared::PaymentMethodCardGeneratedCard>>,
69    iin: Option<Option<String>>,
70    issuer: Option<Option<String>>,
71    last4: Option<String>,
72    networks: Option<Option<stripe_shared::Networks>>,
73    regulated_status: Option<Option<PaymentMethodCardRegulatedStatus>>,
74    three_d_secure_usage: Option<Option<stripe_shared::ThreeDSecureUsage>>,
75    wallet: Option<Option<stripe_shared::PaymentMethodCardWallet>>,
76}
77
78#[allow(
79    unused_variables,
80    irrefutable_let_patterns,
81    clippy::let_unit_value,
82    clippy::match_single_binding,
83    clippy::single_match
84)]
85const _: () = {
86    use miniserde::de::{Map, Visitor};
87    use miniserde::json::Value;
88    use miniserde::{Deserialize, Result, make_place};
89    use stripe_types::miniserde_helpers::FromValueOpt;
90    use stripe_types::{MapBuilder, ObjectDeser};
91
92    make_place!(Place);
93
94    impl Deserialize for PaymentMethodCard {
95        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
96            Place::new(out)
97        }
98    }
99
100    struct Builder<'a> {
101        out: &'a mut Option<PaymentMethodCard>,
102        builder: PaymentMethodCardBuilder,
103    }
104
105    impl Visitor for Place<PaymentMethodCard> {
106        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
107            Ok(Box::new(Builder {
108                out: &mut self.out,
109                builder: PaymentMethodCardBuilder::deser_default(),
110            }))
111        }
112    }
113
114    impl MapBuilder for PaymentMethodCardBuilder {
115        type Out = PaymentMethodCard;
116        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
117            Ok(match k {
118                "brand" => Deserialize::begin(&mut self.brand),
119                "checks" => Deserialize::begin(&mut self.checks),
120                "country" => Deserialize::begin(&mut self.country),
121                "description" => Deserialize::begin(&mut self.description),
122                "display_brand" => Deserialize::begin(&mut self.display_brand),
123                "exp_month" => Deserialize::begin(&mut self.exp_month),
124                "exp_year" => Deserialize::begin(&mut self.exp_year),
125                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
126                "funding" => Deserialize::begin(&mut self.funding),
127                "generated_from" => Deserialize::begin(&mut self.generated_from),
128                "iin" => Deserialize::begin(&mut self.iin),
129                "issuer" => Deserialize::begin(&mut self.issuer),
130                "last4" => Deserialize::begin(&mut self.last4),
131                "networks" => Deserialize::begin(&mut self.networks),
132                "regulated_status" => Deserialize::begin(&mut self.regulated_status),
133                "three_d_secure_usage" => Deserialize::begin(&mut self.three_d_secure_usage),
134                "wallet" => Deserialize::begin(&mut self.wallet),
135                _ => <dyn Visitor>::ignore(),
136            })
137        }
138
139        fn deser_default() -> Self {
140            Self {
141                brand: None,
142                checks: Some(None),
143                country: Some(None),
144                description: Some(None),
145                display_brand: Some(None),
146                exp_month: None,
147                exp_year: None,
148                fingerprint: Some(None),
149                funding: None,
150                generated_from: Some(None),
151                iin: Some(None),
152                issuer: Some(None),
153                last4: None,
154                networks: Some(None),
155                regulated_status: Some(None),
156                three_d_secure_usage: Some(None),
157                wallet: Some(None),
158            }
159        }
160
161        fn take_out(&mut self) -> Option<Self::Out> {
162            let (
163                Some(brand),
164                Some(checks),
165                Some(country),
166                Some(description),
167                Some(display_brand),
168                Some(exp_month),
169                Some(exp_year),
170                Some(fingerprint),
171                Some(funding),
172                Some(generated_from),
173                Some(iin),
174                Some(issuer),
175                Some(last4),
176                Some(networks),
177                Some(regulated_status),
178                Some(three_d_secure_usage),
179                Some(wallet),
180            ) = (
181                self.brand.take(),
182                self.checks.take(),
183                self.country.take(),
184                self.description.take(),
185                self.display_brand.take(),
186                self.exp_month,
187                self.exp_year,
188                self.fingerprint.take(),
189                self.funding.take(),
190                self.generated_from.take(),
191                self.iin.take(),
192                self.issuer.take(),
193                self.last4.take(),
194                self.networks.take(),
195                self.regulated_status.take(),
196                self.three_d_secure_usage,
197                self.wallet.take(),
198            )
199            else {
200                return None;
201            };
202            Some(Self::Out {
203                brand,
204                checks,
205                country,
206                description,
207                display_brand,
208                exp_month,
209                exp_year,
210                fingerprint,
211                funding,
212                generated_from,
213                iin,
214                issuer,
215                last4,
216                networks,
217                regulated_status,
218                three_d_secure_usage,
219                wallet,
220            })
221        }
222    }
223
224    impl Map for Builder<'_> {
225        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
226            self.builder.key(k)
227        }
228
229        fn finish(&mut self) -> Result<()> {
230            *self.out = self.builder.take_out();
231            Ok(())
232        }
233    }
234
235    impl ObjectDeser for PaymentMethodCard {
236        type Builder = PaymentMethodCardBuilder;
237    }
238
239    impl FromValueOpt for PaymentMethodCard {
240        fn from_value(v: Value) -> Option<Self> {
241            let Value::Object(obj) = v else {
242                return None;
243            };
244            let mut b = PaymentMethodCardBuilder::deser_default();
245            for (k, v) in obj {
246                match k.as_str() {
247                    "brand" => b.brand = FromValueOpt::from_value(v),
248                    "checks" => b.checks = FromValueOpt::from_value(v),
249                    "country" => b.country = FromValueOpt::from_value(v),
250                    "description" => b.description = FromValueOpt::from_value(v),
251                    "display_brand" => b.display_brand = FromValueOpt::from_value(v),
252                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
253                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
254                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
255                    "funding" => b.funding = FromValueOpt::from_value(v),
256                    "generated_from" => b.generated_from = FromValueOpt::from_value(v),
257                    "iin" => b.iin = FromValueOpt::from_value(v),
258                    "issuer" => b.issuer = FromValueOpt::from_value(v),
259                    "last4" => b.last4 = FromValueOpt::from_value(v),
260                    "networks" => b.networks = FromValueOpt::from_value(v),
261                    "regulated_status" => b.regulated_status = FromValueOpt::from_value(v),
262                    "three_d_secure_usage" => b.three_d_secure_usage = FromValueOpt::from_value(v),
263                    "wallet" => b.wallet = FromValueOpt::from_value(v),
264                    _ => {}
265                }
266            }
267            b.take_out()
268        }
269    }
270};
271/// Status of a card based on the card issuer.
272#[derive(Clone, Eq, PartialEq)]
273#[non_exhaustive]
274pub enum PaymentMethodCardRegulatedStatus {
275    Regulated,
276    Unregulated,
277    /// An unrecognized value from Stripe. Should not be used as a request parameter.
278    Unknown(String),
279}
280impl PaymentMethodCardRegulatedStatus {
281    pub fn as_str(&self) -> &str {
282        use PaymentMethodCardRegulatedStatus::*;
283        match self {
284            Regulated => "regulated",
285            Unregulated => "unregulated",
286            Unknown(v) => v,
287        }
288    }
289}
290
291impl std::str::FromStr for PaymentMethodCardRegulatedStatus {
292    type Err = std::convert::Infallible;
293    fn from_str(s: &str) -> Result<Self, Self::Err> {
294        use PaymentMethodCardRegulatedStatus::*;
295        match s {
296            "regulated" => Ok(Regulated),
297            "unregulated" => Ok(Unregulated),
298            v => {
299                tracing::warn!(
300                    "Unknown value '{}' for enum '{}'",
301                    v,
302                    "PaymentMethodCardRegulatedStatus"
303                );
304                Ok(Unknown(v.to_owned()))
305            }
306        }
307    }
308}
309impl std::fmt::Display for PaymentMethodCardRegulatedStatus {
310    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
311        f.write_str(self.as_str())
312    }
313}
314
315#[cfg(not(feature = "redact-generated-debug"))]
316impl std::fmt::Debug for PaymentMethodCardRegulatedStatus {
317    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
318        f.write_str(self.as_str())
319    }
320}
321#[cfg(feature = "redact-generated-debug")]
322impl std::fmt::Debug for PaymentMethodCardRegulatedStatus {
323    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
324        f.debug_struct(stringify!(PaymentMethodCardRegulatedStatus)).finish_non_exhaustive()
325    }
326}
327#[cfg(feature = "serialize")]
328impl serde::Serialize for PaymentMethodCardRegulatedStatus {
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 PaymentMethodCardRegulatedStatus {
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<PaymentMethodCardRegulatedStatus> {
343    fn string(&mut self, s: &str) -> miniserde::Result<()> {
344        use std::str::FromStr;
345        self.out = Some(PaymentMethodCardRegulatedStatus::from_str(s).expect("infallible"));
346        Ok(())
347    }
348}
349
350stripe_types::impl_from_val_with_from_str!(PaymentMethodCardRegulatedStatus);
351#[cfg(feature = "deserialize")]
352impl<'de> serde::Deserialize<'de> for PaymentMethodCardRegulatedStatus {
353    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
354        use std::str::FromStr;
355        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
356        Ok(Self::from_str(&s).expect("infallible"))
357    }
358}