stripe_shared/
invoice_payment_method_options_us_bank_account.rs

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