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(), self.funding_type, self.setup_future_usage)
84            else {
85                return None;
86            };
87            Some(Self::Out { bank_transfer, funding_type, setup_future_usage })
88        }
89    }
90
91    impl Map for Builder<'_> {
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            self.builder.key(k)
94        }
95
96        fn finish(&mut self) -> Result<()> {
97            *self.out = self.builder.take_out();
98            Ok(())
99        }
100    }
101
102    impl ObjectDeser for PaymentMethodOptionsCustomerBalance {
103        type Builder = PaymentMethodOptionsCustomerBalanceBuilder;
104    }
105
106    impl FromValueOpt for PaymentMethodOptionsCustomerBalance {
107        fn from_value(v: Value) -> Option<Self> {
108            let Value::Object(obj) = v else {
109                return None;
110            };
111            let mut b = PaymentMethodOptionsCustomerBalanceBuilder::deser_default();
112            for (k, v) in obj {
113                match k.as_str() {
114                    "bank_transfer" => b.bank_transfer = FromValueOpt::from_value(v),
115                    "funding_type" => b.funding_type = FromValueOpt::from_value(v),
116                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
117                    _ => {}
118                }
119            }
120            b.take_out()
121        }
122    }
123};
124/// The funding method type to be used when there are not enough funds in the customer balance.
125/// Permitted values include: `bank_transfer`.
126#[derive(Copy, Clone, Eq, PartialEq)]
127pub enum PaymentMethodOptionsCustomerBalanceFundingType {
128    BankTransfer,
129}
130impl PaymentMethodOptionsCustomerBalanceFundingType {
131    pub fn as_str(self) -> &'static str {
132        use PaymentMethodOptionsCustomerBalanceFundingType::*;
133        match self {
134            BankTransfer => "bank_transfer",
135        }
136    }
137}
138
139impl std::str::FromStr for PaymentMethodOptionsCustomerBalanceFundingType {
140    type Err = stripe_types::StripeParseError;
141    fn from_str(s: &str) -> Result<Self, Self::Err> {
142        use PaymentMethodOptionsCustomerBalanceFundingType::*;
143        match s {
144            "bank_transfer" => Ok(BankTransfer),
145            _ => Err(stripe_types::StripeParseError),
146        }
147    }
148}
149impl std::fmt::Display for PaymentMethodOptionsCustomerBalanceFundingType {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154
155impl std::fmt::Debug for PaymentMethodOptionsCustomerBalanceFundingType {
156    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157        f.write_str(self.as_str())
158    }
159}
160#[cfg(feature = "serialize")]
161impl serde::Serialize for PaymentMethodOptionsCustomerBalanceFundingType {
162    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163    where
164        S: serde::Serializer,
165    {
166        serializer.serialize_str(self.as_str())
167    }
168}
169impl miniserde::Deserialize for PaymentMethodOptionsCustomerBalanceFundingType {
170    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
171        crate::Place::new(out)
172    }
173}
174
175impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCustomerBalanceFundingType> {
176    fn string(&mut self, s: &str) -> miniserde::Result<()> {
177        use std::str::FromStr;
178        self.out = Some(
179            PaymentMethodOptionsCustomerBalanceFundingType::from_str(s)
180                .map_err(|_| miniserde::Error)?,
181        );
182        Ok(())
183    }
184}
185
186stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCustomerBalanceFundingType);
187#[cfg(feature = "deserialize")]
188impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCustomerBalanceFundingType {
189    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
190        use std::str::FromStr;
191        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
192        Self::from_str(&s).map_err(|_| {
193            serde::de::Error::custom(
194                "Unknown value for PaymentMethodOptionsCustomerBalanceFundingType",
195            )
196        })
197    }
198}
199/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
200///
201/// 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.
202/// 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.
203///
204/// 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.
205///
206/// 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).
207#[derive(Copy, Clone, Eq, PartialEq)]
208pub enum PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
209    None,
210}
211impl PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
212    pub fn as_str(self) -> &'static str {
213        use PaymentMethodOptionsCustomerBalanceSetupFutureUsage::*;
214        match self {
215            None => "none",
216        }
217    }
218}
219
220impl std::str::FromStr for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
221    type Err = stripe_types::StripeParseError;
222    fn from_str(s: &str) -> Result<Self, Self::Err> {
223        use PaymentMethodOptionsCustomerBalanceSetupFutureUsage::*;
224        match s {
225            "none" => Ok(None),
226            _ => Err(stripe_types::StripeParseError),
227        }
228    }
229}
230impl std::fmt::Display for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.write_str(self.as_str())
233    }
234}
235
236impl std::fmt::Debug for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
237    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238        f.write_str(self.as_str())
239    }
240}
241#[cfg(feature = "serialize")]
242impl serde::Serialize for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
243    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
244    where
245        S: serde::Serializer,
246    {
247        serializer.serialize_str(self.as_str())
248    }
249}
250impl miniserde::Deserialize for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
251    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
252        crate::Place::new(out)
253    }
254}
255
256impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCustomerBalanceSetupFutureUsage> {
257    fn string(&mut self, s: &str) -> miniserde::Result<()> {
258        use std::str::FromStr;
259        self.out = Some(
260            PaymentMethodOptionsCustomerBalanceSetupFutureUsage::from_str(s)
261                .map_err(|_| miniserde::Error)?,
262        );
263        Ok(())
264    }
265}
266
267stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCustomerBalanceSetupFutureUsage);
268#[cfg(feature = "deserialize")]
269impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCustomerBalanceSetupFutureUsage {
270    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
271        use std::str::FromStr;
272        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
273        Self::from_str(&s).map_err(|_| {
274            serde::de::Error::custom(
275                "Unknown value for PaymentMethodOptionsCustomerBalanceSetupFutureUsage",
276            )
277        })
278    }
279}