stripe_shared/
payment_flows_automatic_payment_methods_setup_intent.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentFlowsAutomaticPaymentMethodsSetupIntent {
5 pub allow_redirects: Option<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>,
10 pub enabled: Option<bool>,
12}
13#[doc(hidden)]
14pub struct PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder {
15 allow_redirects: Option<Option<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>>,
16 enabled: Option<Option<bool>>,
17}
18
19#[allow(
20 unused_variables,
21 irrefutable_let_patterns,
22 clippy::let_unit_value,
23 clippy::match_single_binding,
24 clippy::single_match
25)]
26const _: () = {
27 use miniserde::de::{Map, Visitor};
28 use miniserde::json::Value;
29 use miniserde::{Deserialize, Result, make_place};
30 use stripe_types::miniserde_helpers::FromValueOpt;
31 use stripe_types::{MapBuilder, ObjectDeser};
32
33 make_place!(Place);
34
35 impl Deserialize for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
36 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37 Place::new(out)
38 }
39 }
40
41 struct Builder<'a> {
42 out: &'a mut Option<PaymentFlowsAutomaticPaymentMethodsSetupIntent>,
43 builder: PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder,
44 }
45
46 impl Visitor for Place<PaymentFlowsAutomaticPaymentMethodsSetupIntent> {
47 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48 Ok(Box::new(Builder {
49 out: &mut self.out,
50 builder: PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder::deser_default(),
51 }))
52 }
53 }
54
55 impl MapBuilder for PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder {
56 type Out = PaymentFlowsAutomaticPaymentMethodsSetupIntent;
57 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58 Ok(match k {
59 "allow_redirects" => Deserialize::begin(&mut self.allow_redirects),
60 "enabled" => Deserialize::begin(&mut self.enabled),
61 _ => <dyn Visitor>::ignore(),
62 })
63 }
64
65 fn deser_default() -> Self {
66 Self { allow_redirects: Deserialize::default(), enabled: Deserialize::default() }
67 }
68
69 fn take_out(&mut self) -> Option<Self::Out> {
70 let (Some(allow_redirects), Some(enabled)) =
71 (self.allow_redirects.take(), self.enabled)
72 else {
73 return None;
74 };
75 Some(Self::Out { allow_redirects, enabled })
76 }
77 }
78
79 impl Map for Builder<'_> {
80 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81 self.builder.key(k)
82 }
83
84 fn finish(&mut self) -> Result<()> {
85 *self.out = self.builder.take_out();
86 Ok(())
87 }
88 }
89
90 impl ObjectDeser for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
91 type Builder = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder;
92 }
93
94 impl FromValueOpt for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
95 fn from_value(v: Value) -> Option<Self> {
96 let Value::Object(obj) = v else {
97 return None;
98 };
99 let mut b = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder::deser_default();
100 for (k, v) in obj {
101 match k.as_str() {
102 "allow_redirects" => b.allow_redirects = FromValueOpt::from_value(v),
103 "enabled" => b.enabled = FromValueOpt::from_value(v),
104 _ => {}
105 }
106 }
107 b.take_out()
108 }
109 }
110};
111#[derive(Clone, Eq, PartialEq)]
116#[non_exhaustive]
117pub enum PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
118 Always,
119 Never,
120 Unknown(String),
122}
123impl PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
124 pub fn as_str(&self) -> &str {
125 use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
126 match self {
127 Always => "always",
128 Never => "never",
129 Unknown(v) => v,
130 }
131 }
132}
133
134impl std::str::FromStr for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
135 type Err = std::convert::Infallible;
136 fn from_str(s: &str) -> Result<Self, Self::Err> {
137 use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
138 match s {
139 "always" => Ok(Always),
140 "never" => Ok(Never),
141 v => {
142 tracing::warn!(
143 "Unknown value '{}' for enum '{}'",
144 v,
145 "PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects"
146 );
147 Ok(Unknown(v.to_owned()))
148 }
149 }
150 }
151}
152impl std::fmt::Display for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
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 PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
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 PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
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 PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
173 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
174 crate::Place::new(out)
175 }
176}
177
178impl miniserde::de::Visitor
179 for crate::Place<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>
180{
181 fn string(&mut self, s: &str) -> miniserde::Result<()> {
182 use std::str::FromStr;
183 self.out = Some(
184 PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::from_str(s)
185 .expect("infallible"),
186 );
187 Ok(())
188 }
189}
190
191stripe_types::impl_from_val_with_from_str!(
192 PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects
193);
194#[cfg(feature = "deserialize")]
195impl<'de> serde::Deserialize<'de> for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
196 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
197 use std::str::FromStr;
198 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
199 Ok(Self::from_str(&s).expect("infallible"))
200 }
201}