stripe_shared/
payment_method_interac_present.rs

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