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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
139            })
140        }
141
142        fn deser_default() -> Self {
143            Self {
144                brand: Deserialize::default(),
145                cardholder_name: Deserialize::default(),
146                country: Deserialize::default(),
147                description: Deserialize::default(),
148                emv_auth_data: Deserialize::default(),
149                exp_month: Deserialize::default(),
150                exp_year: Deserialize::default(),
151                fingerprint: Deserialize::default(),
152                funding: Deserialize::default(),
153                generated_card: Deserialize::default(),
154                iin: Deserialize::default(),
155                issuer: Deserialize::default(),
156                last4: Deserialize::default(),
157                network: Deserialize::default(),
158                network_transaction_id: Deserialize::default(),
159                preferred_locales: Deserialize::default(),
160                read_method: Deserialize::default(),
161                receipt: Deserialize::default(),
162            }
163        }
164
165        fn take_out(&mut self) -> Option<Self::Out> {
166            let (
167                Some(brand),
168                Some(cardholder_name),
169                Some(country),
170                Some(description),
171                Some(emv_auth_data),
172                Some(exp_month),
173                Some(exp_year),
174                Some(fingerprint),
175                Some(funding),
176                Some(generated_card),
177                Some(iin),
178                Some(issuer),
179                Some(last4),
180                Some(network),
181                Some(network_transaction_id),
182                Some(preferred_locales),
183                Some(read_method),
184                Some(receipt),
185            ) = (
186                self.brand.take(),
187                self.cardholder_name.take(),
188                self.country.take(),
189                self.description.take(),
190                self.emv_auth_data.take(),
191                self.exp_month,
192                self.exp_year,
193                self.fingerprint.take(),
194                self.funding.take(),
195                self.generated_card.take(),
196                self.iin.take(),
197                self.issuer.take(),
198                self.last4.take(),
199                self.network.take(),
200                self.network_transaction_id.take(),
201                self.preferred_locales.take(),
202                self.read_method,
203                self.receipt.take(),
204            )
205            else {
206                return None;
207            };
208            Some(Self::Out {
209                brand,
210                cardholder_name,
211                country,
212                description,
213                emv_auth_data,
214                exp_month,
215                exp_year,
216                fingerprint,
217                funding,
218                generated_card,
219                iin,
220                issuer,
221                last4,
222                network,
223                network_transaction_id,
224                preferred_locales,
225                read_method,
226                receipt,
227            })
228        }
229    }
230
231    impl Map for Builder<'_> {
232        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
233            self.builder.key(k)
234        }
235
236        fn finish(&mut self) -> Result<()> {
237            *self.out = self.builder.take_out();
238            Ok(())
239        }
240    }
241
242    impl ObjectDeser for PaymentMethodDetailsInteracPresent {
243        type Builder = PaymentMethodDetailsInteracPresentBuilder;
244    }
245
246    impl FromValueOpt for PaymentMethodDetailsInteracPresent {
247        fn from_value(v: Value) -> Option<Self> {
248            let Value::Object(obj) = v else {
249                return None;
250            };
251            let mut b = PaymentMethodDetailsInteracPresentBuilder::deser_default();
252            for (k, v) in obj {
253                match k.as_str() {
254                    "brand" => b.brand = FromValueOpt::from_value(v),
255                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
256                    "country" => b.country = FromValueOpt::from_value(v),
257                    "description" => b.description = FromValueOpt::from_value(v),
258                    "emv_auth_data" => b.emv_auth_data = FromValueOpt::from_value(v),
259                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
260                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
261                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
262                    "funding" => b.funding = FromValueOpt::from_value(v),
263                    "generated_card" => b.generated_card = FromValueOpt::from_value(v),
264                    "iin" => b.iin = FromValueOpt::from_value(v),
265                    "issuer" => b.issuer = FromValueOpt::from_value(v),
266                    "last4" => b.last4 = FromValueOpt::from_value(v),
267                    "network" => b.network = FromValueOpt::from_value(v),
268                    "network_transaction_id" => {
269                        b.network_transaction_id = FromValueOpt::from_value(v)
270                    }
271                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
272                    "read_method" => b.read_method = FromValueOpt::from_value(v),
273                    "receipt" => b.receipt = FromValueOpt::from_value(v),
274                    _ => {}
275                }
276            }
277            b.take_out()
278        }
279    }
280};
281/// How card details were read in this transaction.
282#[derive(Copy, Clone, Eq, PartialEq)]
283pub enum PaymentMethodDetailsInteracPresentReadMethod {
284    ContactEmv,
285    ContactlessEmv,
286    ContactlessMagstripeMode,
287    MagneticStripeFallback,
288    MagneticStripeTrack2,
289}
290impl PaymentMethodDetailsInteracPresentReadMethod {
291    pub fn as_str(self) -> &'static str {
292        use PaymentMethodDetailsInteracPresentReadMethod::*;
293        match self {
294            ContactEmv => "contact_emv",
295            ContactlessEmv => "contactless_emv",
296            ContactlessMagstripeMode => "contactless_magstripe_mode",
297            MagneticStripeFallback => "magnetic_stripe_fallback",
298            MagneticStripeTrack2 => "magnetic_stripe_track2",
299        }
300    }
301}
302
303impl std::str::FromStr for PaymentMethodDetailsInteracPresentReadMethod {
304    type Err = stripe_types::StripeParseError;
305    fn from_str(s: &str) -> Result<Self, Self::Err> {
306        use PaymentMethodDetailsInteracPresentReadMethod::*;
307        match s {
308            "contact_emv" => Ok(ContactEmv),
309            "contactless_emv" => Ok(ContactlessEmv),
310            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
311            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
312            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
313            _ => Err(stripe_types::StripeParseError),
314        }
315    }
316}
317impl std::fmt::Display for PaymentMethodDetailsInteracPresentReadMethod {
318    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
319        f.write_str(self.as_str())
320    }
321}
322
323impl std::fmt::Debug for PaymentMethodDetailsInteracPresentReadMethod {
324    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
325        f.write_str(self.as_str())
326    }
327}
328#[cfg(feature = "serialize")]
329impl serde::Serialize for PaymentMethodDetailsInteracPresentReadMethod {
330    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
331    where
332        S: serde::Serializer,
333    {
334        serializer.serialize_str(self.as_str())
335    }
336}
337impl miniserde::Deserialize for PaymentMethodDetailsInteracPresentReadMethod {
338    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
339        crate::Place::new(out)
340    }
341}
342
343impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsInteracPresentReadMethod> {
344    fn string(&mut self, s: &str) -> miniserde::Result<()> {
345        use std::str::FromStr;
346        self.out = Some(
347            PaymentMethodDetailsInteracPresentReadMethod::from_str(s)
348                .map_err(|_| miniserde::Error)?,
349        );
350        Ok(())
351    }
352}
353
354stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsInteracPresentReadMethod);
355#[cfg(feature = "deserialize")]
356impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsInteracPresentReadMethod {
357    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
358        use std::str::FromStr;
359        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
360        Self::from_str(&s).map_err(|_| {
361            serde::de::Error::custom(
362                "Unknown value for PaymentMethodDetailsInteracPresentReadMethod",
363            )
364        })
365    }
366}