Skip to main content

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