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::{make_place, Deserialize, Result};
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
100                _ => <dyn Visitor>::ignore(),
101            })
102        }
103
104        fn deser_default() -> Self {
105            Self {
106                application_fee_percent: Deserialize::default(),
107                automatic_tax: Deserialize::default(),
108                billing_cycle_anchor: Deserialize::default(),
109                billing_thresholds: Deserialize::default(),
110                collection_method: Deserialize::default(),
111                default_payment_method: Deserialize::default(),
112                description: Deserialize::default(),
113                invoice_settings: Deserialize::default(),
114                on_behalf_of: Deserialize::default(),
115                transfer_data: Deserialize::default(),
116            }
117        }
118
119        fn take_out(&mut self) -> Option<Self::Out> {
120            let (
121                Some(application_fee_percent),
122                Some(automatic_tax),
123                Some(billing_cycle_anchor),
124                Some(billing_thresholds),
125                Some(collection_method),
126                Some(default_payment_method),
127                Some(description),
128                Some(invoice_settings),
129                Some(on_behalf_of),
130                Some(transfer_data),
131            ) = (
132                self.application_fee_percent,
133                self.automatic_tax.take(),
134                self.billing_cycle_anchor,
135                self.billing_thresholds,
136                self.collection_method,
137                self.default_payment_method.take(),
138                self.description.take(),
139                self.invoice_settings.take(),
140                self.on_behalf_of.take(),
141                self.transfer_data.take(),
142            )
143            else {
144                return None;
145            };
146            Some(Self::Out {
147                application_fee_percent,
148                automatic_tax,
149                billing_cycle_anchor,
150                billing_thresholds,
151                collection_method,
152                default_payment_method,
153                description,
154                invoice_settings,
155                on_behalf_of,
156                transfer_data,
157            })
158        }
159    }
160
161    impl Map for Builder<'_> {
162        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
163            self.builder.key(k)
164        }
165
166        fn finish(&mut self) -> Result<()> {
167            *self.out = self.builder.take_out();
168            Ok(())
169        }
170    }
171
172    impl ObjectDeser for SubscriptionSchedulesResourceDefaultSettings {
173        type Builder = SubscriptionSchedulesResourceDefaultSettingsBuilder;
174    }
175
176    impl FromValueOpt for SubscriptionSchedulesResourceDefaultSettings {
177        fn from_value(v: Value) -> Option<Self> {
178            let Value::Object(obj) = v else {
179                return None;
180            };
181            let mut b = SubscriptionSchedulesResourceDefaultSettingsBuilder::deser_default();
182            for (k, v) in obj {
183                match k.as_str() {
184                    "application_fee_percent" => {
185                        b.application_fee_percent = FromValueOpt::from_value(v)
186                    }
187                    "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
188                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
189                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
190                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
191                    "default_payment_method" => {
192                        b.default_payment_method = FromValueOpt::from_value(v)
193                    }
194                    "description" => b.description = FromValueOpt::from_value(v),
195                    "invoice_settings" => b.invoice_settings = FromValueOpt::from_value(v),
196                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
197                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
198
199                    _ => {}
200                }
201            }
202            b.take_out()
203        }
204    }
205};
206/// Possible values are `phase_start` or `automatic`.
207/// If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase.
208/// If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase.
209/// For more information, see the billing cycle [documentation](https://stripe.com/docs/billing/subscriptions/billing-cycle).
210#[derive(Copy, Clone, Eq, PartialEq)]
211pub enum SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
212    Automatic,
213    PhaseStart,
214}
215impl SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
216    pub fn as_str(self) -> &'static str {
217        use SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::*;
218        match self {
219            Automatic => "automatic",
220            PhaseStart => "phase_start",
221        }
222    }
223}
224
225impl std::str::FromStr for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
226    type Err = stripe_types::StripeParseError;
227    fn from_str(s: &str) -> Result<Self, Self::Err> {
228        use SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::*;
229        match s {
230            "automatic" => Ok(Automatic),
231            "phase_start" => Ok(PhaseStart),
232            _ => Err(stripe_types::StripeParseError),
233        }
234    }
235}
236impl std::fmt::Display for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
237    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238        f.write_str(self.as_str())
239    }
240}
241
242impl std::fmt::Debug for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
243    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244        f.write_str(self.as_str())
245    }
246}
247#[cfg(feature = "serialize")]
248impl serde::Serialize for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
249    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
250    where
251        S: serde::Serializer,
252    {
253        serializer.serialize_str(self.as_str())
254    }
255}
256impl miniserde::Deserialize for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor {
257    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
258        crate::Place::new(out)
259    }
260}
261
262impl miniserde::de::Visitor
263    for crate::Place<SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor>
264{
265    fn string(&mut self, s: &str) -> miniserde::Result<()> {
266        use std::str::FromStr;
267        self.out = Some(
268            SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor::from_str(s)
269                .map_err(|_| miniserde::Error)?,
270        );
271        Ok(())
272    }
273}
274
275stripe_types::impl_from_val_with_from_str!(
276    SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor
277);
278#[cfg(feature = "deserialize")]
279impl<'de> serde::Deserialize<'de>
280    for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor
281{
282    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
283        use std::str::FromStr;
284        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
285        Self::from_str(&s).map_err(|_| {
286            serde::de::Error::custom(
287                "Unknown value for SubscriptionSchedulesResourceDefaultSettingsBillingCycleAnchor",
288            )
289        })
290    }
291}
292/// Either `charge_automatically`, or `send_invoice`.
293/// 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.
294/// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
295#[derive(Copy, Clone, Eq, PartialEq)]
296pub enum SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
297    ChargeAutomatically,
298    SendInvoice,
299}
300impl SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
301    pub fn as_str(self) -> &'static str {
302        use SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::*;
303        match self {
304            ChargeAutomatically => "charge_automatically",
305            SendInvoice => "send_invoice",
306        }
307    }
308}
309
310impl std::str::FromStr for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
311    type Err = stripe_types::StripeParseError;
312    fn from_str(s: &str) -> Result<Self, Self::Err> {
313        use SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::*;
314        match s {
315            "charge_automatically" => Ok(ChargeAutomatically),
316            "send_invoice" => Ok(SendInvoice),
317            _ => Err(stripe_types::StripeParseError),
318        }
319    }
320}
321impl std::fmt::Display for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
322    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
323        f.write_str(self.as_str())
324    }
325}
326
327impl std::fmt::Debug for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
328    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
329        f.write_str(self.as_str())
330    }
331}
332#[cfg(feature = "serialize")]
333impl serde::Serialize for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
334    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
335    where
336        S: serde::Serializer,
337    {
338        serializer.serialize_str(self.as_str())
339    }
340}
341impl miniserde::Deserialize for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
342    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
343        crate::Place::new(out)
344    }
345}
346
347impl miniserde::de::Visitor
348    for crate::Place<SubscriptionSchedulesResourceDefaultSettingsCollectionMethod>
349{
350    fn string(&mut self, s: &str) -> miniserde::Result<()> {
351        use std::str::FromStr;
352        self.out = Some(
353            SubscriptionSchedulesResourceDefaultSettingsCollectionMethod::from_str(s)
354                .map_err(|_| miniserde::Error)?,
355        );
356        Ok(())
357    }
358}
359
360stripe_types::impl_from_val_with_from_str!(
361    SubscriptionSchedulesResourceDefaultSettingsCollectionMethod
362);
363#[cfg(feature = "deserialize")]
364impl<'de> serde::Deserialize<'de> for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod {
365    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
366        use std::str::FromStr;
367        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
368        Self::from_str(&s).map_err(|_| {
369            serde::de::Error::custom(
370                "Unknown value for SubscriptionSchedulesResourceDefaultSettingsCollectionMethod",
371            )
372        })
373    }
374}