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