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                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                bank_transfer: Deserialize::default(),
76                funding_type: Deserialize::default(),
77                setup_future_usage: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(bank_transfer), Some(funding_type), Some(setup_future_usage)) = (
83                self.bank_transfer.take(),
84                self.funding_type.take(),
85                self.setup_future_usage.take(),
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 PaymentMethodOptionsCustomerBalance {
105        type Builder = PaymentMethodOptionsCustomerBalanceBuilder;
106    }
107
108    impl FromValueOpt for PaymentMethodOptionsCustomerBalance {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = PaymentMethodOptionsCustomerBalanceBuilder::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(Clone, Eq, PartialEq)]
129#[non_exhaustive]
130pub enum PaymentMethodOptionsCustomerBalanceFundingType {
131    BankTransfer,
132    /// An unrecognized value from Stripe. Should not be used as a request parameter.
133    Unknown(String),
134}
135impl PaymentMethodOptionsCustomerBalanceFundingType {
136    pub fn as_str(&self) -> &str {
137        use PaymentMethodOptionsCustomerBalanceFundingType::*;
138        match self {
139            BankTransfer => "bank_transfer",
140            Unknown(v) => v,
141        }
142    }
143}
144
145impl std::str::FromStr for PaymentMethodOptionsCustomerBalanceFundingType {
146    type Err = std::convert::Infallible;
147    fn from_str(s: &str) -> Result<Self, Self::Err> {
148        use PaymentMethodOptionsCustomerBalanceFundingType::*;
149        match s {
150            "bank_transfer" => Ok(BankTransfer),
151            v => {
152                tracing::warn!(
153                    "Unknown value '{}' for enum '{}'",
154                    v,
155                    "PaymentMethodOptionsCustomerBalanceFundingType"
156                );
157                Ok(Unknown(v.to_owned()))
158            }
159        }
160    }
161}
162impl std::fmt::Display for PaymentMethodOptionsCustomerBalanceFundingType {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167
168impl std::fmt::Debug for PaymentMethodOptionsCustomerBalanceFundingType {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173#[cfg(feature = "serialize")]
174impl serde::Serialize for PaymentMethodOptionsCustomerBalanceFundingType {
175    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176    where
177        S: serde::Serializer,
178    {
179        serializer.serialize_str(self.as_str())
180    }
181}
182impl miniserde::Deserialize for PaymentMethodOptionsCustomerBalanceFundingType {
183    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
184        crate::Place::new(out)
185    }
186}
187
188impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCustomerBalanceFundingType> {
189    fn string(&mut self, s: &str) -> miniserde::Result<()> {
190        use std::str::FromStr;
191        self.out =
192            Some(PaymentMethodOptionsCustomerBalanceFundingType::from_str(s).expect("infallible"));
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCustomerBalanceFundingType);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCustomerBalanceFundingType {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Ok(Self::from_str(&s).expect("infallible"))
204    }
205}
206/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
207///
208/// 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.
209/// 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.
210///
211/// 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.
212///
213/// 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).
214#[derive(Clone, Eq, PartialEq)]
215#[non_exhaustive]
216pub enum PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
217    None,
218    /// An unrecognized value from Stripe. Should not be used as a request parameter.
219    Unknown(String),
220}
221impl PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
222    pub fn as_str(&self) -> &str {
223        use PaymentMethodOptionsCustomerBalanceSetupFutureUsage::*;
224        match self {
225            None => "none",
226            Unknown(v) => v,
227        }
228    }
229}
230
231impl std::str::FromStr for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
232    type Err = std::convert::Infallible;
233    fn from_str(s: &str) -> Result<Self, Self::Err> {
234        use PaymentMethodOptionsCustomerBalanceSetupFutureUsage::*;
235        match s {
236            "none" => Ok(None),
237            v => {
238                tracing::warn!(
239                    "Unknown value '{}' for enum '{}'",
240                    v,
241                    "PaymentMethodOptionsCustomerBalanceSetupFutureUsage"
242                );
243                Ok(Unknown(v.to_owned()))
244            }
245        }
246    }
247}
248impl std::fmt::Display for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        f.write_str(self.as_str())
251    }
252}
253
254impl std::fmt::Debug for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
255    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
256        f.write_str(self.as_str())
257    }
258}
259#[cfg(feature = "serialize")]
260impl serde::Serialize for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
261    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
262    where
263        S: serde::Serializer,
264    {
265        serializer.serialize_str(self.as_str())
266    }
267}
268impl miniserde::Deserialize for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
269    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
270        crate::Place::new(out)
271    }
272}
273
274impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCustomerBalanceSetupFutureUsage> {
275    fn string(&mut self, s: &str) -> miniserde::Result<()> {
276        use std::str::FromStr;
277        self.out = Some(
278            PaymentMethodOptionsCustomerBalanceSetupFutureUsage::from_str(s).expect("infallible"),
279        );
280        Ok(())
281    }
282}
283
284stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCustomerBalanceSetupFutureUsage);
285#[cfg(feature = "deserialize")]
286impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
287    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
288        use std::str::FromStr;
289        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
290        Ok(Self::from_str(&s).expect("infallible"))
291    }
292}