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::{make_place, Deserialize, Result};
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
75                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self {
81                capture_method: Deserialize::default(),
82                preferred_locale: Deserialize::default(),
83                reference: Deserialize::default(),
84                setup_future_usage: Deserialize::default(),
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (
90                Some(capture_method),
91                Some(preferred_locale),
92                Some(reference),
93                Some(setup_future_usage),
94            ) = (
95                self.capture_method,
96                self.preferred_locale.take(),
97                self.reference.take(),
98                self.setup_future_usage,
99            )
100            else {
101                return None;
102            };
103            Some(Self::Out { capture_method, preferred_locale, reference, setup_future_usage })
104        }
105    }
106
107    impl<'a> Map for Builder<'a> {
108        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
109            self.builder.key(k)
110        }
111
112        fn finish(&mut self) -> Result<()> {
113            *self.out = self.builder.take_out();
114            Ok(())
115        }
116    }
117
118    impl ObjectDeser for CheckoutPaypalPaymentMethodOptions {
119        type Builder = CheckoutPaypalPaymentMethodOptionsBuilder;
120    }
121
122    impl FromValueOpt for CheckoutPaypalPaymentMethodOptions {
123        fn from_value(v: Value) -> Option<Self> {
124            let Value::Object(obj) = v else {
125                return None;
126            };
127            let mut b = CheckoutPaypalPaymentMethodOptionsBuilder::deser_default();
128            for (k, v) in obj {
129                match k.as_str() {
130                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
131                    "preferred_locale" => b.preferred_locale = FromValueOpt::from_value(v),
132                    "reference" => b.reference = FromValueOpt::from_value(v),
133                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
134
135                    _ => {}
136                }
137            }
138            b.take_out()
139        }
140    }
141};
142/// Controls when the funds will be captured from the customer's account.
143#[derive(Copy, Clone, Eq, PartialEq)]
144pub enum CheckoutPaypalPaymentMethodOptionsCaptureMethod {
145    Manual,
146}
147impl CheckoutPaypalPaymentMethodOptionsCaptureMethod {
148    pub fn as_str(self) -> &'static str {
149        use CheckoutPaypalPaymentMethodOptionsCaptureMethod::*;
150        match self {
151            Manual => "manual",
152        }
153    }
154}
155
156impl std::str::FromStr for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
157    type Err = stripe_types::StripeParseError;
158    fn from_str(s: &str) -> Result<Self, Self::Err> {
159        use CheckoutPaypalPaymentMethodOptionsCaptureMethod::*;
160        match s {
161            "manual" => Ok(Manual),
162            _ => Err(stripe_types::StripeParseError),
163        }
164    }
165}
166impl std::fmt::Display for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171
172impl std::fmt::Debug for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177#[cfg(feature = "serialize")]
178impl serde::Serialize for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
179    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
180    where
181        S: serde::Serializer,
182    {
183        serializer.serialize_str(self.as_str())
184    }
185}
186impl miniserde::Deserialize for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
187    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
188        crate::Place::new(out)
189    }
190}
191
192impl miniserde::de::Visitor for crate::Place<CheckoutPaypalPaymentMethodOptionsCaptureMethod> {
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out = Some(
196            CheckoutPaypalPaymentMethodOptionsCaptureMethod::from_str(s)
197                .map_err(|_| miniserde::Error)?,
198        );
199        Ok(())
200    }
201}
202
203stripe_types::impl_from_val_with_from_str!(CheckoutPaypalPaymentMethodOptionsCaptureMethod);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for CheckoutPaypalPaymentMethodOptionsCaptureMethod {
206    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207        use std::str::FromStr;
208        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
209        Self::from_str(&s).map_err(|_| {
210            serde::de::Error::custom(
211                "Unknown value for CheckoutPaypalPaymentMethodOptionsCaptureMethod",
212            )
213        })
214    }
215}
216/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
217///
218/// 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.
219/// 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.
220///
221/// 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.
222///
223/// 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).
224#[derive(Copy, Clone, Eq, PartialEq)]
225pub enum CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
226    None,
227    OffSession,
228}
229impl CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
230    pub fn as_str(self) -> &'static str {
231        use CheckoutPaypalPaymentMethodOptionsSetupFutureUsage::*;
232        match self {
233            None => "none",
234            OffSession => "off_session",
235        }
236    }
237}
238
239impl std::str::FromStr for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
240    type Err = stripe_types::StripeParseError;
241    fn from_str(s: &str) -> Result<Self, Self::Err> {
242        use CheckoutPaypalPaymentMethodOptionsSetupFutureUsage::*;
243        match s {
244            "none" => Ok(None),
245            "off_session" => Ok(OffSession),
246            _ => Err(stripe_types::StripeParseError),
247        }
248    }
249}
250impl std::fmt::Display for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
251    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
252        f.write_str(self.as_str())
253    }
254}
255
256impl std::fmt::Debug for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
257    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
258        f.write_str(self.as_str())
259    }
260}
261#[cfg(feature = "serialize")]
262impl serde::Serialize for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
263    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
264    where
265        S: serde::Serializer,
266    {
267        serializer.serialize_str(self.as_str())
268    }
269}
270impl miniserde::Deserialize for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
271    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
272        crate::Place::new(out)
273    }
274}
275
276impl miniserde::de::Visitor for crate::Place<CheckoutPaypalPaymentMethodOptionsSetupFutureUsage> {
277    fn string(&mut self, s: &str) -> miniserde::Result<()> {
278        use std::str::FromStr;
279        self.out = Some(
280            CheckoutPaypalPaymentMethodOptionsSetupFutureUsage::from_str(s)
281                .map_err(|_| miniserde::Error)?,
282        );
283        Ok(())
284    }
285}
286
287stripe_types::impl_from_val_with_from_str!(CheckoutPaypalPaymentMethodOptionsSetupFutureUsage);
288#[cfg(feature = "deserialize")]
289impl<'de> serde::Deserialize<'de> for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage {
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        Self::from_str(&s).map_err(|_| {
294            serde::de::Error::custom(
295                "Unknown value for CheckoutPaypalPaymentMethodOptionsSetupFutureUsage",
296            )
297        })
298    }
299}