stripe_shared/
customer_balance_customer_balance_settings.rs

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