stripe_shared/
payment_intent_payment_method_options_sepa_debit.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsSepaDebit {
5    pub mandate_options:
6        Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsSepaDebit>,
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<PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage>,
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#[doc(hidden)]
22pub struct PaymentIntentPaymentMethodOptionsSepaDebitBuilder {
23    mandate_options:
24        Option<Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsSepaDebit>>,
25    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage>>,
26    target_date: Option<Option<String>>,
27}
28
29#[allow(
30    unused_variables,
31    irrefutable_let_patterns,
32    clippy::let_unit_value,
33    clippy::match_single_binding,
34    clippy::single_match
35)]
36const _: () = {
37    use miniserde::de::{Map, Visitor};
38    use miniserde::json::Value;
39    use miniserde::{make_place, Deserialize, Result};
40    use stripe_types::miniserde_helpers::FromValueOpt;
41    use stripe_types::{MapBuilder, ObjectDeser};
42
43    make_place!(Place);
44
45    impl Deserialize for PaymentIntentPaymentMethodOptionsSepaDebit {
46        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
47            Place::new(out)
48        }
49    }
50
51    struct Builder<'a> {
52        out: &'a mut Option<PaymentIntentPaymentMethodOptionsSepaDebit>,
53        builder: PaymentIntentPaymentMethodOptionsSepaDebitBuilder,
54    }
55
56    impl Visitor for Place<PaymentIntentPaymentMethodOptionsSepaDebit> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: PaymentIntentPaymentMethodOptionsSepaDebitBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for PaymentIntentPaymentMethodOptionsSepaDebitBuilder {
66        type Out = PaymentIntentPaymentMethodOptionsSepaDebit;
67        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68            Ok(match k {
69                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
70                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
71                "target_date" => Deserialize::begin(&mut self.target_date),
72
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                mandate_options: Deserialize::default(),
80                setup_future_usage: Deserialize::default(),
81                target_date: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (Some(mandate_options), Some(setup_future_usage), Some(target_date)) =
87                (self.mandate_options.take(), self.setup_future_usage, 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 PaymentIntentPaymentMethodOptionsSepaDebit {
107        type Builder = PaymentIntentPaymentMethodOptionsSepaDebitBuilder;
108    }
109
110    impl FromValueOpt for PaymentIntentPaymentMethodOptionsSepaDebit {
111        fn from_value(v: Value) -> Option<Self> {
112            let Value::Object(obj) = v else {
113                return None;
114            };
115            let mut b = PaymentIntentPaymentMethodOptionsSepaDebitBuilder::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            }
125            b.take_out()
126        }
127    }
128};
129/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
130///
131/// 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.
132/// 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.
133///
134/// 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.
135///
136/// 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).
137#[derive(Copy, Clone, Eq, PartialEq)]
138pub enum PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
139    None,
140    OffSession,
141    OnSession,
142}
143impl PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
144    pub fn as_str(self) -> &'static str {
145        use PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage::*;
146        match self {
147            None => "none",
148            OffSession => "off_session",
149            OnSession => "on_session",
150        }
151    }
152}
153
154impl std::str::FromStr for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
155    type Err = stripe_types::StripeParseError;
156    fn from_str(s: &str) -> Result<Self, Self::Err> {
157        use PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage::*;
158        match s {
159            "none" => Ok(None),
160            "off_session" => Ok(OffSession),
161            "on_session" => Ok(OnSession),
162            _ => Err(stripe_types::StripeParseError),
163        }
164    }
165}
166impl std::fmt::Display for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171
172impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177#[cfg(feature = "serialize")]
178impl serde::Serialize for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
179    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
180    where
181        S: serde::Serializer,
182    {
183        serializer.serialize_str(self.as_str())
184    }
185}
186impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
187    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
188        crate::Place::new(out)
189    }
190}
191
192impl miniserde::de::Visitor
193    for crate::Place<PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage>
194{
195    fn string(&mut self, s: &str) -> miniserde::Result<()> {
196        use std::str::FromStr;
197        self.out = Some(
198            PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage::from_str(s)
199                .map_err(|_| miniserde::Error)?,
200        );
201        Ok(())
202    }
203}
204
205stripe_types::impl_from_val_with_from_str!(
206    PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage
207);
208#[cfg(feature = "deserialize")]
209impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage {
210    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
211        use std::str::FromStr;
212        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
213        Self::from_str(&s).map_err(|_| {
214            serde::de::Error::custom(
215                "Unknown value for PaymentIntentPaymentMethodOptionsSepaDebitSetupFutureUsage",
216            )
217        })
218    }
219}