stripe_shared/
checkout_paypal_payment_method_options.rs

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