Skip to main content

stripe_shared/
checkout_customer_balance_payment_method_options.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct CheckoutCustomerBalancePaymentMethodOptions {
6    pub bank_transfer:
7        Option<stripe_shared::CheckoutCustomerBalanceBankTransferPaymentMethodOptions>,
8    /// The funding method type to be used when there are not enough funds in the customer balance.
9    /// Permitted values include: `bank_transfer`.
10    pub funding_type: Option<CheckoutCustomerBalancePaymentMethodOptionsFundingType>,
11    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
12    ///
13    /// 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.
14    /// 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.
15    ///
16    /// 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.
17    ///
18    /// 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).
19    pub setup_future_usage: Option<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>,
20}
21#[cfg(feature = "redact-generated-debug")]
22impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptions {
23    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
24        f.debug_struct("CheckoutCustomerBalancePaymentMethodOptions").finish_non_exhaustive()
25    }
26}
27#[doc(hidden)]
28pub struct CheckoutCustomerBalancePaymentMethodOptionsBuilder {
29    bank_transfer:
30        Option<Option<stripe_shared::CheckoutCustomerBalanceBankTransferPaymentMethodOptions>>,
31    funding_type: Option<Option<CheckoutCustomerBalancePaymentMethodOptionsFundingType>>,
32    setup_future_usage: Option<Option<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>>,
33}
34
35#[allow(
36    unused_variables,
37    irrefutable_let_patterns,
38    clippy::let_unit_value,
39    clippy::match_single_binding,
40    clippy::single_match
41)]
42const _: () = {
43    use miniserde::de::{Map, Visitor};
44    use miniserde::json::Value;
45    use miniserde::{Deserialize, Result, make_place};
46    use stripe_types::miniserde_helpers::FromValueOpt;
47    use stripe_types::{MapBuilder, ObjectDeser};
48
49    make_place!(Place);
50
51    impl Deserialize for CheckoutCustomerBalancePaymentMethodOptions {
52        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
53            Place::new(out)
54        }
55    }
56
57    struct Builder<'a> {
58        out: &'a mut Option<CheckoutCustomerBalancePaymentMethodOptions>,
59        builder: CheckoutCustomerBalancePaymentMethodOptionsBuilder,
60    }
61
62    impl Visitor for Place<CheckoutCustomerBalancePaymentMethodOptions> {
63        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
64            Ok(Box::new(Builder {
65                out: &mut self.out,
66                builder: CheckoutCustomerBalancePaymentMethodOptionsBuilder::deser_default(),
67            }))
68        }
69    }
70
71    impl MapBuilder for CheckoutCustomerBalancePaymentMethodOptionsBuilder {
72        type Out = CheckoutCustomerBalancePaymentMethodOptions;
73        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74            Ok(match k {
75                "bank_transfer" => Deserialize::begin(&mut self.bank_transfer),
76                "funding_type" => Deserialize::begin(&mut self.funding_type),
77                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
78                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                bank_transfer: Some(None),
85                funding_type: Some(None),
86                setup_future_usage: Some(None),
87            }
88        }
89
90        fn take_out(&mut self) -> Option<Self::Out> {
91            let (Some(bank_transfer), Some(funding_type), Some(setup_future_usage)) = (
92                self.bank_transfer.take(),
93                self.funding_type.take(),
94                self.setup_future_usage.take(),
95            ) else {
96                return None;
97            };
98            Some(Self::Out { bank_transfer, funding_type, setup_future_usage })
99        }
100    }
101
102    impl Map for Builder<'_> {
103        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
104            self.builder.key(k)
105        }
106
107        fn finish(&mut self) -> Result<()> {
108            *self.out = self.builder.take_out();
109            Ok(())
110        }
111    }
112
113    impl ObjectDeser for CheckoutCustomerBalancePaymentMethodOptions {
114        type Builder = CheckoutCustomerBalancePaymentMethodOptionsBuilder;
115    }
116
117    impl FromValueOpt for CheckoutCustomerBalancePaymentMethodOptions {
118        fn from_value(v: Value) -> Option<Self> {
119            let Value::Object(obj) = v else {
120                return None;
121            };
122            let mut b = CheckoutCustomerBalancePaymentMethodOptionsBuilder::deser_default();
123            for (k, v) in obj {
124                match k.as_str() {
125                    "bank_transfer" => b.bank_transfer = FromValueOpt::from_value(v),
126                    "funding_type" => b.funding_type = FromValueOpt::from_value(v),
127                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
128                    _ => {}
129                }
130            }
131            b.take_out()
132        }
133    }
134};
135/// The funding method type to be used when there are not enough funds in the customer balance.
136/// Permitted values include: `bank_transfer`.
137#[derive(Clone, Eq, PartialEq)]
138#[non_exhaustive]
139pub enum CheckoutCustomerBalancePaymentMethodOptionsFundingType {
140    BankTransfer,
141    /// An unrecognized value from Stripe. Should not be used as a request parameter.
142    Unknown(String),
143}
144impl CheckoutCustomerBalancePaymentMethodOptionsFundingType {
145    pub fn as_str(&self) -> &str {
146        use CheckoutCustomerBalancePaymentMethodOptionsFundingType::*;
147        match self {
148            BankTransfer => "bank_transfer",
149            Unknown(v) => v,
150        }
151    }
152}
153
154impl std::str::FromStr for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
155    type Err = std::convert::Infallible;
156    fn from_str(s: &str) -> Result<Self, Self::Err> {
157        use CheckoutCustomerBalancePaymentMethodOptionsFundingType::*;
158        match s {
159            "bank_transfer" => Ok(BankTransfer),
160            v => {
161                tracing::warn!(
162                    "Unknown value '{}' for enum '{}'",
163                    v,
164                    "CheckoutCustomerBalancePaymentMethodOptionsFundingType"
165                );
166                Ok(Unknown(v.to_owned()))
167            }
168        }
169    }
170}
171impl std::fmt::Display for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
172    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173        f.write_str(self.as_str())
174    }
175}
176
177#[cfg(not(feature = "redact-generated-debug"))]
178impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183#[cfg(feature = "redact-generated-debug")]
184impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
185    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
186        f.debug_struct(stringify!(CheckoutCustomerBalancePaymentMethodOptionsFundingType))
187            .finish_non_exhaustive()
188    }
189}
190#[cfg(feature = "serialize")]
191impl serde::Serialize for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
192    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
193    where
194        S: serde::Serializer,
195    {
196        serializer.serialize_str(self.as_str())
197    }
198}
199impl miniserde::Deserialize for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
200    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
201        crate::Place::new(out)
202    }
203}
204
205impl miniserde::de::Visitor
206    for crate::Place<CheckoutCustomerBalancePaymentMethodOptionsFundingType>
207{
208    fn string(&mut self, s: &str) -> miniserde::Result<()> {
209        use std::str::FromStr;
210        self.out = Some(
211            CheckoutCustomerBalancePaymentMethodOptionsFundingType::from_str(s)
212                .expect("infallible"),
213        );
214        Ok(())
215    }
216}
217
218stripe_types::impl_from_val_with_from_str!(CheckoutCustomerBalancePaymentMethodOptionsFundingType);
219#[cfg(feature = "deserialize")]
220impl<'de> serde::Deserialize<'de> for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
221    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
222        use std::str::FromStr;
223        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
224        Ok(Self::from_str(&s).expect("infallible"))
225    }
226}
227/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
228///
229/// 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.
230/// 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.
231///
232/// 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.
233///
234/// 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).
235#[derive(Clone, Eq, PartialEq)]
236#[non_exhaustive]
237pub enum CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
238    None,
239    /// An unrecognized value from Stripe. Should not be used as a request parameter.
240    Unknown(String),
241}
242impl CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
243    pub fn as_str(&self) -> &str {
244        use CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::*;
245        match self {
246            None => "none",
247            Unknown(v) => v,
248        }
249    }
250}
251
252impl std::str::FromStr for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
253    type Err = std::convert::Infallible;
254    fn from_str(s: &str) -> Result<Self, Self::Err> {
255        use CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::*;
256        match s {
257            "none" => Ok(None),
258            v => {
259                tracing::warn!(
260                    "Unknown value '{}' for enum '{}'",
261                    v,
262                    "CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage"
263                );
264                Ok(Unknown(v.to_owned()))
265            }
266        }
267    }
268}
269impl std::fmt::Display for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
270    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271        f.write_str(self.as_str())
272    }
273}
274
275#[cfg(not(feature = "redact-generated-debug"))]
276impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
277    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
278        f.write_str(self.as_str())
279    }
280}
281#[cfg(feature = "redact-generated-debug")]
282impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
283    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284        f.debug_struct(stringify!(CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage))
285            .finish_non_exhaustive()
286    }
287}
288#[cfg(feature = "serialize")]
289impl serde::Serialize for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
290    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
291    where
292        S: serde::Serializer,
293    {
294        serializer.serialize_str(self.as_str())
295    }
296}
297impl miniserde::Deserialize for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
298    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
299        crate::Place::new(out)
300    }
301}
302
303impl miniserde::de::Visitor
304    for crate::Place<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>
305{
306    fn string(&mut self, s: &str) -> miniserde::Result<()> {
307        use std::str::FromStr;
308        self.out = Some(
309            CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::from_str(s)
310                .expect("infallible"),
311        );
312        Ok(())
313    }
314}
315
316stripe_types::impl_from_val_with_from_str!(
317    CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage
318);
319#[cfg(feature = "deserialize")]
320impl<'de> serde::Deserialize<'de> for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
321    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
322        use std::str::FromStr;
323        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
324        Ok(Self::from_str(&s).expect("infallible"))
325    }
326}