stripe_shared/
payment_method_details_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 PaymentMethodDetailsInteracPresent {
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    /// Authorization response cryptogram.
19    pub emv_auth_data: 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: Option<String>,
32    /// ID of a card PaymentMethod generated from the card_present PaymentMethod that may be attached to a Customer for future transactions.
33    /// Only present if it was possible to generate a card PaymentMethod.
34    pub generated_card: Option<String>,
35    /// Issuer identification number of the card.
36    /// (For internal use only and not typically available in standard API requests.).
37    pub iin: Option<String>,
38    /// The name of the card's issuing bank.
39    /// (For internal use only and not typically available in standard API requests.).
40    pub issuer: Option<String>,
41    /// The last four digits of the card.
42    pub last4: Option<String>,
43    /// Identifies which network this charge was processed on.
44    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `interac`, `jcb`, `link`, `mastercard`, `unionpay`, `visa`, or `unknown`.
45    pub network: Option<String>,
46    /// This is used by the financial networks to identify a transaction.
47    /// Visa calls this the Transaction ID, Mastercard calls this the Trace ID, and American Express calls this the Acquirer Reference Data.
48    /// This value will be present if it is returned by the financial network in the authorization response, and null otherwise.
49    pub network_transaction_id: Option<String>,
50    /// The languages that the issuing bank recommends using for localizing any customer-facing text, as read from the card.
51    /// Referenced from EMV tag 5F2D, data encoded on the card's chip.
52    pub preferred_locales: Option<Vec<String>>,
53    /// How card details were read in this transaction.
54    pub read_method: Option<PaymentMethodDetailsInteracPresentReadMethod>,
55    /// A collection of fields required to be displayed on receipts. Only required for EMV transactions.
56    pub receipt: Option<stripe_shared::PaymentMethodDetailsInteracPresentReceipt>,
57}
58#[doc(hidden)]
59pub struct PaymentMethodDetailsInteracPresentBuilder {
60    brand: Option<Option<String>>,
61    cardholder_name: Option<Option<String>>,
62    country: Option<Option<String>>,
63    description: Option<Option<String>>,
64    emv_auth_data: Option<Option<String>>,
65    exp_month: Option<i64>,
66    exp_year: Option<i64>,
67    fingerprint: Option<Option<String>>,
68    funding: Option<Option<String>>,
69    generated_card: Option<Option<String>>,
70    iin: Option<Option<String>>,
71    issuer: Option<Option<String>>,
72    last4: Option<Option<String>>,
73    network: Option<Option<String>>,
74    network_transaction_id: Option<Option<String>>,
75    preferred_locales: Option<Option<Vec<String>>>,
76    read_method: Option<Option<PaymentMethodDetailsInteracPresentReadMethod>>,
77    receipt: Option<Option<stripe_shared::PaymentMethodDetailsInteracPresentReceipt>>,
78}
79
80#[allow(
81    unused_variables,
82    irrefutable_let_patterns,
83    clippy::let_unit_value,
84    clippy::match_single_binding,
85    clippy::single_match
86)]
87const _: () = {
88    use miniserde::de::{Map, Visitor};
89    use miniserde::json::Value;
90    use miniserde::{make_place, Deserialize, Result};
91    use stripe_types::miniserde_helpers::FromValueOpt;
92    use stripe_types::{MapBuilder, ObjectDeser};
93
94    make_place!(Place);
95
96    impl Deserialize for PaymentMethodDetailsInteracPresent {
97        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
98            Place::new(out)
99        }
100    }
101
102    struct Builder<'a> {
103        out: &'a mut Option<PaymentMethodDetailsInteracPresent>,
104        builder: PaymentMethodDetailsInteracPresentBuilder,
105    }
106
107    impl Visitor for Place<PaymentMethodDetailsInteracPresent> {
108        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
109            Ok(Box::new(Builder {
110                out: &mut self.out,
111                builder: PaymentMethodDetailsInteracPresentBuilder::deser_default(),
112            }))
113        }
114    }
115
116    impl MapBuilder for PaymentMethodDetailsInteracPresentBuilder {
117        type Out = PaymentMethodDetailsInteracPresent;
118        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
119            Ok(match k {
120                "brand" => Deserialize::begin(&mut self.brand),
121                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
122                "country" => Deserialize::begin(&mut self.country),
123                "description" => Deserialize::begin(&mut self.description),
124                "emv_auth_data" => Deserialize::begin(&mut self.emv_auth_data),
125                "exp_month" => Deserialize::begin(&mut self.exp_month),
126                "exp_year" => Deserialize::begin(&mut self.exp_year),
127                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
128                "funding" => Deserialize::begin(&mut self.funding),
129                "generated_card" => Deserialize::begin(&mut self.generated_card),
130                "iin" => Deserialize::begin(&mut self.iin),
131                "issuer" => Deserialize::begin(&mut self.issuer),
132                "last4" => Deserialize::begin(&mut self.last4),
133                "network" => Deserialize::begin(&mut self.network),
134                "network_transaction_id" => Deserialize::begin(&mut self.network_transaction_id),
135                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
136                "read_method" => Deserialize::begin(&mut self.read_method),
137                "receipt" => Deserialize::begin(&mut self.receipt),
138
139                _ => <dyn Visitor>::ignore(),
140            })
141        }
142
143        fn deser_default() -> Self {
144            Self {
145                brand: Deserialize::default(),
146                cardholder_name: Deserialize::default(),
147                country: Deserialize::default(),
148                description: Deserialize::default(),
149                emv_auth_data: Deserialize::default(),
150                exp_month: Deserialize::default(),
151                exp_year: Deserialize::default(),
152                fingerprint: Deserialize::default(),
153                funding: Deserialize::default(),
154                generated_card: Deserialize::default(),
155                iin: Deserialize::default(),
156                issuer: Deserialize::default(),
157                last4: Deserialize::default(),
158                network: Deserialize::default(),
159                network_transaction_id: Deserialize::default(),
160                preferred_locales: Deserialize::default(),
161                read_method: Deserialize::default(),
162                receipt: Deserialize::default(),
163            }
164        }
165
166        fn take_out(&mut self) -> Option<Self::Out> {
167            let (
168                Some(brand),
169                Some(cardholder_name),
170                Some(country),
171                Some(description),
172                Some(emv_auth_data),
173                Some(exp_month),
174                Some(exp_year),
175                Some(fingerprint),
176                Some(funding),
177                Some(generated_card),
178                Some(iin),
179                Some(issuer),
180                Some(last4),
181                Some(network),
182                Some(network_transaction_id),
183                Some(preferred_locales),
184                Some(read_method),
185                Some(receipt),
186            ) = (
187                self.brand.take(),
188                self.cardholder_name.take(),
189                self.country.take(),
190                self.description.take(),
191                self.emv_auth_data.take(),
192                self.exp_month,
193                self.exp_year,
194                self.fingerprint.take(),
195                self.funding.take(),
196                self.generated_card.take(),
197                self.iin.take(),
198                self.issuer.take(),
199                self.last4.take(),
200                self.network.take(),
201                self.network_transaction_id.take(),
202                self.preferred_locales.take(),
203                self.read_method,
204                self.receipt.take(),
205            )
206            else {
207                return None;
208            };
209            Some(Self::Out {
210                brand,
211                cardholder_name,
212                country,
213                description,
214                emv_auth_data,
215                exp_month,
216                exp_year,
217                fingerprint,
218                funding,
219                generated_card,
220                iin,
221                issuer,
222                last4,
223                network,
224                network_transaction_id,
225                preferred_locales,
226                read_method,
227                receipt,
228            })
229        }
230    }
231
232    impl Map for Builder<'_> {
233        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
234            self.builder.key(k)
235        }
236
237        fn finish(&mut self) -> Result<()> {
238            *self.out = self.builder.take_out();
239            Ok(())
240        }
241    }
242
243    impl ObjectDeser for PaymentMethodDetailsInteracPresent {
244        type Builder = PaymentMethodDetailsInteracPresentBuilder;
245    }
246
247    impl FromValueOpt for PaymentMethodDetailsInteracPresent {
248        fn from_value(v: Value) -> Option<Self> {
249            let Value::Object(obj) = v else {
250                return None;
251            };
252            let mut b = PaymentMethodDetailsInteracPresentBuilder::deser_default();
253            for (k, v) in obj {
254                match k.as_str() {
255                    "brand" => b.brand = FromValueOpt::from_value(v),
256                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
257                    "country" => b.country = FromValueOpt::from_value(v),
258                    "description" => b.description = FromValueOpt::from_value(v),
259                    "emv_auth_data" => b.emv_auth_data = FromValueOpt::from_value(v),
260                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
261                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
262                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
263                    "funding" => b.funding = FromValueOpt::from_value(v),
264                    "generated_card" => b.generated_card = FromValueOpt::from_value(v),
265                    "iin" => b.iin = FromValueOpt::from_value(v),
266                    "issuer" => b.issuer = FromValueOpt::from_value(v),
267                    "last4" => b.last4 = FromValueOpt::from_value(v),
268                    "network" => b.network = FromValueOpt::from_value(v),
269                    "network_transaction_id" => {
270                        b.network_transaction_id = FromValueOpt::from_value(v)
271                    }
272                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
273                    "read_method" => b.read_method = FromValueOpt::from_value(v),
274                    "receipt" => b.receipt = FromValueOpt::from_value(v),
275
276                    _ => {}
277                }
278            }
279            b.take_out()
280        }
281    }
282};
283/// How card details were read in this transaction.
284#[derive(Copy, Clone, Eq, PartialEq)]
285pub enum PaymentMethodDetailsInteracPresentReadMethod {
286    ContactEmv,
287    ContactlessEmv,
288    ContactlessMagstripeMode,
289    MagneticStripeFallback,
290    MagneticStripeTrack2,
291}
292impl PaymentMethodDetailsInteracPresentReadMethod {
293    pub fn as_str(self) -> &'static str {
294        use PaymentMethodDetailsInteracPresentReadMethod::*;
295        match self {
296            ContactEmv => "contact_emv",
297            ContactlessEmv => "contactless_emv",
298            ContactlessMagstripeMode => "contactless_magstripe_mode",
299            MagneticStripeFallback => "magnetic_stripe_fallback",
300            MagneticStripeTrack2 => "magnetic_stripe_track2",
301        }
302    }
303}
304
305impl std::str::FromStr for PaymentMethodDetailsInteracPresentReadMethod {
306    type Err = stripe_types::StripeParseError;
307    fn from_str(s: &str) -> Result<Self, Self::Err> {
308        use PaymentMethodDetailsInteracPresentReadMethod::*;
309        match s {
310            "contact_emv" => Ok(ContactEmv),
311            "contactless_emv" => Ok(ContactlessEmv),
312            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
313            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
314            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
315            _ => Err(stripe_types::StripeParseError),
316        }
317    }
318}
319impl std::fmt::Display for PaymentMethodDetailsInteracPresentReadMethod {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324
325impl std::fmt::Debug for PaymentMethodDetailsInteracPresentReadMethod {
326    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327        f.write_str(self.as_str())
328    }
329}
330#[cfg(feature = "serialize")]
331impl serde::Serialize for PaymentMethodDetailsInteracPresentReadMethod {
332    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
333    where
334        S: serde::Serializer,
335    {
336        serializer.serialize_str(self.as_str())
337    }
338}
339impl miniserde::Deserialize for PaymentMethodDetailsInteracPresentReadMethod {
340    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
341        crate::Place::new(out)
342    }
343}
344
345impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsInteracPresentReadMethod> {
346    fn string(&mut self, s: &str) -> miniserde::Result<()> {
347        use std::str::FromStr;
348        self.out = Some(
349            PaymentMethodDetailsInteracPresentReadMethod::from_str(s)
350                .map_err(|_| miniserde::Error)?,
351        );
352        Ok(())
353    }
354}
355
356stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsInteracPresentReadMethod);
357#[cfg(feature = "deserialize")]
358impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsInteracPresentReadMethod {
359    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
360        use std::str::FromStr;
361        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
362        Self::from_str(&s).map_err(|_| {
363            serde::de::Error::custom(
364                "Unknown value for PaymentMethodDetailsInteracPresentReadMethod",
365            )
366        })
367    }
368}