stripe_shared/
checkout_sepa_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 CheckoutSepaDebitPaymentMethodOptions {
5    pub mandate_options: Option<stripe_shared::CheckoutPaymentMethodOptionsMandateOptionsSepaDebit>,
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<CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage>,
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 CheckoutSepaDebitPaymentMethodOptionsBuilder {
22    mandate_options:
23        Option<Option<stripe_shared::CheckoutPaymentMethodOptionsMandateOptionsSepaDebit>>,
24    setup_future_usage: Option<Option<CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage>>,
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::{make_place, Deserialize, Result};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for CheckoutSepaDebitPaymentMethodOptions {
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<CheckoutSepaDebitPaymentMethodOptions>,
52        builder: CheckoutSepaDebitPaymentMethodOptionsBuilder,
53    }
54
55    impl Visitor for Place<CheckoutSepaDebitPaymentMethodOptions> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: CheckoutSepaDebitPaymentMethodOptionsBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for CheckoutSepaDebitPaymentMethodOptionsBuilder {
65        type Out = CheckoutSepaDebitPaymentMethodOptions;
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
72                _ => <dyn Visitor>::ignore(),
73            })
74        }
75
76        fn deser_default() -> Self {
77            Self {
78                mandate_options: Deserialize::default(),
79                setup_future_usage: Deserialize::default(),
80                target_date: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (Some(mandate_options), Some(setup_future_usage), Some(target_date)) =
86                (self.mandate_options.take(), self.setup_future_usage, self.target_date.take())
87            else {
88                return None;
89            };
90            Some(Self::Out { mandate_options, setup_future_usage, target_date })
91        }
92    }
93
94    impl Map for Builder<'_> {
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            self.builder.key(k)
97        }
98
99        fn finish(&mut self) -> Result<()> {
100            *self.out = self.builder.take_out();
101            Ok(())
102        }
103    }
104
105    impl ObjectDeser for CheckoutSepaDebitPaymentMethodOptions {
106        type Builder = CheckoutSepaDebitPaymentMethodOptionsBuilder;
107    }
108
109    impl FromValueOpt for CheckoutSepaDebitPaymentMethodOptions {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = CheckoutSepaDebitPaymentMethodOptionsBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
118                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
119                    "target_date" => b.target_date = FromValueOpt::from_value(v),
120
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(Copy, Clone, Eq, PartialEq)]
137pub enum CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
138    None,
139    OffSession,
140    OnSession,
141}
142impl CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
143    pub fn as_str(self) -> &'static str {
144        use CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage::*;
145        match self {
146            None => "none",
147            OffSession => "off_session",
148            OnSession => "on_session",
149        }
150    }
151}
152
153impl std::str::FromStr for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
154    type Err = stripe_types::StripeParseError;
155    fn from_str(s: &str) -> Result<Self, Self::Err> {
156        use CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage::*;
157        match s {
158            "none" => Ok(None),
159            "off_session" => Ok(OffSession),
160            "on_session" => Ok(OnSession),
161            _ => Err(stripe_types::StripeParseError),
162        }
163    }
164}
165impl std::fmt::Display for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170
171impl std::fmt::Debug for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
172    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173        f.write_str(self.as_str())
174    }
175}
176#[cfg(feature = "serialize")]
177impl serde::Serialize for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
178    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
179    where
180        S: serde::Serializer,
181    {
182        serializer.serialize_str(self.as_str())
183    }
184}
185impl miniserde::Deserialize for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
186    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
187        crate::Place::new(out)
188    }
189}
190
191impl miniserde::de::Visitor
192    for crate::Place<CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage>
193{
194    fn string(&mut self, s: &str) -> miniserde::Result<()> {
195        use std::str::FromStr;
196        self.out = Some(
197            CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage::from_str(s)
198                .map_err(|_| miniserde::Error)?,
199        );
200        Ok(())
201    }
202}
203
204stripe_types::impl_from_val_with_from_str!(CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage);
205#[cfg(feature = "deserialize")]
206impl<'de> serde::Deserialize<'de> for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage {
207    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
208        use std::str::FromStr;
209        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
210        Self::from_str(&s).map_err(|_| {
211            serde::de::Error::custom(
212                "Unknown value for CheckoutSepaDebitPaymentMethodOptionsSetupFutureUsage",
213            )
214        })
215    }
216}