Skip to main content

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