stripe_shared/
setup_attempt_payment_method_details_card_wallet.rs

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