stripe_shared/
payment_intent_payment_method_options_payto.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsPayto {
5    pub mandate_options:
6        Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsPayto>,
7    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
8    ///
9    /// 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.
10    /// 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.
11    ///
12    /// 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.
13    ///
14    /// 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).
15    pub setup_future_usage: Option<PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentIntentPaymentMethodOptionsPaytoBuilder {
19    mandate_options:
20        Option<Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsPayto>>,
21    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage>>,
22}
23
24#[allow(
25    unused_variables,
26    irrefutable_let_patterns,
27    clippy::let_unit_value,
28    clippy::match_single_binding,
29    clippy::single_match
30)]
31const _: () = {
32    use miniserde::de::{Map, Visitor};
33    use miniserde::json::Value;
34    use miniserde::{Deserialize, Result, make_place};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for PaymentIntentPaymentMethodOptionsPayto {
41        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42            Place::new(out)
43        }
44    }
45
46    struct Builder<'a> {
47        out: &'a mut Option<PaymentIntentPaymentMethodOptionsPayto>,
48        builder: PaymentIntentPaymentMethodOptionsPaytoBuilder,
49    }
50
51    impl Visitor for Place<PaymentIntentPaymentMethodOptionsPayto> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: PaymentIntentPaymentMethodOptionsPaytoBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for PaymentIntentPaymentMethodOptionsPaytoBuilder {
61        type Out = PaymentIntentPaymentMethodOptionsPayto;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
65                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self {
72                mandate_options: Deserialize::default(),
73                setup_future_usage: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(mandate_options), Some(setup_future_usage)) =
79                (self.mandate_options.take(), self.setup_future_usage.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { mandate_options, setup_future_usage })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for PaymentIntentPaymentMethodOptionsPayto {
99        type Builder = PaymentIntentPaymentMethodOptionsPaytoBuilder;
100    }
101
102    impl FromValueOpt for PaymentIntentPaymentMethodOptionsPayto {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentIntentPaymentMethodOptionsPaytoBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
111                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
120///
121/// 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.
122/// 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.
123///
124/// 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.
125///
126/// 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).
127#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
130    None,
131    OffSession,
132    /// An unrecognized value from Stripe. Should not be used as a request parameter.
133    Unknown(String),
134}
135impl PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
136    pub fn as_str(&self) -> &str {
137        use PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage::*;
138        match self {
139            None => "none",
140            OffSession => "off_session",
141            Unknown(v) => v,
142        }
143    }
144}
145
146impl std::str::FromStr for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
147    type Err = std::convert::Infallible;
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        use PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage::*;
150        match s {
151            "none" => Ok(None),
152            "off_session" => Ok(OffSession),
153            v => {
154                tracing::warn!(
155                    "Unknown value '{}' for enum '{}'",
156                    v,
157                    "PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage"
158                );
159                Ok(Unknown(v.to_owned()))
160            }
161        }
162    }
163}
164impl std::fmt::Display for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169
170impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
178    where
179        S: serde::Serializer,
180    {
181        serializer.serialize_str(self.as_str())
182    }
183}
184impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
185    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
186        crate::Place::new(out)
187    }
188}
189
190impl miniserde::de::Visitor
191    for crate::Place<PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage>
192{
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out = Some(
196            PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage::from_str(s)
197                .expect("infallible"),
198        );
199        Ok(())
200    }
201}
202
203stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsPaytoSetupFutureUsage {
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        Ok(Self::from_str(&s).expect("infallible"))
210    }
211}