stripe_shared/
payment_flows_automatic_payment_methods_payment_intent.rs1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentFlowsAutomaticPaymentMethodsPaymentIntent {
5 pub allow_redirects: Option<PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects>,
10 pub enabled: bool,
12}
13#[doc(hidden)]
14pub struct PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder {
15 allow_redirects: Option<Option<PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects>>,
16 enabled: 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 PaymentFlowsAutomaticPaymentMethodsPaymentIntent {
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<PaymentFlowsAutomaticPaymentMethodsPaymentIntent>,
43 builder: PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder,
44 }
45
46 impl Visitor for Place<PaymentFlowsAutomaticPaymentMethodsPaymentIntent> {
47 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48 Ok(Box::new(Builder {
49 out: &mut self.out,
50 builder: PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder::deser_default(),
51 }))
52 }
53 }
54
55 impl MapBuilder for PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder {
56 type Out = PaymentFlowsAutomaticPaymentMethodsPaymentIntent;
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)) = (self.allow_redirects, self.enabled)
71 else {
72 return None;
73 };
74 Some(Self::Out { allow_redirects, enabled })
75 }
76 }
77
78 impl Map for Builder<'_> {
79 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80 self.builder.key(k)
81 }
82
83 fn finish(&mut self) -> Result<()> {
84 *self.out = self.builder.take_out();
85 Ok(())
86 }
87 }
88
89 impl ObjectDeser for PaymentFlowsAutomaticPaymentMethodsPaymentIntent {
90 type Builder = PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder;
91 }
92
93 impl FromValueOpt for PaymentFlowsAutomaticPaymentMethodsPaymentIntent {
94 fn from_value(v: Value) -> Option<Self> {
95 let Value::Object(obj) = v else {
96 return None;
97 };
98 let mut b = PaymentFlowsAutomaticPaymentMethodsPaymentIntentBuilder::deser_default();
99 for (k, v) in obj {
100 match k.as_str() {
101 "allow_redirects" => b.allow_redirects = FromValueOpt::from_value(v),
102 "enabled" => b.enabled = FromValueOpt::from_value(v),
103 _ => {}
104 }
105 }
106 b.take_out()
107 }
108 }
109};
110#[derive(Copy, Clone, Eq, PartialEq)]
115pub enum PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
116 Always,
117 Never,
118}
119impl PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
120 pub fn as_str(self) -> &'static str {
121 use PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects::*;
122 match self {
123 Always => "always",
124 Never => "never",
125 }
126 }
127}
128
129impl std::str::FromStr for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
130 type Err = stripe_types::StripeParseError;
131 fn from_str(s: &str) -> Result<Self, Self::Err> {
132 use PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects::*;
133 match s {
134 "always" => Ok(Always),
135 "never" => Ok(Never),
136 _ => Err(stripe_types::StripeParseError),
137 }
138 }
139}
140impl std::fmt::Display for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
141 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142 f.write_str(self.as_str())
143 }
144}
145
146impl std::fmt::Debug for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
147 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148 f.write_str(self.as_str())
149 }
150}
151#[cfg(feature = "serialize")]
152impl serde::Serialize for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
153 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
154 where
155 S: serde::Serializer,
156 {
157 serializer.serialize_str(self.as_str())
158 }
159}
160impl miniserde::Deserialize for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects {
161 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
162 crate::Place::new(out)
163 }
164}
165
166impl miniserde::de::Visitor
167 for crate::Place<PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects>
168{
169 fn string(&mut self, s: &str) -> miniserde::Result<()> {
170 use std::str::FromStr;
171 self.out = Some(
172 PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects::from_str(s)
173 .map_err(|_| miniserde::Error)?,
174 );
175 Ok(())
176 }
177}
178
179stripe_types::impl_from_val_with_from_str!(
180 PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects
181);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de>
184 for PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects
185{
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 PaymentFlowsAutomaticPaymentMethodsPaymentIntentAllowRedirects",
192 )
193 })
194 }
195}