Skip to main content

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