Skip to main content

stripe_shared/
invoice_payment_method_options_us_bank_account.rs

1#[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 InvoicePaymentMethodOptionsUsBankAccount {
6    pub financial_connections:
7        Option<stripe_shared::InvoicePaymentMethodOptionsUsBankAccountLinkedAccountOptions>,
8    /// Bank account verification method. The default value is `automatic`.
9    pub verification_method: Option<InvoicePaymentMethodOptionsUsBankAccountVerificationMethod>,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for InvoicePaymentMethodOptionsUsBankAccount {
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        f.debug_struct("InvoicePaymentMethodOptionsUsBankAccount").finish_non_exhaustive()
15    }
16}
17#[doc(hidden)]
18pub struct InvoicePaymentMethodOptionsUsBankAccountBuilder {
19    financial_connections:
20        Option<Option<stripe_shared::InvoicePaymentMethodOptionsUsBankAccountLinkedAccountOptions>>,
21    verification_method: Option<Option<InvoicePaymentMethodOptionsUsBankAccountVerificationMethod>>,
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 InvoicePaymentMethodOptionsUsBankAccount {
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<InvoicePaymentMethodOptionsUsBankAccount>,
48        builder: InvoicePaymentMethodOptionsUsBankAccountBuilder,
49    }
50
51    impl Visitor for Place<InvoicePaymentMethodOptionsUsBankAccount> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: InvoicePaymentMethodOptionsUsBankAccountBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for InvoicePaymentMethodOptionsUsBankAccountBuilder {
61        type Out = InvoicePaymentMethodOptionsUsBankAccount;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "financial_connections" => Deserialize::begin(&mut self.financial_connections),
65                "verification_method" => Deserialize::begin(&mut self.verification_method),
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self { financial_connections: Some(None), verification_method: Some(None) }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(financial_connections), Some(verification_method)) =
76                (self.financial_connections.take(), self.verification_method.take())
77            else {
78                return None;
79            };
80            Some(Self::Out { financial_connections, verification_method })
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 InvoicePaymentMethodOptionsUsBankAccount {
96        type Builder = InvoicePaymentMethodOptionsUsBankAccountBuilder;
97    }
98
99    impl FromValueOpt for InvoicePaymentMethodOptionsUsBankAccount {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = InvoicePaymentMethodOptionsUsBankAccountBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "financial_connections" => {
108                        b.financial_connections = FromValueOpt::from_value(v)
109                    }
110                    "verification_method" => b.verification_method = FromValueOpt::from_value(v),
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Bank account verification method. The default value is `automatic`.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
122    Automatic,
123    Instant,
124    Microdeposits,
125    /// An unrecognized value from Stripe. Should not be used as a request parameter.
126    Unknown(String),
127}
128impl InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
129    pub fn as_str(&self) -> &str {
130        use InvoicePaymentMethodOptionsUsBankAccountVerificationMethod::*;
131        match self {
132            Automatic => "automatic",
133            Instant => "instant",
134            Microdeposits => "microdeposits",
135            Unknown(v) => v,
136        }
137    }
138}
139
140impl std::str::FromStr for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
141    type Err = std::convert::Infallible;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use InvoicePaymentMethodOptionsUsBankAccountVerificationMethod::*;
144        match s {
145            "automatic" => Ok(Automatic),
146            "instant" => Ok(Instant),
147            "microdeposits" => Ok(Microdeposits),
148            v => {
149                tracing::warn!(
150                    "Unknown value '{}' for enum '{}'",
151                    v,
152                    "InvoicePaymentMethodOptionsUsBankAccountVerificationMethod"
153                );
154                Ok(Unknown(v.to_owned()))
155            }
156        }
157    }
158}
159impl std::fmt::Display for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164
165#[cfg(not(feature = "redact-generated-debug"))]
166impl std::fmt::Debug for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171#[cfg(feature = "redact-generated-debug")]
172impl std::fmt::Debug for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.debug_struct(stringify!(InvoicePaymentMethodOptionsUsBankAccountVerificationMethod))
175            .finish_non_exhaustive()
176    }
177}
178#[cfg(feature = "serialize")]
179impl serde::Serialize for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
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 InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
188    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
189        crate::Place::new(out)
190    }
191}
192
193impl miniserde::de::Visitor
194    for crate::Place<InvoicePaymentMethodOptionsUsBankAccountVerificationMethod>
195{
196    fn string(&mut self, s: &str) -> miniserde::Result<()> {
197        use std::str::FromStr;
198        self.out = Some(
199            InvoicePaymentMethodOptionsUsBankAccountVerificationMethod::from_str(s)
200                .expect("infallible"),
201        );
202        Ok(())
203    }
204}
205
206stripe_types::impl_from_val_with_from_str!(
207    InvoicePaymentMethodOptionsUsBankAccountVerificationMethod
208);
209#[cfg(feature = "deserialize")]
210impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsUsBankAccountVerificationMethod {
211    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
212        use std::str::FromStr;
213        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
214        Ok(Self::from_str(&s).expect("infallible"))
215    }
216}