stripe_shared/
payment_method_options_customer_balance.rs

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