Skip to main content

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