stripe_shared/
payment_intent_payment_method_options_bacs_debit.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsBacsDebit {
5    pub mandate_options:
6        Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsBacsDebit>,
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<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>,
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 PaymentIntentPaymentMethodOptionsBacsDebitBuilder {
23    mandate_options:
24        Option<Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsBacsDebit>>,
25    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>>,
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::{Deserialize, Result, make_place};
40    use stripe_types::miniserde_helpers::FromValueOpt;
41    use stripe_types::{MapBuilder, ObjectDeser};
42
43    make_place!(Place);
44
45    impl Deserialize for PaymentIntentPaymentMethodOptionsBacsDebit {
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<PaymentIntentPaymentMethodOptionsBacsDebit>,
53        builder: PaymentIntentPaymentMethodOptionsBacsDebitBuilder,
54    }
55
56    impl Visitor for Place<PaymentIntentPaymentMethodOptionsBacsDebit> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: PaymentIntentPaymentMethodOptionsBacsDebitBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for PaymentIntentPaymentMethodOptionsBacsDebitBuilder {
66        type Out = PaymentIntentPaymentMethodOptionsBacsDebit;
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                _ => <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 PaymentIntentPaymentMethodOptionsBacsDebit {
106        type Builder = PaymentIntentPaymentMethodOptionsBacsDebitBuilder;
107    }
108
109    impl FromValueOpt for PaymentIntentPaymentMethodOptionsBacsDebit {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = PaymentIntentPaymentMethodOptionsBacsDebitBuilder::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            b.take_out()
124        }
125    }
126};
127/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
128///
129/// 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.
130/// 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.
131///
132/// 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.
133///
134/// 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).
135#[derive(Copy, Clone, Eq, PartialEq)]
136pub enum PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
137    None,
138    OffSession,
139    OnSession,
140}
141impl PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
142    pub fn as_str(self) -> &'static str {
143        use PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::*;
144        match self {
145            None => "none",
146            OffSession => "off_session",
147            OnSession => "on_session",
148        }
149    }
150}
151
152impl std::str::FromStr for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
153    type Err = stripe_types::StripeParseError;
154    fn from_str(s: &str) -> Result<Self, Self::Err> {
155        use PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::*;
156        match s {
157            "none" => Ok(None),
158            "off_session" => Ok(OffSession),
159            "on_session" => Ok(OnSession),
160            _ => Err(stripe_types::StripeParseError),
161        }
162    }
163}
164impl std::fmt::Display for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169
170impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
178    where
179        S: serde::Serializer,
180    {
181        serializer.serialize_str(self.as_str())
182    }
183}
184impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
185    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
186        crate::Place::new(out)
187    }
188}
189
190impl miniserde::de::Visitor
191    for crate::Place<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>
192{
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out = Some(
196            PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::from_str(s)
197                .map_err(|_| miniserde::Error)?,
198        );
199        Ok(())
200    }
201}
202
203stripe_types::impl_from_val_with_from_str!(
204    PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage
205);
206#[cfg(feature = "deserialize")]
207impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
208    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
209        use std::str::FromStr;
210        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
211        Self::from_str(&s).map_err(|_| {
212            serde::de::Error::custom(
213                "Unknown value for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage",
214            )
215        })
216    }
217}