stripe_shared/
checkout_boleto_payment_method_options.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutBoletoPaymentMethodOptions {
5    /// The number of calendar days before a Boleto voucher expires.
6    /// For example, if you create a Boleto voucher on Monday and you set expires_after_days to 2, the Boleto voucher will expire on Wednesday at 23:59 America/Sao_Paulo time.
7    pub expires_after_days: u32,
8    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
9    ///
10    /// 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.
11    /// 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.
12    ///
13    /// 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.
14    ///
15    /// 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).
16    pub setup_future_usage: Option<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage>,
17}
18#[doc(hidden)]
19pub struct CheckoutBoletoPaymentMethodOptionsBuilder {
20    expires_after_days: Option<u32>,
21    setup_future_usage: Option<Option<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage>>,
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::{make_place, Deserialize, Result};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for CheckoutBoletoPaymentMethodOptions {
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<CheckoutBoletoPaymentMethodOptions>,
48        builder: CheckoutBoletoPaymentMethodOptionsBuilder,
49    }
50
51    impl Visitor for Place<CheckoutBoletoPaymentMethodOptions> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: CheckoutBoletoPaymentMethodOptionsBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for CheckoutBoletoPaymentMethodOptionsBuilder {
61        type Out = CheckoutBoletoPaymentMethodOptions;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "expires_after_days" => Deserialize::begin(&mut self.expires_after_days),
65                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
66
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                expires_after_days: Deserialize::default(),
74                setup_future_usage: Deserialize::default(),
75            }
76        }
77
78        fn take_out(&mut self) -> Option<Self::Out> {
79            let (Some(expires_after_days), Some(setup_future_usage)) =
80                (self.expires_after_days, self.setup_future_usage)
81            else {
82                return None;
83            };
84            Some(Self::Out { expires_after_days, setup_future_usage })
85        }
86    }
87
88    impl<'a> Map for Builder<'a> {
89        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
90            self.builder.key(k)
91        }
92
93        fn finish(&mut self) -> Result<()> {
94            *self.out = self.builder.take_out();
95            Ok(())
96        }
97    }
98
99    impl ObjectDeser for CheckoutBoletoPaymentMethodOptions {
100        type Builder = CheckoutBoletoPaymentMethodOptionsBuilder;
101    }
102
103    impl FromValueOpt for CheckoutBoletoPaymentMethodOptions {
104        fn from_value(v: Value) -> Option<Self> {
105            let Value::Object(obj) = v else {
106                return None;
107            };
108            let mut b = CheckoutBoletoPaymentMethodOptionsBuilder::deser_default();
109            for (k, v) in obj {
110                match k.as_str() {
111                    "expires_after_days" => b.expires_after_days = FromValueOpt::from_value(v),
112                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
113
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
122///
123/// 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.
124/// 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.
125///
126/// 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.
127///
128/// 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).
129#[derive(Copy, Clone, Eq, PartialEq)]
130pub enum CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
131    None,
132    OffSession,
133    OnSession,
134}
135impl CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
136    pub fn as_str(self) -> &'static str {
137        use CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::*;
138        match self {
139            None => "none",
140            OffSession => "off_session",
141            OnSession => "on_session",
142        }
143    }
144}
145
146impl std::str::FromStr for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
147    type Err = stripe_types::StripeParseError;
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        use CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::*;
150        match s {
151            "none" => Ok(None),
152            "off_session" => Ok(OffSession),
153            "on_session" => Ok(OnSession),
154            _ => Err(stripe_types::StripeParseError),
155        }
156    }
157}
158impl std::fmt::Display for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160        f.write_str(self.as_str())
161    }
162}
163
164impl std::fmt::Debug for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169#[cfg(feature = "serialize")]
170impl serde::Serialize for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
171    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
172    where
173        S: serde::Serializer,
174    {
175        serializer.serialize_str(self.as_str())
176    }
177}
178impl miniserde::Deserialize for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
179    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
180        crate::Place::new(out)
181    }
182}
183
184impl miniserde::de::Visitor for crate::Place<CheckoutBoletoPaymentMethodOptionsSetupFutureUsage> {
185    fn string(&mut self, s: &str) -> miniserde::Result<()> {
186        use std::str::FromStr;
187        self.out = Some(
188            CheckoutBoletoPaymentMethodOptionsSetupFutureUsage::from_str(s)
189                .map_err(|_| miniserde::Error)?,
190        );
191        Ok(())
192    }
193}
194
195stripe_types::impl_from_val_with_from_str!(CheckoutBoletoPaymentMethodOptionsSetupFutureUsage);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Self::from_str(&s).map_err(|_| {
202            serde::de::Error::custom(
203                "Unknown value for CheckoutBoletoPaymentMethodOptionsSetupFutureUsage",
204            )
205        })
206    }
207}