stripe_shared/
issuing_card_apple_pay.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardApplePay {
5    /// Apple Pay Eligibility
6    pub eligible: bool,
7    /// Reason the card is ineligible for Apple Pay
8    pub ineligible_reason: Option<IssuingCardApplePayIneligibleReason>,
9}
10#[doc(hidden)]
11pub struct IssuingCardApplePayBuilder {
12    eligible: Option<bool>,
13    ineligible_reason: Option<Option<IssuingCardApplePayIneligibleReason>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for IssuingCardApplePay {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<IssuingCardApplePay>,
40        builder: IssuingCardApplePayBuilder,
41    }
42
43    impl Visitor for Place<IssuingCardApplePay> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: IssuingCardApplePayBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for IssuingCardApplePayBuilder {
53        type Out = IssuingCardApplePay;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "eligible" => Deserialize::begin(&mut self.eligible),
57                "ineligible_reason" => Deserialize::begin(&mut self.ineligible_reason),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { eligible: Deserialize::default(), ineligible_reason: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(eligible), Some(ineligible_reason)) =
68                (self.eligible, self.ineligible_reason.take())
69            else {
70                return None;
71            };
72            Some(Self::Out { eligible, ineligible_reason })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for IssuingCardApplePay {
88        type Builder = IssuingCardApplePayBuilder;
89    }
90
91    impl FromValueOpt for IssuingCardApplePay {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = IssuingCardApplePayBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "eligible" => b.eligible = FromValueOpt::from_value(v),
100                    "ineligible_reason" => b.ineligible_reason = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Reason the card is ineligible for Apple Pay
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum IssuingCardApplePayIneligibleReason {
112    MissingAgreement,
113    MissingCardholderContact,
114    UnsupportedRegion,
115    /// An unrecognized value from Stripe. Should not be used as a request parameter.
116    Unknown(String),
117}
118impl IssuingCardApplePayIneligibleReason {
119    pub fn as_str(&self) -> &str {
120        use IssuingCardApplePayIneligibleReason::*;
121        match self {
122            MissingAgreement => "missing_agreement",
123            MissingCardholderContact => "missing_cardholder_contact",
124            UnsupportedRegion => "unsupported_region",
125            Unknown(v) => v,
126        }
127    }
128}
129
130impl std::str::FromStr for IssuingCardApplePayIneligibleReason {
131    type Err = std::convert::Infallible;
132    fn from_str(s: &str) -> Result<Self, Self::Err> {
133        use IssuingCardApplePayIneligibleReason::*;
134        match s {
135            "missing_agreement" => Ok(MissingAgreement),
136            "missing_cardholder_contact" => Ok(MissingCardholderContact),
137            "unsupported_region" => Ok(UnsupportedRegion),
138            v => {
139                tracing::warn!(
140                    "Unknown value '{}' for enum '{}'",
141                    v,
142                    "IssuingCardApplePayIneligibleReason"
143                );
144                Ok(Unknown(v.to_owned()))
145            }
146        }
147    }
148}
149impl std::fmt::Display for IssuingCardApplePayIneligibleReason {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154
155impl std::fmt::Debug for IssuingCardApplePayIneligibleReason {
156    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157        f.write_str(self.as_str())
158    }
159}
160#[cfg(feature = "serialize")]
161impl serde::Serialize for IssuingCardApplePayIneligibleReason {
162    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163    where
164        S: serde::Serializer,
165    {
166        serializer.serialize_str(self.as_str())
167    }
168}
169impl miniserde::Deserialize for IssuingCardApplePayIneligibleReason {
170    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
171        crate::Place::new(out)
172    }
173}
174
175impl miniserde::de::Visitor for crate::Place<IssuingCardApplePayIneligibleReason> {
176    fn string(&mut self, s: &str) -> miniserde::Result<()> {
177        use std::str::FromStr;
178        self.out = Some(IssuingCardApplePayIneligibleReason::from_str(s).expect("infallible"));
179        Ok(())
180    }
181}
182
183stripe_types::impl_from_val_with_from_str!(IssuingCardApplePayIneligibleReason);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for IssuingCardApplePayIneligibleReason {
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Ok(Self::from_str(&s).expect("infallible"))
190    }
191}