stripe_shared/
setup_attempt_payment_method_details_card_wallet.rs1#[derive(Copy, 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 #[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
64 _ => <dyn Visitor>::ignore(),
65 })
66 }
67
68 fn deser_default() -> Self {
69 Self {
70 apple_pay: Deserialize::default(),
71 google_pay: Deserialize::default(),
72 type_: Deserialize::default(),
73 }
74 }
75
76 fn take_out(&mut self) -> Option<Self::Out> {
77 let (Some(apple_pay), Some(google_pay), Some(type_)) =
78 (self.apple_pay, self.google_pay, self.type_)
79 else {
80 return None;
81 };
82 Some(Self::Out { apple_pay, google_pay, type_ })
83 }
84 }
85
86 impl Map for Builder<'_> {
87 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88 self.builder.key(k)
89 }
90
91 fn finish(&mut self) -> Result<()> {
92 *self.out = self.builder.take_out();
93 Ok(())
94 }
95 }
96
97 impl ObjectDeser for SetupAttemptPaymentMethodDetailsCardWallet {
98 type Builder = SetupAttemptPaymentMethodDetailsCardWalletBuilder;
99 }
100
101 impl FromValueOpt for SetupAttemptPaymentMethodDetailsCardWallet {
102 fn from_value(v: Value) -> Option<Self> {
103 let Value::Object(obj) = v else {
104 return None;
105 };
106 let mut b = SetupAttemptPaymentMethodDetailsCardWalletBuilder::deser_default();
107 for (k, v) in obj {
108 match k.as_str() {
109 "apple_pay" => b.apple_pay = FromValueOpt::from_value(v),
110 "google_pay" => b.google_pay = FromValueOpt::from_value(v),
111 "type" => b.type_ = FromValueOpt::from_value(v),
112
113 _ => {}
114 }
115 }
116 b.take_out()
117 }
118 }
119};
120#[derive(Copy, Clone, Eq, PartialEq)]
124pub enum SetupAttemptPaymentMethodDetailsCardWalletType {
125 ApplePay,
126 GooglePay,
127 Link,
128}
129impl SetupAttemptPaymentMethodDetailsCardWalletType {
130 pub fn as_str(self) -> &'static str {
131 use SetupAttemptPaymentMethodDetailsCardWalletType::*;
132 match self {
133 ApplePay => "apple_pay",
134 GooglePay => "google_pay",
135 Link => "link",
136 }
137 }
138}
139
140impl std::str::FromStr for SetupAttemptPaymentMethodDetailsCardWalletType {
141 type Err = stripe_types::StripeParseError;
142 fn from_str(s: &str) -> Result<Self, Self::Err> {
143 use SetupAttemptPaymentMethodDetailsCardWalletType::*;
144 match s {
145 "apple_pay" => Ok(ApplePay),
146 "google_pay" => Ok(GooglePay),
147 "link" => Ok(Link),
148 _ => Err(stripe_types::StripeParseError),
149 }
150 }
151}
152impl std::fmt::Display for SetupAttemptPaymentMethodDetailsCardWalletType {
153 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154 f.write_str(self.as_str())
155 }
156}
157
158impl std::fmt::Debug for SetupAttemptPaymentMethodDetailsCardWalletType {
159 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160 f.write_str(self.as_str())
161 }
162}
163#[cfg(feature = "serialize")]
164impl serde::Serialize for SetupAttemptPaymentMethodDetailsCardWalletType {
165 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
166 where
167 S: serde::Serializer,
168 {
169 serializer.serialize_str(self.as_str())
170 }
171}
172impl miniserde::Deserialize for SetupAttemptPaymentMethodDetailsCardWalletType {
173 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
174 crate::Place::new(out)
175 }
176}
177
178impl miniserde::de::Visitor for crate::Place<SetupAttemptPaymentMethodDetailsCardWalletType> {
179 fn string(&mut self, s: &str) -> miniserde::Result<()> {
180 use std::str::FromStr;
181 self.out = Some(
182 SetupAttemptPaymentMethodDetailsCardWalletType::from_str(s)
183 .map_err(|_| miniserde::Error)?,
184 );
185 Ok(())
186 }
187}
188
189stripe_types::impl_from_val_with_from_str!(SetupAttemptPaymentMethodDetailsCardWalletType);
190#[cfg(feature = "deserialize")]
191impl<'de> serde::Deserialize<'de> for SetupAttemptPaymentMethodDetailsCardWalletType {
192 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
193 use std::str::FromStr;
194 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
195 Self::from_str(&s).map_err(|_| {
196 serde::de::Error::custom(
197 "Unknown value for SetupAttemptPaymentMethodDetailsCardWalletType",
198 )
199 })
200 }
201}