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 to save the payment method after a payment is completed for a one-time invoice or a subscription invoice when the customer already has a default payment method on the 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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self {
67                default_account_tax_ids: Deserialize::default(),
68                hosted_payment_method_save: Deserialize::default(),
69            }
70        }
71
72        fn take_out(&mut self) -> Option<Self::Out> {
73            let (Some(default_account_tax_ids), Some(hosted_payment_method_save)) =
74                (self.default_account_tax_ids.take(), self.hosted_payment_method_save.take())
75            else {
76                return None;
77            };
78            Some(Self::Out { default_account_tax_ids, hosted_payment_method_save })
79        }
80    }
81
82    impl Map for Builder<'_> {
83        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84            self.builder.key(k)
85        }
86
87        fn finish(&mut self) -> Result<()> {
88            *self.out = self.builder.take_out();
89            Ok(())
90        }
91    }
92
93    impl ObjectDeser for AccountInvoicesSettings {
94        type Builder = AccountInvoicesSettingsBuilder;
95    }
96
97    impl FromValueOpt for AccountInvoicesSettings {
98        fn from_value(v: Value) -> Option<Self> {
99            let Value::Object(obj) = v else {
100                return None;
101            };
102            let mut b = AccountInvoicesSettingsBuilder::deser_default();
103            for (k, v) in obj {
104                match k.as_str() {
105                    "default_account_tax_ids" => {
106                        b.default_account_tax_ids = FromValueOpt::from_value(v)
107                    }
108                    "hosted_payment_method_save" => {
109                        b.hosted_payment_method_save = FromValueOpt::from_value(v)
110                    }
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Whether to save the payment method after a payment is completed for a one-time invoice or a subscription invoice when the customer already has a default payment method on the hosted invoice page.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum AccountInvoicesSettingsHostedPaymentMethodSave {
122    Always,
123    Never,
124    Offer,
125    /// An unrecognized value from Stripe. Should not be used as a request parameter.
126    Unknown(String),
127}
128impl AccountInvoicesSettingsHostedPaymentMethodSave {
129    pub fn as_str(&self) -> &str {
130        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
131        match self {
132            Always => "always",
133            Never => "never",
134            Offer => "offer",
135            Unknown(v) => v,
136        }
137    }
138}
139
140impl std::str::FromStr for AccountInvoicesSettingsHostedPaymentMethodSave {
141    type Err = std::convert::Infallible;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
144        match s {
145            "always" => Ok(Always),
146            "never" => Ok(Never),
147            "offer" => Ok(Offer),
148            v => {
149                tracing::warn!(
150                    "Unknown value '{}' for enum '{}'",
151                    v,
152                    "AccountInvoicesSettingsHostedPaymentMethodSave"
153                );
154                Ok(Unknown(v.to_owned()))
155            }
156        }
157    }
158}
159impl std::fmt::Display for AccountInvoicesSettingsHostedPaymentMethodSave {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164
165impl std::fmt::Debug for AccountInvoicesSettingsHostedPaymentMethodSave {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170#[cfg(feature = "serialize")]
171impl serde::Serialize for AccountInvoicesSettingsHostedPaymentMethodSave {
172    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173    where
174        S: serde::Serializer,
175    {
176        serializer.serialize_str(self.as_str())
177    }
178}
179impl miniserde::Deserialize for AccountInvoicesSettingsHostedPaymentMethodSave {
180    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
181        crate::Place::new(out)
182    }
183}
184
185impl miniserde::de::Visitor for crate::Place<AccountInvoicesSettingsHostedPaymentMethodSave> {
186    fn string(&mut self, s: &str) -> miniserde::Result<()> {
187        use std::str::FromStr;
188        self.out =
189            Some(AccountInvoicesSettingsHostedPaymentMethodSave::from_str(s).expect("infallible"));
190        Ok(())
191    }
192}
193
194stripe_types::impl_from_val_with_from_str!(AccountInvoicesSettingsHostedPaymentMethodSave);
195#[cfg(feature = "deserialize")]
196impl<'de> serde::Deserialize<'de> for AccountInvoicesSettingsHostedPaymentMethodSave {
197    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
198        use std::str::FromStr;
199        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
200        Ok(Self::from_str(&s).expect("infallible"))
201    }
202}