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    /// The languages that the issuing bank recommends using for localizing any customer-facing text, as read from the card.
41    /// Referenced from EMV tag 5F2D, data encoded on the card's chip.
42    pub preferred_locales: Option<Vec<String>>,
43    /// How card details were read in this transaction.
44    pub read_method: Option<PaymentMethodInteracPresentReadMethod>,
45}
46#[doc(hidden)]
47pub struct PaymentMethodInteracPresentBuilder {
48    brand: Option<Option<String>>,
49    cardholder_name: Option<Option<String>>,
50    country: Option<Option<String>>,
51    description: Option<Option<String>>,
52    exp_month: Option<i64>,
53    exp_year: Option<i64>,
54    fingerprint: Option<Option<String>>,
55    funding: Option<Option<String>>,
56    iin: Option<Option<String>>,
57    issuer: Option<Option<String>>,
58    last4: Option<Option<String>>,
59    networks: Option<Option<stripe_shared::PaymentMethodCardPresentNetworks>>,
60    preferred_locales: Option<Option<Vec<String>>>,
61    read_method: Option<Option<PaymentMethodInteracPresentReadMethod>>,
62}
63
64#[allow(
65    unused_variables,
66    irrefutable_let_patterns,
67    clippy::let_unit_value,
68    clippy::match_single_binding,
69    clippy::single_match
70)]
71const _: () = {
72    use miniserde::de::{Map, Visitor};
73    use miniserde::json::Value;
74    use miniserde::{make_place, Deserialize, Result};
75    use stripe_types::miniserde_helpers::FromValueOpt;
76    use stripe_types::{MapBuilder, ObjectDeser};
77
78    make_place!(Place);
79
80    impl Deserialize for PaymentMethodInteracPresent {
81        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
82            Place::new(out)
83        }
84    }
85
86    struct Builder<'a> {
87        out: &'a mut Option<PaymentMethodInteracPresent>,
88        builder: PaymentMethodInteracPresentBuilder,
89    }
90
91    impl Visitor for Place<PaymentMethodInteracPresent> {
92        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
93            Ok(Box::new(Builder {
94                out: &mut self.out,
95                builder: PaymentMethodInteracPresentBuilder::deser_default(),
96            }))
97        }
98    }
99
100    impl MapBuilder for PaymentMethodInteracPresentBuilder {
101        type Out = PaymentMethodInteracPresent;
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            Ok(match k {
104                "brand" => Deserialize::begin(&mut self.brand),
105                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
106                "country" => Deserialize::begin(&mut self.country),
107                "description" => Deserialize::begin(&mut self.description),
108                "exp_month" => Deserialize::begin(&mut self.exp_month),
109                "exp_year" => Deserialize::begin(&mut self.exp_year),
110                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
111                "funding" => Deserialize::begin(&mut self.funding),
112                "iin" => Deserialize::begin(&mut self.iin),
113                "issuer" => Deserialize::begin(&mut self.issuer),
114                "last4" => Deserialize::begin(&mut self.last4),
115                "networks" => Deserialize::begin(&mut self.networks),
116                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
117                "read_method" => Deserialize::begin(&mut self.read_method),
118
119                _ => <dyn Visitor>::ignore(),
120            })
121        }
122
123        fn deser_default() -> Self {
124            Self {
125                brand: Deserialize::default(),
126                cardholder_name: Deserialize::default(),
127                country: Deserialize::default(),
128                description: Deserialize::default(),
129                exp_month: Deserialize::default(),
130                exp_year: Deserialize::default(),
131                fingerprint: Deserialize::default(),
132                funding: Deserialize::default(),
133                iin: Deserialize::default(),
134                issuer: Deserialize::default(),
135                last4: Deserialize::default(),
136                networks: Deserialize::default(),
137                preferred_locales: Deserialize::default(),
138                read_method: Deserialize::default(),
139            }
140        }
141
142        fn take_out(&mut self) -> Option<Self::Out> {
143            let (
144                Some(brand),
145                Some(cardholder_name),
146                Some(country),
147                Some(description),
148                Some(exp_month),
149                Some(exp_year),
150                Some(fingerprint),
151                Some(funding),
152                Some(iin),
153                Some(issuer),
154                Some(last4),
155                Some(networks),
156                Some(preferred_locales),
157                Some(read_method),
158            ) = (
159                self.brand.take(),
160                self.cardholder_name.take(),
161                self.country.take(),
162                self.description.take(),
163                self.exp_month,
164                self.exp_year,
165                self.fingerprint.take(),
166                self.funding.take(),
167                self.iin.take(),
168                self.issuer.take(),
169                self.last4.take(),
170                self.networks.take(),
171                self.preferred_locales.take(),
172                self.read_method,
173            )
174            else {
175                return None;
176            };
177            Some(Self::Out {
178                brand,
179                cardholder_name,
180                country,
181                description,
182                exp_month,
183                exp_year,
184                fingerprint,
185                funding,
186                iin,
187                issuer,
188                last4,
189                networks,
190                preferred_locales,
191                read_method,
192            })
193        }
194    }
195
196    impl Map for Builder<'_> {
197        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
198            self.builder.key(k)
199        }
200
201        fn finish(&mut self) -> Result<()> {
202            *self.out = self.builder.take_out();
203            Ok(())
204        }
205    }
206
207    impl ObjectDeser for PaymentMethodInteracPresent {
208        type Builder = PaymentMethodInteracPresentBuilder;
209    }
210
211    impl FromValueOpt for PaymentMethodInteracPresent {
212        fn from_value(v: Value) -> Option<Self> {
213            let Value::Object(obj) = v else {
214                return None;
215            };
216            let mut b = PaymentMethodInteracPresentBuilder::deser_default();
217            for (k, v) in obj {
218                match k.as_str() {
219                    "brand" => b.brand = FromValueOpt::from_value(v),
220                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
221                    "country" => b.country = FromValueOpt::from_value(v),
222                    "description" => b.description = FromValueOpt::from_value(v),
223                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
224                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
225                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
226                    "funding" => b.funding = FromValueOpt::from_value(v),
227                    "iin" => b.iin = FromValueOpt::from_value(v),
228                    "issuer" => b.issuer = FromValueOpt::from_value(v),
229                    "last4" => b.last4 = FromValueOpt::from_value(v),
230                    "networks" => b.networks = FromValueOpt::from_value(v),
231                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
232                    "read_method" => b.read_method = FromValueOpt::from_value(v),
233
234                    _ => {}
235                }
236            }
237            b.take_out()
238        }
239    }
240};
241/// How card details were read in this transaction.
242#[derive(Copy, Clone, Eq, PartialEq)]
243pub enum PaymentMethodInteracPresentReadMethod {
244    ContactEmv,
245    ContactlessEmv,
246    ContactlessMagstripeMode,
247    MagneticStripeFallback,
248    MagneticStripeTrack2,
249}
250impl PaymentMethodInteracPresentReadMethod {
251    pub fn as_str(self) -> &'static str {
252        use PaymentMethodInteracPresentReadMethod::*;
253        match self {
254            ContactEmv => "contact_emv",
255            ContactlessEmv => "contactless_emv",
256            ContactlessMagstripeMode => "contactless_magstripe_mode",
257            MagneticStripeFallback => "magnetic_stripe_fallback",
258            MagneticStripeTrack2 => "magnetic_stripe_track2",
259        }
260    }
261}
262
263impl std::str::FromStr for PaymentMethodInteracPresentReadMethod {
264    type Err = stripe_types::StripeParseError;
265    fn from_str(s: &str) -> Result<Self, Self::Err> {
266        use PaymentMethodInteracPresentReadMethod::*;
267        match s {
268            "contact_emv" => Ok(ContactEmv),
269            "contactless_emv" => Ok(ContactlessEmv),
270            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
271            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
272            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
273            _ => Err(stripe_types::StripeParseError),
274        }
275    }
276}
277impl std::fmt::Display for PaymentMethodInteracPresentReadMethod {
278    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
279        f.write_str(self.as_str())
280    }
281}
282
283impl std::fmt::Debug for PaymentMethodInteracPresentReadMethod {
284    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
285        f.write_str(self.as_str())
286    }
287}
288#[cfg(feature = "serialize")]
289impl serde::Serialize for PaymentMethodInteracPresentReadMethod {
290    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
291    where
292        S: serde::Serializer,
293    {
294        serializer.serialize_str(self.as_str())
295    }
296}
297impl miniserde::Deserialize for PaymentMethodInteracPresentReadMethod {
298    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
299        crate::Place::new(out)
300    }
301}
302
303impl miniserde::de::Visitor for crate::Place<PaymentMethodInteracPresentReadMethod> {
304    fn string(&mut self, s: &str) -> miniserde::Result<()> {
305        use std::str::FromStr;
306        self.out =
307            Some(PaymentMethodInteracPresentReadMethod::from_str(s).map_err(|_| miniserde::Error)?);
308        Ok(())
309    }
310}
311
312stripe_types::impl_from_val_with_from_str!(PaymentMethodInteracPresentReadMethod);
313#[cfg(feature = "deserialize")]
314impl<'de> serde::Deserialize<'de> for PaymentMethodInteracPresentReadMethod {
315    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
316        use std::str::FromStr;
317        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
318        Self::from_str(&s).map_err(|_| {
319            serde::de::Error::custom("Unknown value for PaymentMethodInteracPresentReadMethod")
320        })
321    }
322}