Skip to main content

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