stripe_shared/
payment_links_resource_payment_intent_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourcePaymentIntentData {
5    /// Indicates when the funds will be captured from the customer's account.
6    pub capture_method: Option<PaymentLinksResourcePaymentIntentDataCaptureMethod>,
7    /// An arbitrary string attached to the object. Often useful for displaying to users.
8    pub description: Option<String>,
9    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that will set metadata on [Payment Intents](https://stripe.com/docs/api/payment_intents) generated from this payment link.
10    pub metadata: std::collections::HashMap<String, String>,
11    /// Indicates that you intend to make future payments with the payment method collected during checkout.
12    pub setup_future_usage: Option<PaymentLinksResourcePaymentIntentDataSetupFutureUsage>,
13    /// For a non-card payment, information about the charge that appears on the customer's statement when this payment succeeds in creating a charge.
14    pub statement_descriptor: Option<String>,
15    /// For a card payment, information about the charge that appears on the customer's statement when this payment succeeds in creating a charge.
16    /// Concatenated with the account's statement descriptor prefix to form the complete statement descriptor.
17    pub statement_descriptor_suffix: Option<String>,
18    /// A string that identifies the resulting payment as part of a group.
19    /// See the PaymentIntents [use case for connected accounts](https://stripe.com/docs/connect/separate-charges-and-transfers) for details.
20    pub transfer_group: Option<String>,
21}
22#[doc(hidden)]
23pub struct PaymentLinksResourcePaymentIntentDataBuilder {
24    capture_method: Option<Option<PaymentLinksResourcePaymentIntentDataCaptureMethod>>,
25    description: Option<Option<String>>,
26    metadata: Option<std::collections::HashMap<String, String>>,
27    setup_future_usage: Option<Option<PaymentLinksResourcePaymentIntentDataSetupFutureUsage>>,
28    statement_descriptor: Option<Option<String>>,
29    statement_descriptor_suffix: Option<Option<String>>,
30    transfer_group: Option<Option<String>>,
31}
32
33#[allow(
34    unused_variables,
35    irrefutable_let_patterns,
36    clippy::let_unit_value,
37    clippy::match_single_binding,
38    clippy::single_match
39)]
40const _: () = {
41    use miniserde::de::{Map, Visitor};
42    use miniserde::json::Value;
43    use miniserde::{Deserialize, Result, make_place};
44    use stripe_types::miniserde_helpers::FromValueOpt;
45    use stripe_types::{MapBuilder, ObjectDeser};
46
47    make_place!(Place);
48
49    impl Deserialize for PaymentLinksResourcePaymentIntentData {
50        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
51            Place::new(out)
52        }
53    }
54
55    struct Builder<'a> {
56        out: &'a mut Option<PaymentLinksResourcePaymentIntentData>,
57        builder: PaymentLinksResourcePaymentIntentDataBuilder,
58    }
59
60    impl Visitor for Place<PaymentLinksResourcePaymentIntentData> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder: PaymentLinksResourcePaymentIntentDataBuilder::deser_default(),
65            }))
66        }
67    }
68
69    impl MapBuilder for PaymentLinksResourcePaymentIntentDataBuilder {
70        type Out = PaymentLinksResourcePaymentIntentData;
71        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
72            Ok(match k {
73                "capture_method" => Deserialize::begin(&mut self.capture_method),
74                "description" => Deserialize::begin(&mut self.description),
75                "metadata" => Deserialize::begin(&mut self.metadata),
76                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
77                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
78                "statement_descriptor_suffix" => {
79                    Deserialize::begin(&mut self.statement_descriptor_suffix)
80                }
81                "transfer_group" => Deserialize::begin(&mut self.transfer_group),
82                _ => <dyn Visitor>::ignore(),
83            })
84        }
85
86        fn deser_default() -> Self {
87            Self {
88                capture_method: Deserialize::default(),
89                description: Deserialize::default(),
90                metadata: Deserialize::default(),
91                setup_future_usage: Deserialize::default(),
92                statement_descriptor: Deserialize::default(),
93                statement_descriptor_suffix: Deserialize::default(),
94                transfer_group: Deserialize::default(),
95            }
96        }
97
98        fn take_out(&mut self) -> Option<Self::Out> {
99            let (
100                Some(capture_method),
101                Some(description),
102                Some(metadata),
103                Some(setup_future_usage),
104                Some(statement_descriptor),
105                Some(statement_descriptor_suffix),
106                Some(transfer_group),
107            ) = (
108                self.capture_method.take(),
109                self.description.take(),
110                self.metadata.take(),
111                self.setup_future_usage.take(),
112                self.statement_descriptor.take(),
113                self.statement_descriptor_suffix.take(),
114                self.transfer_group.take(),
115            )
116            else {
117                return None;
118            };
119            Some(Self::Out {
120                capture_method,
121                description,
122                metadata,
123                setup_future_usage,
124                statement_descriptor,
125                statement_descriptor_suffix,
126                transfer_group,
127            })
128        }
129    }
130
131    impl Map for Builder<'_> {
132        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
133            self.builder.key(k)
134        }
135
136        fn finish(&mut self) -> Result<()> {
137            *self.out = self.builder.take_out();
138            Ok(())
139        }
140    }
141
142    impl ObjectDeser for PaymentLinksResourcePaymentIntentData {
143        type Builder = PaymentLinksResourcePaymentIntentDataBuilder;
144    }
145
146    impl FromValueOpt for PaymentLinksResourcePaymentIntentData {
147        fn from_value(v: Value) -> Option<Self> {
148            let Value::Object(obj) = v else {
149                return None;
150            };
151            let mut b = PaymentLinksResourcePaymentIntentDataBuilder::deser_default();
152            for (k, v) in obj {
153                match k.as_str() {
154                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
155                    "description" => b.description = FromValueOpt::from_value(v),
156                    "metadata" => b.metadata = FromValueOpt::from_value(v),
157                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
158                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
159                    "statement_descriptor_suffix" => {
160                        b.statement_descriptor_suffix = FromValueOpt::from_value(v)
161                    }
162                    "transfer_group" => b.transfer_group = FromValueOpt::from_value(v),
163                    _ => {}
164                }
165            }
166            b.take_out()
167        }
168    }
169};
170/// Indicates when the funds will be captured from the customer's account.
171#[derive(Clone, Eq, PartialEq)]
172#[non_exhaustive]
173pub enum PaymentLinksResourcePaymentIntentDataCaptureMethod {
174    Automatic,
175    AutomaticAsync,
176    Manual,
177    /// An unrecognized value from Stripe. Should not be used as a request parameter.
178    Unknown(String),
179}
180impl PaymentLinksResourcePaymentIntentDataCaptureMethod {
181    pub fn as_str(&self) -> &str {
182        use PaymentLinksResourcePaymentIntentDataCaptureMethod::*;
183        match self {
184            Automatic => "automatic",
185            AutomaticAsync => "automatic_async",
186            Manual => "manual",
187            Unknown(v) => v,
188        }
189    }
190}
191
192impl std::str::FromStr for PaymentLinksResourcePaymentIntentDataCaptureMethod {
193    type Err = std::convert::Infallible;
194    fn from_str(s: &str) -> Result<Self, Self::Err> {
195        use PaymentLinksResourcePaymentIntentDataCaptureMethod::*;
196        match s {
197            "automatic" => Ok(Automatic),
198            "automatic_async" => Ok(AutomaticAsync),
199            "manual" => Ok(Manual),
200            v => {
201                tracing::warn!(
202                    "Unknown value '{}' for enum '{}'",
203                    v,
204                    "PaymentLinksResourcePaymentIntentDataCaptureMethod"
205                );
206                Ok(Unknown(v.to_owned()))
207            }
208        }
209    }
210}
211impl std::fmt::Display for PaymentLinksResourcePaymentIntentDataCaptureMethod {
212    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
213        f.write_str(self.as_str())
214    }
215}
216
217impl std::fmt::Debug for PaymentLinksResourcePaymentIntentDataCaptureMethod {
218    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
219        f.write_str(self.as_str())
220    }
221}
222#[cfg(feature = "serialize")]
223impl serde::Serialize for PaymentLinksResourcePaymentIntentDataCaptureMethod {
224    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
225    where
226        S: serde::Serializer,
227    {
228        serializer.serialize_str(self.as_str())
229    }
230}
231impl miniserde::Deserialize for PaymentLinksResourcePaymentIntentDataCaptureMethod {
232    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
233        crate::Place::new(out)
234    }
235}
236
237impl miniserde::de::Visitor for crate::Place<PaymentLinksResourcePaymentIntentDataCaptureMethod> {
238    fn string(&mut self, s: &str) -> miniserde::Result<()> {
239        use std::str::FromStr;
240        self.out = Some(
241            PaymentLinksResourcePaymentIntentDataCaptureMethod::from_str(s).expect("infallible"),
242        );
243        Ok(())
244    }
245}
246
247stripe_types::impl_from_val_with_from_str!(PaymentLinksResourcePaymentIntentDataCaptureMethod);
248#[cfg(feature = "deserialize")]
249impl<'de> serde::Deserialize<'de> for PaymentLinksResourcePaymentIntentDataCaptureMethod {
250    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
251        use std::str::FromStr;
252        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
253        Ok(Self::from_str(&s).expect("infallible"))
254    }
255}
256/// Indicates that you intend to make future payments with the payment method collected during checkout.
257#[derive(Clone, Eq, PartialEq)]
258#[non_exhaustive]
259pub enum PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
260    OffSession,
261    OnSession,
262    /// An unrecognized value from Stripe. Should not be used as a request parameter.
263    Unknown(String),
264}
265impl PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
266    pub fn as_str(&self) -> &str {
267        use PaymentLinksResourcePaymentIntentDataSetupFutureUsage::*;
268        match self {
269            OffSession => "off_session",
270            OnSession => "on_session",
271            Unknown(v) => v,
272        }
273    }
274}
275
276impl std::str::FromStr for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
277    type Err = std::convert::Infallible;
278    fn from_str(s: &str) -> Result<Self, Self::Err> {
279        use PaymentLinksResourcePaymentIntentDataSetupFutureUsage::*;
280        match s {
281            "off_session" => Ok(OffSession),
282            "on_session" => Ok(OnSession),
283            v => {
284                tracing::warn!(
285                    "Unknown value '{}' for enum '{}'",
286                    v,
287                    "PaymentLinksResourcePaymentIntentDataSetupFutureUsage"
288                );
289                Ok(Unknown(v.to_owned()))
290            }
291        }
292    }
293}
294impl std::fmt::Display for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
295    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
296        f.write_str(self.as_str())
297    }
298}
299
300impl std::fmt::Debug for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
301    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
302        f.write_str(self.as_str())
303    }
304}
305#[cfg(feature = "serialize")]
306impl serde::Serialize for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
307    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
308    where
309        S: serde::Serializer,
310    {
311        serializer.serialize_str(self.as_str())
312    }
313}
314impl miniserde::Deserialize for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
315    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
316        crate::Place::new(out)
317    }
318}
319
320impl miniserde::de::Visitor
321    for crate::Place<PaymentLinksResourcePaymentIntentDataSetupFutureUsage>
322{
323    fn string(&mut self, s: &str) -> miniserde::Result<()> {
324        use std::str::FromStr;
325        self.out = Some(
326            PaymentLinksResourcePaymentIntentDataSetupFutureUsage::from_str(s).expect("infallible"),
327        );
328        Ok(())
329    }
330}
331
332stripe_types::impl_from_val_with_from_str!(PaymentLinksResourcePaymentIntentDataSetupFutureUsage);
333#[cfg(feature = "deserialize")]
334impl<'de> serde::Deserialize<'de> for PaymentLinksResourcePaymentIntentDataSetupFutureUsage {
335    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
336        use std::str::FromStr;
337        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
338        Ok(Self::from_str(&s).expect("infallible"))
339    }
340}