stripe_shared/
invoice_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 InvoicePaymentMethodOptionsCustomerBalance {
5    pub bank_transfer:
6        Option<stripe_shared::InvoicePaymentMethodOptionsCustomerBalanceBankTransfer>,
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<InvoicePaymentMethodOptionsCustomerBalanceFundingType>,
10}
11#[doc(hidden)]
12pub struct InvoicePaymentMethodOptionsCustomerBalanceBuilder {
13    bank_transfer:
14        Option<Option<stripe_shared::InvoicePaymentMethodOptionsCustomerBalanceBankTransfer>>,
15    funding_type: Option<Option<InvoicePaymentMethodOptionsCustomerBalanceFundingType>>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for InvoicePaymentMethodOptionsCustomerBalance {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<InvoicePaymentMethodOptionsCustomerBalance>,
42        builder: InvoicePaymentMethodOptionsCustomerBalanceBuilder,
43    }
44
45    impl Visitor for Place<InvoicePaymentMethodOptionsCustomerBalance> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: InvoicePaymentMethodOptionsCustomerBalanceBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for InvoicePaymentMethodOptionsCustomerBalanceBuilder {
55        type Out = InvoicePaymentMethodOptionsCustomerBalance;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "bank_transfer" => Deserialize::begin(&mut self.bank_transfer),
59                "funding_type" => Deserialize::begin(&mut self.funding_type),
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { bank_transfer: Deserialize::default(), funding_type: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(bank_transfer), Some(funding_type)) =
70                (self.bank_transfer.take(), self.funding_type.take())
71            else {
72                return None;
73            };
74            Some(Self::Out { bank_transfer, funding_type })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for InvoicePaymentMethodOptionsCustomerBalance {
90        type Builder = InvoicePaymentMethodOptionsCustomerBalanceBuilder;
91    }
92
93    impl FromValueOpt for InvoicePaymentMethodOptionsCustomerBalance {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = InvoicePaymentMethodOptionsCustomerBalanceBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "bank_transfer" => b.bank_transfer = FromValueOpt::from_value(v),
102                    "funding_type" => b.funding_type = FromValueOpt::from_value(v),
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};
110/// The funding method type to be used when there are not enough funds in the customer balance.
111/// Permitted values include: `bank_transfer`.
112#[derive(Clone, Eq, PartialEq)]
113#[non_exhaustive]
114pub enum InvoicePaymentMethodOptionsCustomerBalanceFundingType {
115    BankTransfer,
116    /// An unrecognized value from Stripe. Should not be used as a request parameter.
117    Unknown(String),
118}
119impl InvoicePaymentMethodOptionsCustomerBalanceFundingType {
120    pub fn as_str(&self) -> &str {
121        use InvoicePaymentMethodOptionsCustomerBalanceFundingType::*;
122        match self {
123            BankTransfer => "bank_transfer",
124            Unknown(v) => v,
125        }
126    }
127}
128
129impl std::str::FromStr for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
130    type Err = std::convert::Infallible;
131    fn from_str(s: &str) -> Result<Self, Self::Err> {
132        use InvoicePaymentMethodOptionsCustomerBalanceFundingType::*;
133        match s {
134            "bank_transfer" => Ok(BankTransfer),
135            v => {
136                tracing::warn!(
137                    "Unknown value '{}' for enum '{}'",
138                    v,
139                    "InvoicePaymentMethodOptionsCustomerBalanceFundingType"
140                );
141                Ok(Unknown(v.to_owned()))
142            }
143        }
144    }
145}
146impl std::fmt::Display for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        f.write_str(self.as_str())
149    }
150}
151
152impl std::fmt::Debug for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
153    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154        f.write_str(self.as_str())
155    }
156}
157#[cfg(feature = "serialize")]
158impl serde::Serialize for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
159    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
160    where
161        S: serde::Serializer,
162    {
163        serializer.serialize_str(self.as_str())
164    }
165}
166impl miniserde::Deserialize for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
167    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
168        crate::Place::new(out)
169    }
170}
171
172impl miniserde::de::Visitor
173    for crate::Place<InvoicePaymentMethodOptionsCustomerBalanceFundingType>
174{
175    fn string(&mut self, s: &str) -> miniserde::Result<()> {
176        use std::str::FromStr;
177        self.out = Some(
178            InvoicePaymentMethodOptionsCustomerBalanceFundingType::from_str(s).expect("infallible"),
179        );
180        Ok(())
181    }
182}
183
184stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsCustomerBalanceFundingType);
185#[cfg(feature = "deserialize")]
186impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
187    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
188        use std::str::FromStr;
189        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
190        Ok(Self::from_str(&s).expect("infallible"))
191    }
192}