Skip to main content

stripe_shared/
payment_method_interac_present.rs

1#[derive(Clone, Eq, PartialEq)]
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 PaymentMethodInteracPresent {
6    /// Card brand. Can be `interac`, `mastercard` or `visa`.
7    pub brand: Option<String>,
8    /// The cardholder name as read from the card, in [ISO 7813](https://en.wikipedia.org/wiki/ISO/IEC_7813) format.
9    /// May include alphanumeric characters, special characters and first/last name separator (`/`).
10    /// In some cases, the cardholder name may not be available depending on how the issuer has configured the card.
11    /// Cardholder name is typically not available on swipe or contactless payments, such as those made with Apple Pay and Google Pay.
12    pub cardholder_name: Option<String>,
13    /// Two-letter ISO code representing the country of the card.
14    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
15    pub country: Option<String>,
16    /// A high-level description of the type of cards issued in this range.
17    /// (For internal use only and not typically available in standard API requests.).
18    pub description: Option<String>,
19    /// Two-digit number representing the card's expiration month.
20    pub exp_month: i64,
21    /// Four-digit number representing the card's expiration year.
22    pub exp_year: i64,
23    /// Uniquely identifies this particular card number.
24    /// You can use this attribute to check whether two customers who’ve signed up with you are using the same card number, for example.
25    /// For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
26    ///
27    /// *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.*.
28    pub fingerprint: Option<String>,
29    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
30    pub funding: Option<String>,
31    /// Issuer identification number of the card.
32    /// (For internal use only and not typically available in standard API requests.).
33    pub iin: Option<String>,
34    /// The name of the card's issuing bank.
35    /// (For internal use only and not typically available in standard API requests.).
36    pub issuer: Option<String>,
37    /// The last four digits of the card.
38    pub last4: Option<String>,
39    /// Contains information about card networks that can be used to process the payment.
40    pub networks: Option<stripe_shared::PaymentMethodCardPresentNetworks>,
41    /// The languages that the issuing bank recommends using for localizing any customer-facing text, as read from the card.
42    /// Referenced from EMV tag 5F2D, data encoded on the card's chip.
43    pub preferred_locales: Option<Vec<String>>,
44    /// How card details were read in this transaction.
45    pub read_method: Option<PaymentMethodInteracPresentReadMethod>,
46}
47#[cfg(feature = "redact-generated-debug")]
48impl std::fmt::Debug for PaymentMethodInteracPresent {
49    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
50        f.debug_struct("PaymentMethodInteracPresent").finish_non_exhaustive()
51    }
52}
53#[doc(hidden)]
54pub struct PaymentMethodInteracPresentBuilder {
55    brand: Option<Option<String>>,
56    cardholder_name: Option<Option<String>>,
57    country: Option<Option<String>>,
58    description: Option<Option<String>>,
59    exp_month: Option<i64>,
60    exp_year: Option<i64>,
61    fingerprint: Option<Option<String>>,
62    funding: Option<Option<String>>,
63    iin: Option<Option<String>>,
64    issuer: Option<Option<String>>,
65    last4: Option<Option<String>>,
66    networks: Option<Option<stripe_shared::PaymentMethodCardPresentNetworks>>,
67    preferred_locales: Option<Option<Vec<String>>>,
68    read_method: Option<Option<PaymentMethodInteracPresentReadMethod>>,
69}
70
71#[allow(
72    unused_variables,
73    irrefutable_let_patterns,
74    clippy::let_unit_value,
75    clippy::match_single_binding,
76    clippy::single_match
77)]
78const _: () = {
79    use miniserde::de::{Map, Visitor};
80    use miniserde::json::Value;
81    use miniserde::{Deserialize, Result, make_place};
82    use stripe_types::miniserde_helpers::FromValueOpt;
83    use stripe_types::{MapBuilder, ObjectDeser};
84
85    make_place!(Place);
86
87    impl Deserialize for PaymentMethodInteracPresent {
88        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
89            Place::new(out)
90        }
91    }
92
93    struct Builder<'a> {
94        out: &'a mut Option<PaymentMethodInteracPresent>,
95        builder: PaymentMethodInteracPresentBuilder,
96    }
97
98    impl Visitor for Place<PaymentMethodInteracPresent> {
99        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
100            Ok(Box::new(Builder {
101                out: &mut self.out,
102                builder: PaymentMethodInteracPresentBuilder::deser_default(),
103            }))
104        }
105    }
106
107    impl MapBuilder for PaymentMethodInteracPresentBuilder {
108        type Out = PaymentMethodInteracPresent;
109        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
110            Ok(match k {
111                "brand" => Deserialize::begin(&mut self.brand),
112                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
113                "country" => Deserialize::begin(&mut self.country),
114                "description" => Deserialize::begin(&mut self.description),
115                "exp_month" => Deserialize::begin(&mut self.exp_month),
116                "exp_year" => Deserialize::begin(&mut self.exp_year),
117                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
118                "funding" => Deserialize::begin(&mut self.funding),
119                "iin" => Deserialize::begin(&mut self.iin),
120                "issuer" => Deserialize::begin(&mut self.issuer),
121                "last4" => Deserialize::begin(&mut self.last4),
122                "networks" => Deserialize::begin(&mut self.networks),
123                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
124                "read_method" => Deserialize::begin(&mut self.read_method),
125                _ => <dyn Visitor>::ignore(),
126            })
127        }
128
129        fn deser_default() -> Self {
130            Self {
131                brand: Some(None),
132                cardholder_name: Some(None),
133                country: Some(None),
134                description: Some(None),
135                exp_month: None,
136                exp_year: None,
137                fingerprint: Some(None),
138                funding: Some(None),
139                iin: Some(None),
140                issuer: Some(None),
141                last4: Some(None),
142                networks: Some(None),
143                preferred_locales: Some(None),
144                read_method: Some(None),
145            }
146        }
147
148        fn take_out(&mut self) -> Option<Self::Out> {
149            let (
150                Some(brand),
151                Some(cardholder_name),
152                Some(country),
153                Some(description),
154                Some(exp_month),
155                Some(exp_year),
156                Some(fingerprint),
157                Some(funding),
158                Some(iin),
159                Some(issuer),
160                Some(last4),
161                Some(networks),
162                Some(preferred_locales),
163                Some(read_method),
164            ) = (
165                self.brand.take(),
166                self.cardholder_name.take(),
167                self.country.take(),
168                self.description.take(),
169                self.exp_month,
170                self.exp_year,
171                self.fingerprint.take(),
172                self.funding.take(),
173                self.iin.take(),
174                self.issuer.take(),
175                self.last4.take(),
176                self.networks.take(),
177                self.preferred_locales.take(),
178                self.read_method.take(),
179            )
180            else {
181                return None;
182            };
183            Some(Self::Out {
184                brand,
185                cardholder_name,
186                country,
187                description,
188                exp_month,
189                exp_year,
190                fingerprint,
191                funding,
192                iin,
193                issuer,
194                last4,
195                networks,
196                preferred_locales,
197                read_method,
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 PaymentMethodInteracPresent {
214        type Builder = PaymentMethodInteracPresentBuilder;
215    }
216
217    impl FromValueOpt for PaymentMethodInteracPresent {
218        fn from_value(v: Value) -> Option<Self> {
219            let Value::Object(obj) = v else {
220                return None;
221            };
222            let mut b = PaymentMethodInteracPresentBuilder::deser_default();
223            for (k, v) in obj {
224                match k.as_str() {
225                    "brand" => b.brand = FromValueOpt::from_value(v),
226                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
227                    "country" => b.country = FromValueOpt::from_value(v),
228                    "description" => b.description = FromValueOpt::from_value(v),
229                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
230                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
231                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
232                    "funding" => b.funding = FromValueOpt::from_value(v),
233                    "iin" => b.iin = FromValueOpt::from_value(v),
234                    "issuer" => b.issuer = FromValueOpt::from_value(v),
235                    "last4" => b.last4 = FromValueOpt::from_value(v),
236                    "networks" => b.networks = FromValueOpt::from_value(v),
237                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
238                    "read_method" => b.read_method = FromValueOpt::from_value(v),
239                    _ => {}
240                }
241            }
242            b.take_out()
243        }
244    }
245};
246/// How card details were read in this transaction.
247#[derive(Clone, Eq, PartialEq)]
248#[non_exhaustive]
249pub enum PaymentMethodInteracPresentReadMethod {
250    ContactEmv,
251    ContactlessEmv,
252    ContactlessMagstripeMode,
253    MagneticStripeFallback,
254    MagneticStripeTrack2,
255    /// An unrecognized value from Stripe. Should not be used as a request parameter.
256    Unknown(String),
257}
258impl PaymentMethodInteracPresentReadMethod {
259    pub fn as_str(&self) -> &str {
260        use PaymentMethodInteracPresentReadMethod::*;
261        match self {
262            ContactEmv => "contact_emv",
263            ContactlessEmv => "contactless_emv",
264            ContactlessMagstripeMode => "contactless_magstripe_mode",
265            MagneticStripeFallback => "magnetic_stripe_fallback",
266            MagneticStripeTrack2 => "magnetic_stripe_track2",
267            Unknown(v) => v,
268        }
269    }
270}
271
272impl std::str::FromStr for PaymentMethodInteracPresentReadMethod {
273    type Err = std::convert::Infallible;
274    fn from_str(s: &str) -> Result<Self, Self::Err> {
275        use PaymentMethodInteracPresentReadMethod::*;
276        match s {
277            "contact_emv" => Ok(ContactEmv),
278            "contactless_emv" => Ok(ContactlessEmv),
279            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
280            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
281            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
282            v => {
283                tracing::warn!(
284                    "Unknown value '{}' for enum '{}'",
285                    v,
286                    "PaymentMethodInteracPresentReadMethod"
287                );
288                Ok(Unknown(v.to_owned()))
289            }
290        }
291    }
292}
293impl std::fmt::Display for PaymentMethodInteracPresentReadMethod {
294    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
295        f.write_str(self.as_str())
296    }
297}
298
299#[cfg(not(feature = "redact-generated-debug"))]
300impl std::fmt::Debug for PaymentMethodInteracPresentReadMethod {
301    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
302        f.write_str(self.as_str())
303    }
304}
305#[cfg(feature = "redact-generated-debug")]
306impl std::fmt::Debug for PaymentMethodInteracPresentReadMethod {
307    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308        f.debug_struct(stringify!(PaymentMethodInteracPresentReadMethod)).finish_non_exhaustive()
309    }
310}
311#[cfg(feature = "serialize")]
312impl serde::Serialize for PaymentMethodInteracPresentReadMethod {
313    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
314    where
315        S: serde::Serializer,
316    {
317        serializer.serialize_str(self.as_str())
318    }
319}
320impl miniserde::Deserialize for PaymentMethodInteracPresentReadMethod {
321    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
322        crate::Place::new(out)
323    }
324}
325
326impl miniserde::de::Visitor for crate::Place<PaymentMethodInteracPresentReadMethod> {
327    fn string(&mut self, s: &str) -> miniserde::Result<()> {
328        use std::str::FromStr;
329        self.out = Some(PaymentMethodInteracPresentReadMethod::from_str(s).expect("infallible"));
330        Ok(())
331    }
332}
333
334stripe_types::impl_from_val_with_from_str!(PaymentMethodInteracPresentReadMethod);
335#[cfg(feature = "deserialize")]
336impl<'de> serde::Deserialize<'de> for PaymentMethodInteracPresentReadMethod {
337    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
338        use std::str::FromStr;
339        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
340        Ok(Self::from_str(&s).expect("infallible"))
341    }
342}