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(), self.setup_future_usage, self.target_date.take())
86            else {
87                return None;
88            };
89            Some(Self::Out { mandate_options, setup_future_usage, target_date })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for CheckoutBacsDebitPaymentMethodOptions {
105        type Builder = CheckoutBacsDebitPaymentMethodOptionsBuilder;
106    }
107
108    impl FromValueOpt for CheckoutBacsDebitPaymentMethodOptions {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = CheckoutBacsDebitPaymentMethodOptionsBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
117                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
118                    "target_date" => b.target_date = FromValueOpt::from_value(v),
119                    _ => {}
120                }
121            }
122            b.take_out()
123        }
124    }
125};
126/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
127///
128/// 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.
129/// 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.
130///
131/// 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.
132///
133/// 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).
134#[derive(Copy, Clone, Eq, PartialEq)]
135pub enum CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
136    None,
137    OffSession,
138    OnSession,
139}
140impl CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
141    pub fn as_str(self) -> &'static str {
142        use CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::*;
143        match self {
144            None => "none",
145            OffSession => "off_session",
146            OnSession => "on_session",
147        }
148    }
149}
150
151impl std::str::FromStr for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
152    type Err = stripe_types::StripeParseError;
153    fn from_str(s: &str) -> Result<Self, Self::Err> {
154        use CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::*;
155        match s {
156            "none" => Ok(None),
157            "off_session" => Ok(OffSession),
158            "on_session" => Ok(OnSession),
159            _ => Err(stripe_types::StripeParseError),
160        }
161    }
162}
163impl std::fmt::Display for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168
169impl std::fmt::Debug for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.write_str(self.as_str())
172    }
173}
174#[cfg(feature = "serialize")]
175impl serde::Serialize for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
176    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
177    where
178        S: serde::Serializer,
179    {
180        serializer.serialize_str(self.as_str())
181    }
182}
183impl miniserde::Deserialize for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
184    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
185        crate::Place::new(out)
186    }
187}
188
189impl miniserde::de::Visitor
190    for crate::Place<CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage>
191{
192    fn string(&mut self, s: &str) -> miniserde::Result<()> {
193        use std::str::FromStr;
194        self.out = Some(
195            CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage::from_str(s)
196                .map_err(|_| miniserde::Error)?,
197        );
198        Ok(())
199    }
200}
201
202stripe_types::impl_from_val_with_from_str!(CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage);
203#[cfg(feature = "deserialize")]
204impl<'de> serde::Deserialize<'de> for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage {
205    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
206        use std::str::FromStr;
207        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
208        Self::from_str(&s).map_err(|_| {
209            serde::de::Error::custom(
210                "Unknown value for CheckoutBacsDebitPaymentMethodOptionsSetupFutureUsage",
211            )
212        })
213    }
214}