stripe_shared/
payment_method_options_paypal.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsPaypal {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<PaymentMethodOptionsPaypalCaptureMethod>,
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<PaymentMethodOptionsPaypalSetupFutureUsage>,
21}
22#[doc(hidden)]
23pub struct PaymentMethodOptionsPaypalBuilder {
24    capture_method: Option<Option<PaymentMethodOptionsPaypalCaptureMethod>>,
25    preferred_locale: Option<Option<String>>,
26    reference: Option<Option<String>>,
27    setup_future_usage: Option<Option<PaymentMethodOptionsPaypalSetupFutureUsage>>,
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 PaymentMethodOptionsPaypal {
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<PaymentMethodOptionsPaypal>,
54        builder: PaymentMethodOptionsPaypalBuilder,
55    }
56
57    impl Visitor for Place<PaymentMethodOptionsPaypal> {
58        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59            Ok(Box::new(Builder {
60                out: &mut self.out,
61                builder: PaymentMethodOptionsPaypalBuilder::deser_default(),
62            }))
63        }
64    }
65
66    impl MapBuilder for PaymentMethodOptionsPaypalBuilder {
67        type Out = PaymentMethodOptionsPaypal;
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 PaymentMethodOptionsPaypal {
119        type Builder = PaymentMethodOptionsPaypalBuilder;
120    }
121
122    impl FromValueOpt for PaymentMethodOptionsPaypal {
123        fn from_value(v: Value) -> Option<Self> {
124            let Value::Object(obj) = v else {
125                return None;
126            };
127            let mut b = PaymentMethodOptionsPaypalBuilder::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 PaymentMethodOptionsPaypalCaptureMethod {
145    Manual,
146}
147impl PaymentMethodOptionsPaypalCaptureMethod {
148    pub fn as_str(self) -> &'static str {
149        use PaymentMethodOptionsPaypalCaptureMethod::*;
150        match self {
151            Manual => "manual",
152        }
153    }
154}
155
156impl std::str::FromStr for PaymentMethodOptionsPaypalCaptureMethod {
157    type Err = stripe_types::StripeParseError;
158    fn from_str(s: &str) -> Result<Self, Self::Err> {
159        use PaymentMethodOptionsPaypalCaptureMethod::*;
160        match s {
161            "manual" => Ok(Manual),
162            _ => Err(stripe_types::StripeParseError),
163        }
164    }
165}
166impl std::fmt::Display for PaymentMethodOptionsPaypalCaptureMethod {
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 PaymentMethodOptionsPaypalCaptureMethod {
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 PaymentMethodOptionsPaypalCaptureMethod {
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 PaymentMethodOptionsPaypalCaptureMethod {
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<PaymentMethodOptionsPaypalCaptureMethod> {
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out = Some(
196            PaymentMethodOptionsPaypalCaptureMethod::from_str(s).map_err(|_| miniserde::Error)?,
197        );
198        Ok(())
199    }
200}
201
202stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPaypalCaptureMethod);
203#[cfg(feature = "deserialize")]
204impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPaypalCaptureMethod {
205    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
206        use std::str::FromStr;
207        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
208        Self::from_str(&s).map_err(|_| {
209            serde::de::Error::custom("Unknown value for PaymentMethodOptionsPaypalCaptureMethod")
210        })
211    }
212}
213/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
214///
215/// 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.
216/// 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.
217///
218/// 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.
219///
220/// 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).
221#[derive(Copy, Clone, Eq, PartialEq)]
222pub enum PaymentMethodOptionsPaypalSetupFutureUsage {
223    None,
224    OffSession,
225}
226impl PaymentMethodOptionsPaypalSetupFutureUsage {
227    pub fn as_str(self) -> &'static str {
228        use PaymentMethodOptionsPaypalSetupFutureUsage::*;
229        match self {
230            None => "none",
231            OffSession => "off_session",
232        }
233    }
234}
235
236impl std::str::FromStr for PaymentMethodOptionsPaypalSetupFutureUsage {
237    type Err = stripe_types::StripeParseError;
238    fn from_str(s: &str) -> Result<Self, Self::Err> {
239        use PaymentMethodOptionsPaypalSetupFutureUsage::*;
240        match s {
241            "none" => Ok(None),
242            "off_session" => Ok(OffSession),
243            _ => Err(stripe_types::StripeParseError),
244        }
245    }
246}
247impl std::fmt::Display for PaymentMethodOptionsPaypalSetupFutureUsage {
248    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
249        f.write_str(self.as_str())
250    }
251}
252
253impl std::fmt::Debug for PaymentMethodOptionsPaypalSetupFutureUsage {
254    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
255        f.write_str(self.as_str())
256    }
257}
258#[cfg(feature = "serialize")]
259impl serde::Serialize for PaymentMethodOptionsPaypalSetupFutureUsage {
260    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
261    where
262        S: serde::Serializer,
263    {
264        serializer.serialize_str(self.as_str())
265    }
266}
267impl miniserde::Deserialize for PaymentMethodOptionsPaypalSetupFutureUsage {
268    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
269        crate::Place::new(out)
270    }
271}
272
273impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPaypalSetupFutureUsage> {
274    fn string(&mut self, s: &str) -> miniserde::Result<()> {
275        use std::str::FromStr;
276        self.out = Some(
277            PaymentMethodOptionsPaypalSetupFutureUsage::from_str(s)
278                .map_err(|_| miniserde::Error)?,
279        );
280        Ok(())
281    }
282}
283
284stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPaypalSetupFutureUsage);
285#[cfg(feature = "deserialize")]
286impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPaypalSetupFutureUsage {
287    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
288        use std::str::FromStr;
289        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
290        Self::from_str(&s).map_err(|_| {
291            serde::de::Error::custom("Unknown value for PaymentMethodOptionsPaypalSetupFutureUsage")
292        })
293    }
294}