stripe_shared/
checkout_boleto_payment_method_options.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutBoletoPaymentMethodOptions {
5 pub expires_after_days: u32,
8 pub setup_future_usage: Option<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage>,
17}
18#[doc(hidden)]
19pub struct CheckoutBoletoPaymentMethodOptionsBuilder {
20 expires_after_days: Option<u32>,
21 setup_future_usage: Option<Option<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage>>,
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 CheckoutBoletoPaymentMethodOptions {
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<CheckoutBoletoPaymentMethodOptions>,
48 builder: CheckoutBoletoPaymentMethodOptionsBuilder,
49 }
50
51 impl Visitor for Place<CheckoutBoletoPaymentMethodOptions> {
52 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53 Ok(Box::new(Builder {
54 out: &mut self.out,
55 builder: CheckoutBoletoPaymentMethodOptionsBuilder::deser_default(),
56 }))
57 }
58 }
59
60 impl MapBuilder for CheckoutBoletoPaymentMethodOptionsBuilder {
61 type Out = CheckoutBoletoPaymentMethodOptions;
62 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63 Ok(match k {
64 "expires_after_days" => Deserialize::begin(&mut self.expires_after_days),
65 "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
66 _ => <dyn Visitor>::ignore(),
67 })
68 }
69
70 fn deser_default() -> Self {
71 Self {
72 expires_after_days: Deserialize::default(),
73 setup_future_usage: Deserialize::default(),
74 }
75 }
76
77 fn take_out(&mut self) -> Option<Self::Out> {
78 let (Some(expires_after_days), Some(setup_future_usage)) =
79 (self.expires_after_days, self.setup_future_usage.take())
80 else {
81 return None;
82 };
83 Some(Self::Out { expires_after_days, setup_future_usage })
84 }
85 }
86
87 impl Map for Builder<'_> {
88 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89 self.builder.key(k)
90 }
91
92 fn finish(&mut self) -> Result<()> {
93 *self.out = self.builder.take_out();
94 Ok(())
95 }
96 }
97
98 impl ObjectDeser for CheckoutBoletoPaymentMethodOptions {
99 type Builder = CheckoutBoletoPaymentMethodOptionsBuilder;
100 }
101
102 impl FromValueOpt for CheckoutBoletoPaymentMethodOptions {
103 fn from_value(v: Value) -> Option<Self> {
104 let Value::Object(obj) = v else {
105 return None;
106 };
107 let mut b = CheckoutBoletoPaymentMethodOptionsBuilder::deser_default();
108 for (k, v) in obj {
109 match k.as_str() {
110 "expires_after_days" => b.expires_after_days = FromValueOpt::from_value(v),
111 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
112 _ => {}
113 }
114 }
115 b.take_out()
116 }
117 }
118};
119#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
130 None,
131 OffSession,
132 OnSession,
133 Unknown(String),
135}
136impl CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
137 pub fn as_str(&self) -> &str {
138 use CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::*;
139 match self {
140 None => "none",
141 OffSession => "off_session",
142 OnSession => "on_session",
143 Unknown(v) => v,
144 }
145 }
146}
147
148impl std::str::FromStr for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
149 type Err = std::convert::Infallible;
150 fn from_str(s: &str) -> Result<Self, Self::Err> {
151 use CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::*;
152 match s {
153 "none" => Ok(None),
154 "off_session" => Ok(OffSession),
155 "on_session" => Ok(OnSession),
156 v => {
157 tracing::warn!(
158 "Unknown value '{}' for enum '{}'",
159 v,
160 "CheckoutBoletoPaymentMethodOptionsSetupFutureUsage"
161 );
162 Ok(Unknown(v.to_owned()))
163 }
164 }
165 }
166}
167impl std::fmt::Display for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
168 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169 f.write_str(self.as_str())
170 }
171}
172
173impl std::fmt::Debug for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
174 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175 f.write_str(self.as_str())
176 }
177}
178#[cfg(feature = "serialize")]
179impl serde::Serialize for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
180 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
181 where
182 S: serde::Serializer,
183 {
184 serializer.serialize_str(self.as_str())
185 }
186}
187impl miniserde::Deserialize for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
188 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
189 crate::Place::new(out)
190 }
191}
192
193impl miniserde::de::Visitor for crate::Place<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage> {
194 fn string(&mut self, s: &str) -> miniserde::Result<()> {
195 use std::str::FromStr;
196 self.out = Some(
197 CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"),
198 );
199 Ok(())
200 }
201}
202
203stripe_types::impl_from_val_with_from_str!(CheckoutBoletoPaymentMethodOptionsSetupFutureUsage);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
206 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207 use std::str::FromStr;
208 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
209 Ok(Self::from_str(&s).expect("infallible"))
210 }
211}