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