Skip to main content

stripe_shared/
checkout_us_bank_account_payment_method_options.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 CheckoutUsBankAccountPaymentMethodOptions {
6    pub financial_connections: Option<stripe_shared::LinkedAccountOptionsCommon>,
7    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
8    ///
9    /// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
10    /// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
11    ///
12    /// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
13    ///
14    /// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
15    pub setup_future_usage: Option<CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage>,
16    /// Controls when Stripe will attempt to debit the funds from the customer's account.
17    /// The date must be a string in YYYY-MM-DD format.
18    /// The date must be in the future and between 3 and 15 calendar days from now.
19    pub target_date: Option<String>,
20    /// Bank account verification method. The default value is `automatic`.
21    pub verification_method: Option<CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod>,
22}
23#[cfg(feature = "redact-generated-debug")]
24impl std::fmt::Debug for CheckoutUsBankAccountPaymentMethodOptions {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        f.debug_struct("CheckoutUsBankAccountPaymentMethodOptions").finish_non_exhaustive()
27    }
28}
29#[doc(hidden)]
30pub struct CheckoutUsBankAccountPaymentMethodOptionsBuilder {
31    financial_connections: Option<Option<stripe_shared::LinkedAccountOptionsCommon>>,
32    setup_future_usage: Option<Option<CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage>>,
33    target_date: Option<Option<String>>,
34    verification_method:
35        Option<Option<CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod>>,
36}
37
38#[allow(
39    unused_variables,
40    irrefutable_let_patterns,
41    clippy::let_unit_value,
42    clippy::match_single_binding,
43    clippy::single_match
44)]
45const _: () = {
46    use miniserde::de::{Map, Visitor};
47    use miniserde::json::Value;
48    use miniserde::{Deserialize, Result, make_place};
49    use stripe_types::miniserde_helpers::FromValueOpt;
50    use stripe_types::{MapBuilder, ObjectDeser};
51
52    make_place!(Place);
53
54    impl Deserialize for CheckoutUsBankAccountPaymentMethodOptions {
55        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
56            Place::new(out)
57        }
58    }
59
60    struct Builder<'a> {
61        out: &'a mut Option<CheckoutUsBankAccountPaymentMethodOptions>,
62        builder: CheckoutUsBankAccountPaymentMethodOptionsBuilder,
63    }
64
65    impl Visitor for Place<CheckoutUsBankAccountPaymentMethodOptions> {
66        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
67            Ok(Box::new(Builder {
68                out: &mut self.out,
69                builder: CheckoutUsBankAccountPaymentMethodOptionsBuilder::deser_default(),
70            }))
71        }
72    }
73
74    impl MapBuilder for CheckoutUsBankAccountPaymentMethodOptionsBuilder {
75        type Out = CheckoutUsBankAccountPaymentMethodOptions;
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            Ok(match k {
78                "financial_connections" => Deserialize::begin(&mut self.financial_connections),
79                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
80                "target_date" => Deserialize::begin(&mut self.target_date),
81                "verification_method" => Deserialize::begin(&mut self.verification_method),
82                _ => <dyn Visitor>::ignore(),
83            })
84        }
85
86        fn deser_default() -> Self {
87            Self {
88                financial_connections: Some(None),
89                setup_future_usage: Some(None),
90                target_date: Some(None),
91                verification_method: Some(None),
92            }
93        }
94
95        fn take_out(&mut self) -> Option<Self::Out> {
96            let (
97                Some(financial_connections),
98                Some(setup_future_usage),
99                Some(target_date),
100                Some(verification_method),
101            ) = (
102                self.financial_connections.take(),
103                self.setup_future_usage.take(),
104                self.target_date.take(),
105                self.verification_method.take(),
106            )
107            else {
108                return None;
109            };
110            Some(Self::Out {
111                financial_connections,
112                setup_future_usage,
113                target_date,
114                verification_method,
115            })
116        }
117    }
118
119    impl Map for Builder<'_> {
120        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
121            self.builder.key(k)
122        }
123
124        fn finish(&mut self) -> Result<()> {
125            *self.out = self.builder.take_out();
126            Ok(())
127        }
128    }
129
130    impl ObjectDeser for CheckoutUsBankAccountPaymentMethodOptions {
131        type Builder = CheckoutUsBankAccountPaymentMethodOptionsBuilder;
132    }
133
134    impl FromValueOpt for CheckoutUsBankAccountPaymentMethodOptions {
135        fn from_value(v: Value) -> Option<Self> {
136            let Value::Object(obj) = v else {
137                return None;
138            };
139            let mut b = CheckoutUsBankAccountPaymentMethodOptionsBuilder::deser_default();
140            for (k, v) in obj {
141                match k.as_str() {
142                    "financial_connections" => {
143                        b.financial_connections = FromValueOpt::from_value(v)
144                    }
145                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
146                    "target_date" => b.target_date = FromValueOpt::from_value(v),
147                    "verification_method" => b.verification_method = FromValueOpt::from_value(v),
148                    _ => {}
149                }
150            }
151            b.take_out()
152        }
153    }
154};
155/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
156///
157/// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
158/// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
159///
160/// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
161///
162/// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
163#[derive(Clone, Eq, PartialEq)]
164#[non_exhaustive]
165pub enum CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
166    None,
167    OffSession,
168    OnSession,
169    /// An unrecognized value from Stripe. Should not be used as a request parameter.
170    Unknown(String),
171}
172impl CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
173    pub fn as_str(&self) -> &str {
174        use CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage::*;
175        match self {
176            None => "none",
177            OffSession => "off_session",
178            OnSession => "on_session",
179            Unknown(v) => v,
180        }
181    }
182}
183
184impl std::str::FromStr for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
185    type Err = std::convert::Infallible;
186    fn from_str(s: &str) -> Result<Self, Self::Err> {
187        use CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage::*;
188        match s {
189            "none" => Ok(None),
190            "off_session" => Ok(OffSession),
191            "on_session" => Ok(OnSession),
192            v => {
193                tracing::warn!(
194                    "Unknown value '{}' for enum '{}'",
195                    v,
196                    "CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage"
197                );
198                Ok(Unknown(v.to_owned()))
199            }
200        }
201    }
202}
203impl std::fmt::Display for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
204    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
205        f.write_str(self.as_str())
206    }
207}
208
209#[cfg(not(feature = "redact-generated-debug"))]
210impl std::fmt::Debug for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
211    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
212        f.write_str(self.as_str())
213    }
214}
215#[cfg(feature = "redact-generated-debug")]
216impl std::fmt::Debug for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
217    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
218        f.debug_struct(stringify!(CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage))
219            .finish_non_exhaustive()
220    }
221}
222#[cfg(feature = "serialize")]
223impl serde::Serialize for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
224    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
225    where
226        S: serde::Serializer,
227    {
228        serializer.serialize_str(self.as_str())
229    }
230}
231impl miniserde::Deserialize for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
232    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
233        crate::Place::new(out)
234    }
235}
236
237impl miniserde::de::Visitor
238    for crate::Place<CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage>
239{
240    fn string(&mut self, s: &str) -> miniserde::Result<()> {
241        use std::str::FromStr;
242        self.out = Some(
243            CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage::from_str(s)
244                .expect("infallible"),
245        );
246        Ok(())
247    }
248}
249
250stripe_types::impl_from_val_with_from_str!(
251    CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage
252);
253#[cfg(feature = "deserialize")]
254impl<'de> serde::Deserialize<'de> for CheckoutUsBankAccountPaymentMethodOptionsSetupFutureUsage {
255    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
256        use std::str::FromStr;
257        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
258        Ok(Self::from_str(&s).expect("infallible"))
259    }
260}
261/// Bank account verification method. The default value is `automatic`.
262#[derive(Clone, Eq, PartialEq)]
263#[non_exhaustive]
264pub enum CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
265    Automatic,
266    Instant,
267    /// An unrecognized value from Stripe. Should not be used as a request parameter.
268    Unknown(String),
269}
270impl CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
271    pub fn as_str(&self) -> &str {
272        use CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod::*;
273        match self {
274            Automatic => "automatic",
275            Instant => "instant",
276            Unknown(v) => v,
277        }
278    }
279}
280
281impl std::str::FromStr for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
282    type Err = std::convert::Infallible;
283    fn from_str(s: &str) -> Result<Self, Self::Err> {
284        use CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod::*;
285        match s {
286            "automatic" => Ok(Automatic),
287            "instant" => Ok(Instant),
288            v => {
289                tracing::warn!(
290                    "Unknown value '{}' for enum '{}'",
291                    v,
292                    "CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod"
293                );
294                Ok(Unknown(v.to_owned()))
295            }
296        }
297    }
298}
299impl std::fmt::Display for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
300    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
301        f.write_str(self.as_str())
302    }
303}
304
305#[cfg(not(feature = "redact-generated-debug"))]
306impl std::fmt::Debug for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
307    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308        f.write_str(self.as_str())
309    }
310}
311#[cfg(feature = "redact-generated-debug")]
312impl std::fmt::Debug for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
313    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314        f.debug_struct(stringify!(CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod))
315            .finish_non_exhaustive()
316    }
317}
318#[cfg(feature = "serialize")]
319impl serde::Serialize for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
320    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
321    where
322        S: serde::Serializer,
323    {
324        serializer.serialize_str(self.as_str())
325    }
326}
327impl miniserde::Deserialize for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
328    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
329        crate::Place::new(out)
330    }
331}
332
333impl miniserde::de::Visitor
334    for crate::Place<CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod>
335{
336    fn string(&mut self, s: &str) -> miniserde::Result<()> {
337        use std::str::FromStr;
338        self.out = Some(
339            CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod::from_str(s)
340                .expect("infallible"),
341        );
342        Ok(())
343    }
344}
345
346stripe_types::impl_from_val_with_from_str!(
347    CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod
348);
349#[cfg(feature = "deserialize")]
350impl<'de> serde::Deserialize<'de> for CheckoutUsBankAccountPaymentMethodOptionsVerificationMethod {
351    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
352        use std::str::FromStr;
353        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
354        Ok(Self::from_str(&s).expect("infallible"))
355    }
356}