stripe_shared/
payment_method_options_bancontact.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsBancontact {
5    /// Preferred language of the Bancontact authorization page that the customer is redirected to.
6    pub preferred_language: PaymentMethodOptionsBancontactPreferredLanguage,
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<PaymentMethodOptionsBancontactSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentMethodOptionsBancontactBuilder {
19    preferred_language: Option<PaymentMethodOptionsBancontactPreferredLanguage>,
20    setup_future_usage: Option<Option<PaymentMethodOptionsBancontactSetupFutureUsage>>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for PaymentMethodOptionsBancontact {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<PaymentMethodOptionsBancontact>,
47        builder: PaymentMethodOptionsBancontactBuilder,
48    }
49
50    impl Visitor for Place<PaymentMethodOptionsBancontact> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: PaymentMethodOptionsBancontactBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for PaymentMethodOptionsBancontactBuilder {
60        type Out = PaymentMethodOptionsBancontact;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "preferred_language" => Deserialize::begin(&mut self.preferred_language),
64                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                preferred_language: Deserialize::default(),
72                setup_future_usage: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(preferred_language), Some(setup_future_usage)) =
78                (self.preferred_language.take(), self.setup_future_usage.take())
79            else {
80                return None;
81            };
82            Some(Self::Out { preferred_language, setup_future_usage })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for PaymentMethodOptionsBancontact {
98        type Builder = PaymentMethodOptionsBancontactBuilder;
99    }
100
101    impl FromValueOpt for PaymentMethodOptionsBancontact {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentMethodOptionsBancontactBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "preferred_language" => b.preferred_language = FromValueOpt::from_value(v),
110                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Preferred language of the Bancontact authorization page that the customer is redirected to.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum PaymentMethodOptionsBancontactPreferredLanguage {
122    De,
123    En,
124    Fr,
125    Nl,
126    /// An unrecognized value from Stripe. Should not be used as a request parameter.
127    Unknown(String),
128}
129impl PaymentMethodOptionsBancontactPreferredLanguage {
130    pub fn as_str(&self) -> &str {
131        use PaymentMethodOptionsBancontactPreferredLanguage::*;
132        match self {
133            De => "de",
134            En => "en",
135            Fr => "fr",
136            Nl => "nl",
137            Unknown(v) => v,
138        }
139    }
140}
141
142impl std::str::FromStr for PaymentMethodOptionsBancontactPreferredLanguage {
143    type Err = std::convert::Infallible;
144    fn from_str(s: &str) -> Result<Self, Self::Err> {
145        use PaymentMethodOptionsBancontactPreferredLanguage::*;
146        match s {
147            "de" => Ok(De),
148            "en" => Ok(En),
149            "fr" => Ok(Fr),
150            "nl" => Ok(Nl),
151            v => {
152                tracing::warn!(
153                    "Unknown value '{}' for enum '{}'",
154                    v,
155                    "PaymentMethodOptionsBancontactPreferredLanguage"
156                );
157                Ok(Unknown(v.to_owned()))
158            }
159        }
160    }
161}
162impl std::fmt::Display for PaymentMethodOptionsBancontactPreferredLanguage {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167
168impl std::fmt::Debug for PaymentMethodOptionsBancontactPreferredLanguage {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173#[cfg(feature = "serialize")]
174impl serde::Serialize for PaymentMethodOptionsBancontactPreferredLanguage {
175    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176    where
177        S: serde::Serializer,
178    {
179        serializer.serialize_str(self.as_str())
180    }
181}
182impl miniserde::Deserialize for PaymentMethodOptionsBancontactPreferredLanguage {
183    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
184        crate::Place::new(out)
185    }
186}
187
188impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsBancontactPreferredLanguage> {
189    fn string(&mut self, s: &str) -> miniserde::Result<()> {
190        use std::str::FromStr;
191        self.out =
192            Some(PaymentMethodOptionsBancontactPreferredLanguage::from_str(s).expect("infallible"));
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsBancontactPreferredLanguage);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsBancontactPreferredLanguage {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Ok(Self::from_str(&s).expect("infallible"))
204    }
205}
206/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
207///
208/// 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.
209/// 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.
210///
211/// 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.
212///
213/// 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).
214#[derive(Clone, Eq, PartialEq)]
215#[non_exhaustive]
216pub enum PaymentMethodOptionsBancontactSetupFutureUsage {
217    None,
218    OffSession,
219    /// An unrecognized value from Stripe. Should not be used as a request parameter.
220    Unknown(String),
221}
222impl PaymentMethodOptionsBancontactSetupFutureUsage {
223    pub fn as_str(&self) -> &str {
224        use PaymentMethodOptionsBancontactSetupFutureUsage::*;
225        match self {
226            None => "none",
227            OffSession => "off_session",
228            Unknown(v) => v,
229        }
230    }
231}
232
233impl std::str::FromStr for PaymentMethodOptionsBancontactSetupFutureUsage {
234    type Err = std::convert::Infallible;
235    fn from_str(s: &str) -> Result<Self, Self::Err> {
236        use PaymentMethodOptionsBancontactSetupFutureUsage::*;
237        match s {
238            "none" => Ok(None),
239            "off_session" => Ok(OffSession),
240            v => {
241                tracing::warn!(
242                    "Unknown value '{}' for enum '{}'",
243                    v,
244                    "PaymentMethodOptionsBancontactSetupFutureUsage"
245                );
246                Ok(Unknown(v.to_owned()))
247            }
248        }
249    }
250}
251impl std::fmt::Display for PaymentMethodOptionsBancontactSetupFutureUsage {
252    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
253        f.write_str(self.as_str())
254    }
255}
256
257impl std::fmt::Debug for PaymentMethodOptionsBancontactSetupFutureUsage {
258    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259        f.write_str(self.as_str())
260    }
261}
262#[cfg(feature = "serialize")]
263impl serde::Serialize for PaymentMethodOptionsBancontactSetupFutureUsage {
264    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
265    where
266        S: serde::Serializer,
267    {
268        serializer.serialize_str(self.as_str())
269    }
270}
271impl miniserde::Deserialize for PaymentMethodOptionsBancontactSetupFutureUsage {
272    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
273        crate::Place::new(out)
274    }
275}
276
277impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsBancontactSetupFutureUsage> {
278    fn string(&mut self, s: &str) -> miniserde::Result<()> {
279        use std::str::FromStr;
280        self.out =
281            Some(PaymentMethodOptionsBancontactSetupFutureUsage::from_str(s).expect("infallible"));
282        Ok(())
283    }
284}
285
286stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsBancontactSetupFutureUsage);
287#[cfg(feature = "deserialize")]
288impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsBancontactSetupFutureUsage {
289    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
290        use std::str::FromStr;
291        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
292        Ok(Self::from_str(&s).expect("infallible"))
293    }
294}