stripe_shared/
payment_method_options_klarna.rs

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