stripe_shared/
subscription_schedules_resource_default_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionSchedulesResourceDefaultSettings {
5    /// A non-negative decimal between 0 and 100, with at most two decimal places.
6    /// This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account during this phase of the schedule.
7    pub application_fee_percent: Option<f64>,
8    pub automatic_tax:
9        Option<stripe_shared::SubscriptionSchedulesResourceDefaultSettingsAutomaticTax>,
10    /// Possible values are `phase_start` or `automatic`.
11    /// If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase.
12    /// If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase.
13    /// For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle).
14    pub billing_cycle_anchor: SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor,
15    /// Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period.
16    pub billing_thresholds: Option<stripe_shared::SubscriptionBillingThresholds>,
17    /// Either `charge_automatically`, or `send_invoice`.
18    /// When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer.
19    /// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
20    pub collection_method: Option<SubscriptionSchedulesResourceDefaultSettingsCollectionMethod>,
21    /// ID of the default payment method for the subscription schedule.
22    /// If not set, invoices will use the default payment method in the customer's invoice settings.
23    pub default_payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
24    /// Subscription description, meant to be displayable to the customer.
25    /// Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
26    pub description: Option<String>,
27    pub invoice_settings: stripe_shared::InvoiceSettingSubscriptionScheduleSetting,
28    /// The account (if any) the charge was made on behalf of for charges associated with the schedule's subscription.
29    /// See the Connect documentation for details.
30    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
31    /// The account (if any) the associated subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices.
32    pub transfer_data: Option<stripe_shared::SubscriptionTransferData>,
33}
34#[doc(hidden)]
35pub struct SubscriptionSchedulesResourceDefaultSettingsBuilder {
36    application_fee_percent: Option<Option<f64>>,
37    automatic_tax:
38        Option<Option<stripe_shared::SubscriptionSchedulesResourceDefaultSettingsAutomaticTax>>,
39    billing_cycle_anchor: Option<SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor>,
40    billing_thresholds: Option<Option<stripe_shared::SubscriptionBillingThresholds>>,
41    collection_method: Option<Option<SubscriptionSchedulesResourceDefaultSettingsCollectionMethod>>,
42    default_payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
43    description: Option<Option<String>>,
44    invoice_settings: Option<stripe_shared::InvoiceSettingSubscriptionScheduleSetting>,
45    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
46    transfer_data: Option<Option<stripe_shared::SubscriptionTransferData>>,
47}
48
49#[allow(
50    unused_variables,
51    irrefutable_let_patterns,
52    clippy::let_unit_value,
53    clippy::match_single_binding,
54    clippy::single_match
55)]
56const _: () = {
57    use miniserde::de::{Map, Visitor};
58    use miniserde::json::Value;
59    use miniserde::{Deserialize, Result, make_place};
60    use stripe_types::miniserde_helpers::FromValueOpt;
61    use stripe_types::{MapBuilder, ObjectDeser};
62
63    make_place!(Place);
64
65    impl Deserialize for SubscriptionSchedulesResourceDefaultSettings {
66        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
67            Place::new(out)
68        }
69    }
70
71    struct Builder<'a> {
72        out: &'a mut Option<SubscriptionSchedulesResourceDefaultSettings>,
73        builder: SubscriptionSchedulesResourceDefaultSettingsBuilder,
74    }
75
76    impl Visitor for Place<SubscriptionSchedulesResourceDefaultSettings> {
77        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
78            Ok(Box::new(Builder {
79                out: &mut self.out,
80                builder: SubscriptionSchedulesResourceDefaultSettingsBuilder::deser_default(),
81            }))
82        }
83    }
84
85    impl MapBuilder for SubscriptionSchedulesResourceDefaultSettingsBuilder {
86        type Out = SubscriptionSchedulesResourceDefaultSettings;
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            Ok(match k {
89                "application_fee_percent" => Deserialize::begin(&mut self.application_fee_percent),
90                "automatic_tax" => Deserialize::begin(&mut self.automatic_tax),
91                "billing_cycle_anchor" => Deserialize::begin(&mut self.billing_cycle_anchor),
92                "billing_thresholds" => Deserialize::begin(&mut self.billing_thresholds),
93                "collection_method" => Deserialize::begin(&mut self.collection_method),
94                "default_payment_method" => Deserialize::begin(&mut self.default_payment_method),
95                "description" => Deserialize::begin(&mut self.description),
96                "invoice_settings" => Deserialize::begin(&mut self.invoice_settings),
97                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
98                "transfer_data" => Deserialize::begin(&mut self.transfer_data),
99                _ => <dyn Visitor>::ignore(),
100            })
101        }
102
103        fn deser_default() -> Self {
104            Self {
105                application_fee_percent: Deserialize::default(),
106                automatic_tax: Deserialize::default(),
107                billing_cycle_anchor: Deserialize::default(),
108                billing_thresholds: Deserialize::default(),
109                collection_method: Deserialize::default(),
110                default_payment_method: Deserialize::default(),
111                description: Deserialize::default(),
112                invoice_settings: Deserialize::default(),
113                on_behalf_of: Deserialize::default(),
114                transfer_data: Deserialize::default(),
115            }
116        }
117
118        fn take_out(&mut self) -> Option<Self::Out> {
119            let (
120                Some(application_fee_percent),
121                Some(automatic_tax),
122                Some(billing_cycle_anchor),
123                Some(billing_thresholds),
124                Some(collection_method),
125                Some(default_payment_method),
126                Some(description),
127                Some(invoice_settings),
128                Some(on_behalf_of),
129                Some(transfer_data),
130            ) = (
131                self.application_fee_percent,
132                self.automatic_tax.take(),
133                self.billing_cycle_anchor,
134                self.billing_thresholds,
135                self.collection_method,
136                self.default_payment_method.take(),
137                self.description.take(),
138                self.invoice_settings.take(),
139                self.on_behalf_of.take(),
140                self.transfer_data.take(),
141            )
142            else {
143                return None;
144            };
145            Some(Self::Out {
146                application_fee_percent,
147                automatic_tax,
148                billing_cycle_anchor,
149                billing_thresholds,
150                collection_method,
151                default_payment_method,
152                description,
153                invoice_settings,
154                on_behalf_of,
155                transfer_data,
156            })
157        }
158    }
159
160    impl Map for Builder<'_> {
161        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
162            self.builder.key(k)
163        }
164
165        fn finish(&mut self) -> Result<()> {
166            *self.out = self.builder.take_out();
167            Ok(())
168        }
169    }
170
171    impl ObjectDeser for SubscriptionSchedulesResourceDefaultSettings {
172        type Builder = SubscriptionSchedulesResourceDefaultSettingsBuilder;
173    }
174
175    impl FromValueOpt for SubscriptionSchedulesResourceDefaultSettings {
176        fn from_value(v: Value) -> Option<Self> {
177            let Value::Object(obj) = v else {
178                return None;
179            };
180            let mut b = SubscriptionSchedulesResourceDefaultSettingsBuilder::deser_default();
181            for (k, v) in obj {
182                match k.as_str() {
183                    "application_fee_percent" => {
184                        b.application_fee_percent = FromValueOpt::from_value(v)
185                    }
186                    "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
187                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
188                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
189                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
190                    "default_payment_method" => {
191                        b.default_payment_method = FromValueOpt::from_value(v)
192                    }
193                    "description" => b.description = FromValueOpt::from_value(v),
194                    "invoice_settings" => b.invoice_settings = FromValueOpt::from_value(v),
195                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
196                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
197                    _ => {}
198                }
199            }
200            b.take_out()
201        }
202    }
203};
204/// Possible values are `phase_start` or `automatic`.
205/// If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase.
206/// If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase.
207/// For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle).
208#[derive(Copy, Clone, Eq, PartialEq)]
209pub enum SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
210    Automatic,
211    PhaseStart,
212}
213impl SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
214    pub fn as_str(self) -> &'static str {
215        use SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::*;
216        match self {
217            Automatic => "automatic",
218            PhaseStart => "phase_start",
219        }
220    }
221}
222
223impl std::str::FromStr for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
224    type Err = stripe_types::StripeParseError;
225    fn from_str(s: &str) -> Result<Self, Self::Err> {
226        use SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::*;
227        match s {
228            "automatic" => Ok(Automatic),
229            "phase_start" => Ok(PhaseStart),
230            _ => Err(stripe_types::StripeParseError),
231        }
232    }
233}
234impl std::fmt::Display for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
235    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236        f.write_str(self.as_str())
237    }
238}
239
240impl std::fmt::Debug for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
241    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
242        f.write_str(self.as_str())
243    }
244}
245#[cfg(feature = "serialize")]
246impl serde::Serialize for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
247    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
248    where
249        S: serde::Serializer,
250    {
251        serializer.serialize_str(self.as_str())
252    }
253}
254impl miniserde::Deserialize for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
255    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
256        crate::Place::new(out)
257    }
258}
259
260impl miniserde::de::Visitor
261    for crate::Place<SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor>
262{
263    fn string(&mut self, s: &str) -> miniserde::Result<()> {
264        use std::str::FromStr;
265        self.out = Some(
266            SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::from_str(s)
267                .map_err(|_| miniserde::Error)?,
268        );
269        Ok(())
270    }
271}
272
273stripe_types::impl_from_val_with_from_str!(
274    SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor
275);
276#[cfg(feature = "deserialize")]
277impl<'de> serde::Deserialize<'de>
278    for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor
279{
280    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
281        use std::str::FromStr;
282        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
283        Self::from_str(&s).map_err(|_| {
284            serde::de::Error::custom(
285                "Unknown value for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor",
286            )
287        })
288    }
289}
290/// Either `charge_automatically`, or `send_invoice`.
291/// When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer.
292/// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
293#[derive(Copy, Clone, Eq, PartialEq)]
294pub enum SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
295    ChargeAutomatically,
296    SendInvoice,
297}
298impl SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
299    pub fn as_str(self) -> &'static str {
300        use SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::*;
301        match self {
302            ChargeAutomatically => "charge_automatically",
303            SendInvoice => "send_invoice",
304        }
305    }
306}
307
308impl std::str::FromStr for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
309    type Err = stripe_types::StripeParseError;
310    fn from_str(s: &str) -> Result<Self, Self::Err> {
311        use SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::*;
312        match s {
313            "charge_automatically" => Ok(ChargeAutomatically),
314            "send_invoice" => Ok(SendInvoice),
315            _ => Err(stripe_types::StripeParseError),
316        }
317    }
318}
319impl std::fmt::Display for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324
325impl std::fmt::Debug for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
326    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327        f.write_str(self.as_str())
328    }
329}
330#[cfg(feature = "serialize")]
331impl serde::Serialize for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
332    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
333    where
334        S: serde::Serializer,
335    {
336        serializer.serialize_str(self.as_str())
337    }
338}
339impl miniserde::Deserialize for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
340    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
341        crate::Place::new(out)
342    }
343}
344
345impl miniserde::de::Visitor
346    for crate::Place<SubscriptionSchedulesResourceDefaultSettingsCollectionMethod>
347{
348    fn string(&mut self, s: &str) -> miniserde::Result<()> {
349        use std::str::FromStr;
350        self.out = Some(
351            SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::from_str(s)
352                .map_err(|_| miniserde::Error)?,
353        );
354        Ok(())
355    }
356}
357
358stripe_types::impl_from_val_with_from_str!(
359    SubscriptionSchedulesResourceDefaultSettingsCollectionMethod
360);
361#[cfg(feature = "deserialize")]
362impl<'de> serde::Deserialize<'de> for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
363    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
364        use std::str::FromStr;
365        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
366        Self::from_str(&s).map_err(|_| {
367            serde::de::Error::custom(
368                "Unknown value for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod",
369            )
370        })
371    }
372}