stripe_shared/
checkout_bacs_debit_payment_method_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutBacsDebitPaymentMethodOptions {
5    pub mandate_options: Option<stripe_shared::CheckoutPaymentMethodOptionsMandateOptionsBacsDebit>,
6    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
7    ///
8    /// 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.
9    /// 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.
10    ///
11    /// 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.
12    ///
13    /// 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).
14    pub setup_future_usage: Option<CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage>,
15    /// Controls when Stripe will attempt to debit the funds from the customer's account.
16    /// The date must be a string in YYYY-MM-DD format.
17    /// The date must be in the future and between 3 and 15 calendar days from now.
18    pub target_date: Option<String>,
19}
20#[doc(hidden)]
21pub struct CheckoutBacsDebitPaymentMethodOptionsBuilder {
22    mandate_options:
23        Option<Option<stripe_shared::CheckoutPaymentMethodOptionsMandateOptionsBacsDebit>>,
24    setup_future_usage: Option<Option<CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage>>,
25    target_date: Option<Option<String>>,
26}
27
28#[allow(
29    unused_variables,
30    irrefutable_let_patterns,
31    clippy::let_unit_value,
32    clippy::match_single_binding,
33    clippy::single_match
34)]
35const _: () = {
36    use miniserde::de::{Map, Visitor};
37    use miniserde::json::Value;
38    use miniserde::{Deserialize, Result, make_place};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for CheckoutBacsDebitPaymentMethodOptions {
45        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
46            Place::new(out)
47        }
48    }
49
50    struct Builder<'a> {
51        out: &'a mut Option<CheckoutBacsDebitPaymentMethodOptions>,
52        builder: CheckoutBacsDebitPaymentMethodOptionsBuilder,
53    }
54
55    impl Visitor for Place<CheckoutBacsDebitPaymentMethodOptions> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: CheckoutBacsDebitPaymentMethodOptionsBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for CheckoutBacsDebitPaymentMethodOptionsBuilder {
65        type Out = CheckoutBacsDebitPaymentMethodOptions;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
69                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
70                "target_date" => Deserialize::begin(&mut self.target_date),
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self {
77                mandate_options: Deserialize::default(),
78                setup_future_usage: Deserialize::default(),
79                target_date: Deserialize::default(),
80            }
81        }
82
83        fn take_out(&mut self) -> Option<Self::Out> {
84            let (Some(mandate_options), Some(setup_future_usage), Some(target_date)) = (
85                self.mandate_options.take(),
86                self.setup_future_usage.take(),
87                self.target_date.take(),
88            ) else {
89                return None;
90            };
91            Some(Self::Out { mandate_options, setup_future_usage, target_date })
92        }
93    }
94
95    impl Map for Builder<'_> {
96        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
97            self.builder.key(k)
98        }
99
100        fn finish(&mut self) -> Result<()> {
101            *self.out = self.builder.take_out();
102            Ok(())
103        }
104    }
105
106    impl ObjectDeser for CheckoutBacsDebitPaymentMethodOptions {
107        type Builder = CheckoutBacsDebitPaymentMethodOptionsBuilder;
108    }
109
110    impl FromValueOpt for CheckoutBacsDebitPaymentMethodOptions {
111        fn from_value(v: Value) -> Option<Self> {
112            let Value::Object(obj) = v else {
113                return None;
114            };
115            let mut b = CheckoutBacsDebitPaymentMethodOptionsBuilder::deser_default();
116            for (k, v) in obj {
117                match k.as_str() {
118                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
119                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
120                    "target_date" => b.target_date = FromValueOpt::from_value(v),
121                    _ => {}
122                }
123            }
124            b.take_out()
125        }
126    }
127};
128/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
129///
130/// 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.
131/// 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.
132///
133/// 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.
134///
135/// 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).
136#[derive(Clone, Eq, PartialEq)]
137#[non_exhaustive]
138pub enum CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
139    None,
140    OffSession,
141    OnSession,
142    /// An unrecognized value from Stripe. Should not be used as a request parameter.
143    Unknown(String),
144}
145impl CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
146    pub fn as_str(&self) -> &str {
147        use CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::*;
148        match self {
149            None => "none",
150            OffSession => "off_session",
151            OnSession => "on_session",
152            Unknown(v) => v,
153        }
154    }
155}
156
157impl std::str::FromStr for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
158    type Err = std::convert::Infallible;
159    fn from_str(s: &str) -> Result<Self, Self::Err> {
160        use CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::*;
161        match s {
162            "none" => Ok(None),
163            "off_session" => Ok(OffSession),
164            "on_session" => Ok(OnSession),
165            v => {
166                tracing::warn!(
167                    "Unknown value '{}' for enum '{}'",
168                    v,
169                    "CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage"
170                );
171                Ok(Unknown(v.to_owned()))
172            }
173        }
174    }
175}
176impl std::fmt::Display for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.write_str(self.as_str())
179    }
180}
181
182impl std::fmt::Debug for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
183    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
184        f.write_str(self.as_str())
185    }
186}
187#[cfg(feature = "serialize")]
188impl serde::Serialize for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::Serializer,
192    {
193        serializer.serialize_str(self.as_str())
194    }
195}
196impl miniserde::Deserialize for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
197    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
198        crate::Place::new(out)
199    }
200}
201
202impl miniserde::de::Visitor
203    for crate::Place<CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage>
204{
205    fn string(&mut self, s: &str) -> miniserde::Result<()> {
206        use std::str::FromStr;
207        self.out = Some(
208            CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"),
209        );
210        Ok(())
211    }
212}
213
214stripe_types::impl_from_val_with_from_str!(CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage);
215#[cfg(feature = "deserialize")]
216impl<'de> serde::Deserialize<'de> for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
217    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
218        use std::str::FromStr;
219        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
220        Ok(Self::from_str(&s).expect("infallible"))
221    }
222}