stripe_shared/
account_invoices_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountInvoicesSettings {
5    /// The list of default Account Tax IDs to automatically include on invoices.
6    /// Account Tax IDs get added when an invoice is finalized.
7    pub default_account_tax_ids: Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>,
8    /// Whether payment methods should be saved when a payment is completed for a one-time invoices on a hosted invoice page.
9    pub hosted_payment_method_save: Option<AccountInvoicesSettingsHostedPaymentMethodSave>,
10}
11#[doc(hidden)]
12pub struct AccountInvoicesSettingsBuilder {
13    default_account_tax_ids: Option<Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>>,
14    hosted_payment_method_save: Option<Option<AccountInvoicesSettingsHostedPaymentMethodSave>>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{make_place, Deserialize, Result};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for AccountInvoicesSettings {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<AccountInvoicesSettings>,
41        builder: AccountInvoicesSettingsBuilder,
42    }
43
44    impl Visitor for Place<AccountInvoicesSettings> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: AccountInvoicesSettingsBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for AccountInvoicesSettingsBuilder {
54        type Out = AccountInvoicesSettings;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "default_account_tax_ids" => Deserialize::begin(&mut self.default_account_tax_ids),
58                "hosted_payment_method_save" => {
59                    Deserialize::begin(&mut self.hosted_payment_method_save)
60                }
61
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                default_account_tax_ids: Deserialize::default(),
69                hosted_payment_method_save: Deserialize::default(),
70            }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(default_account_tax_ids), Some(hosted_payment_method_save)) =
75                (self.default_account_tax_ids.take(), self.hosted_payment_method_save)
76            else {
77                return None;
78            };
79            Some(Self::Out { default_account_tax_ids, hosted_payment_method_save })
80        }
81    }
82
83    impl Map for Builder<'_> {
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            self.builder.key(k)
86        }
87
88        fn finish(&mut self) -> Result<()> {
89            *self.out = self.builder.take_out();
90            Ok(())
91        }
92    }
93
94    impl ObjectDeser for AccountInvoicesSettings {
95        type Builder = AccountInvoicesSettingsBuilder;
96    }
97
98    impl FromValueOpt for AccountInvoicesSettings {
99        fn from_value(v: Value) -> Option<Self> {
100            let Value::Object(obj) = v else {
101                return None;
102            };
103            let mut b = AccountInvoicesSettingsBuilder::deser_default();
104            for (k, v) in obj {
105                match k.as_str() {
106                    "default_account_tax_ids" => {
107                        b.default_account_tax_ids = FromValueOpt::from_value(v)
108                    }
109                    "hosted_payment_method_save" => {
110                        b.hosted_payment_method_save = FromValueOpt::from_value(v)
111                    }
112
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};
120/// Whether payment methods should be saved when a payment is completed for a one-time invoices on a hosted invoice page.
121#[derive(Copy, Clone, Eq, PartialEq)]
122pub enum AccountInvoicesSettingsHostedPaymentMethodSave {
123    Always,
124    Never,
125    Offer,
126}
127impl AccountInvoicesSettingsHostedPaymentMethodSave {
128    pub fn as_str(self) -> &'static str {
129        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
130        match self {
131            Always => "always",
132            Never => "never",
133            Offer => "offer",
134        }
135    }
136}
137
138impl std::str::FromStr for AccountInvoicesSettingsHostedPaymentMethodSave {
139    type Err = stripe_types::StripeParseError;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
142        match s {
143            "always" => Ok(Always),
144            "never" => Ok(Never),
145            "offer" => Ok(Offer),
146            _ => Err(stripe_types::StripeParseError),
147        }
148    }
149}
150impl std::fmt::Display for AccountInvoicesSettingsHostedPaymentMethodSave {
151    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152        f.write_str(self.as_str())
153    }
154}
155
156impl std::fmt::Debug for AccountInvoicesSettingsHostedPaymentMethodSave {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161#[cfg(feature = "serialize")]
162impl serde::Serialize for AccountInvoicesSettingsHostedPaymentMethodSave {
163    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
164    where
165        S: serde::Serializer,
166    {
167        serializer.serialize_str(self.as_str())
168    }
169}
170impl miniserde::Deserialize for AccountInvoicesSettingsHostedPaymentMethodSave {
171    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
172        crate::Place::new(out)
173    }
174}
175
176impl miniserde::de::Visitor for crate::Place<AccountInvoicesSettingsHostedPaymentMethodSave> {
177    fn string(&mut self, s: &str) -> miniserde::Result<()> {
178        use std::str::FromStr;
179        self.out = Some(
180            AccountInvoicesSettingsHostedPaymentMethodSave::from_str(s)
181                .map_err(|_| miniserde::Error)?,
182        );
183        Ok(())
184    }
185}
186
187stripe_types::impl_from_val_with_from_str!(AccountInvoicesSettingsHostedPaymentMethodSave);
188#[cfg(feature = "deserialize")]
189impl<'de> serde::Deserialize<'de> for AccountInvoicesSettingsHostedPaymentMethodSave {
190    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
191        use std::str::FromStr;
192        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
193        Self::from_str(&s).map_err(|_| {
194            serde::de::Error::custom(
195                "Unknown value for AccountInvoicesSettingsHostedPaymentMethodSave",
196            )
197        })
198    }
199}