stripe_shared/
payment_method_options_sofort.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsSofort {
5    /// Preferred language of the SOFORT authorization page that the customer is redirected to.
6    pub preferred_language: Option<PaymentMethodOptionsSofortPreferredLanguage>,
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<PaymentMethodOptionsSofortSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentMethodOptionsSofortBuilder {
19    preferred_language: Option<Option<PaymentMethodOptionsSofortPreferredLanguage>>,
20    setup_future_usage: Option<Option<PaymentMethodOptionsSofortSetupFutureUsage>>,
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::{make_place, Deserialize, Result};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for PaymentMethodOptionsSofort {
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<PaymentMethodOptionsSofort>,
47        builder: PaymentMethodOptionsSofortBuilder,
48    }
49
50    impl Visitor for Place<PaymentMethodOptionsSofort> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: PaymentMethodOptionsSofortBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for PaymentMethodOptionsSofortBuilder {
60        type Out = PaymentMethodOptionsSofort;
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
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self {
72                preferred_language: Deserialize::default(),
73                setup_future_usage: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(preferred_language), Some(setup_future_usage)) =
79                (self.preferred_language, self.setup_future_usage)
80            else {
81                return None;
82            };
83            Some(Self::Out { preferred_language, setup_future_usage })
84        }
85    }
86
87    impl<'a> Map for Builder<'a> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for PaymentMethodOptionsSofort {
99        type Builder = PaymentMethodOptionsSofortBuilder;
100    }
101
102    impl FromValueOpt for PaymentMethodOptionsSofort {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentMethodOptionsSofortBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "preferred_language" => b.preferred_language = FromValueOpt::from_value(v),
111                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
112
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};
120/// Preferred language of the SOFORT authorization page that the customer is redirected to.
121#[derive(Copy, Clone, Eq, PartialEq)]
122pub enum PaymentMethodOptionsSofortPreferredLanguage {
123    De,
124    En,
125    Es,
126    Fr,
127    It,
128    Nl,
129    Pl,
130}
131impl PaymentMethodOptionsSofortPreferredLanguage {
132    pub fn as_str(self) -> &'static str {
133        use PaymentMethodOptionsSofortPreferredLanguage::*;
134        match self {
135            De => "de",
136            En => "en",
137            Es => "es",
138            Fr => "fr",
139            It => "it",
140            Nl => "nl",
141            Pl => "pl",
142        }
143    }
144}
145
146impl std::str::FromStr for PaymentMethodOptionsSofortPreferredLanguage {
147    type Err = stripe_types::StripeParseError;
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        use PaymentMethodOptionsSofortPreferredLanguage::*;
150        match s {
151            "de" => Ok(De),
152            "en" => Ok(En),
153            "es" => Ok(Es),
154            "fr" => Ok(Fr),
155            "it" => Ok(It),
156            "nl" => Ok(Nl),
157            "pl" => Ok(Pl),
158            _ => Err(stripe_types::StripeParseError),
159        }
160    }
161}
162impl std::fmt::Display for PaymentMethodOptionsSofortPreferredLanguage {
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 PaymentMethodOptionsSofortPreferredLanguage {
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 PaymentMethodOptionsSofortPreferredLanguage {
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 PaymentMethodOptionsSofortPreferredLanguage {
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<PaymentMethodOptionsSofortPreferredLanguage> {
189    fn string(&mut self, s: &str) -> miniserde::Result<()> {
190        use std::str::FromStr;
191        self.out = Some(
192            PaymentMethodOptionsSofortPreferredLanguage::from_str(s)
193                .map_err(|_| miniserde::Error)?,
194        );
195        Ok(())
196    }
197}
198
199stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsSofortPreferredLanguage);
200#[cfg(feature = "deserialize")]
201impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsSofortPreferredLanguage {
202    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
203        use std::str::FromStr;
204        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
205        Self::from_str(&s).map_err(|_| {
206            serde::de::Error::custom(
207                "Unknown value for PaymentMethodOptionsSofortPreferredLanguage",
208            )
209        })
210    }
211}
212/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
213///
214/// 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.
215/// 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.
216///
217/// 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.
218///
219/// 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).
220#[derive(Copy, Clone, Eq, PartialEq)]
221pub enum PaymentMethodOptionsSofortSetupFutureUsage {
222    None,
223    OffSession,
224}
225impl PaymentMethodOptionsSofortSetupFutureUsage {
226    pub fn as_str(self) -> &'static str {
227        use PaymentMethodOptionsSofortSetupFutureUsage::*;
228        match self {
229            None => "none",
230            OffSession => "off_session",
231        }
232    }
233}
234
235impl std::str::FromStr for PaymentMethodOptionsSofortSetupFutureUsage {
236    type Err = stripe_types::StripeParseError;
237    fn from_str(s: &str) -> Result<Self, Self::Err> {
238        use PaymentMethodOptionsSofortSetupFutureUsage::*;
239        match s {
240            "none" => Ok(None),
241            "off_session" => Ok(OffSession),
242            _ => Err(stripe_types::StripeParseError),
243        }
244    }
245}
246impl std::fmt::Display for PaymentMethodOptionsSofortSetupFutureUsage {
247    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
248        f.write_str(self.as_str())
249    }
250}
251
252impl std::fmt::Debug for PaymentMethodOptionsSofortSetupFutureUsage {
253    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
254        f.write_str(self.as_str())
255    }
256}
257#[cfg(feature = "serialize")]
258impl serde::Serialize for PaymentMethodOptionsSofortSetupFutureUsage {
259    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
260    where
261        S: serde::Serializer,
262    {
263        serializer.serialize_str(self.as_str())
264    }
265}
266impl miniserde::Deserialize for PaymentMethodOptionsSofortSetupFutureUsage {
267    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
268        crate::Place::new(out)
269    }
270}
271
272impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsSofortSetupFutureUsage> {
273    fn string(&mut self, s: &str) -> miniserde::Result<()> {
274        use std::str::FromStr;
275        self.out = Some(
276            PaymentMethodOptionsSofortSetupFutureUsage::from_str(s)
277                .map_err(|_| miniserde::Error)?,
278        );
279        Ok(())
280    }
281}
282
283stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsSofortSetupFutureUsage);
284#[cfg(feature = "deserialize")]
285impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsSofortSetupFutureUsage {
286    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
287        use std::str::FromStr;
288        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
289        Self::from_str(&s).map_err(|_| {
290            serde::de::Error::custom("Unknown value for PaymentMethodOptionsSofortSetupFutureUsage")
291        })
292    }
293}