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