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