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