Skip to main content

stripe_shared/
subscription_schedule_phase_configuration.rs

1/// A phase describes the plans, coupon, and trialing status of a subscription for a predefined time period.
2#[derive(Clone)]
3#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
4#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
5#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
6pub struct SubscriptionSchedulePhaseConfiguration {
7    /// A list of prices and quantities that will generate invoice items appended to the next invoice for this phase.
8    pub add_invoice_items: Vec<stripe_shared::SubscriptionScheduleAddInvoiceItem>,
9    /// A non-negative decimal between 0 and 100, with at most two decimal places.
10    /// 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.
11    pub application_fee_percent: Option<f64>,
12    pub automatic_tax: Option<stripe_shared::SchedulesPhaseAutomaticTax>,
13    /// Possible values are `phase_start` or `automatic`.
14    /// If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase.
15    /// If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase.
16    /// For more information, see the billing cycle [documentation](https://docs.stripe.com/billing/subscriptions/billing-cycle).
17    pub billing_cycle_anchor: Option<SubscriptionSchedulePhaseConfigurationBillingCycleAnchor>,
18    /// Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period.
19    pub billing_thresholds: Option<stripe_shared::SubscriptionBillingThresholds>,
20    /// Either `charge_automatically`, or `send_invoice`.
21    /// 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.
22    /// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
23    pub collection_method: Option<SubscriptionSchedulePhaseConfigurationCollectionMethod>,
24    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
25    /// Must be a [supported currency](https://stripe.com/docs/currencies).
26    pub currency: stripe_types::Currency,
27    /// ID of the default payment method for the subscription schedule.
28    /// It must belong to the customer associated with the subscription schedule.
29    /// If not set, invoices will use the default payment method in the customer's invoice settings.
30    pub default_payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
31    /// The default tax rates to apply to the subscription during this phase of the subscription schedule.
32    pub default_tax_rates: Option<Vec<stripe_shared::TaxRate>>,
33    /// Subscription description, meant to be displayable to the customer.
34    /// Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
35    pub description: Option<String>,
36    /// The stackable discounts that will be applied to the subscription on this phase.
37    /// Subscription item discounts are applied before subscription discounts.
38    pub discounts: Vec<stripe_shared::StackableDiscountWithDiscountSettingsAndDiscountEnd>,
39    /// The end of this phase of the subscription schedule.
40    pub end_date: stripe_types::Timestamp,
41    /// The invoice settings applicable during this phase.
42    pub invoice_settings: Option<stripe_shared::InvoiceSettingSubscriptionSchedulePhaseSetting>,
43    /// Subscription items to configure the subscription to during this phase of the subscription schedule.
44    pub items: Vec<stripe_shared::SubscriptionScheduleConfigurationItem>,
45    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to a phase.
46    /// Metadata on a schedule's phase will update the underlying subscription's `metadata` when the phase is entered.
47    /// Updating the underlying subscription's `metadata` directly will not affect the current phase's `metadata`.
48    pub metadata: Option<std::collections::HashMap<String, String>>,
49    /// The account (if any) the charge was made on behalf of for charges associated with the schedule's subscription.
50    /// See the Connect documentation for details.
51    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
52    /// When transitioning phases, controls how prorations are handled (if any).
53    /// Possible values are `create_prorations`, `none`, and `always_invoice`.
54    pub proration_behavior: SubscriptionSchedulePhaseConfigurationProrationBehavior,
55    /// The start of this phase of the subscription schedule.
56    pub start_date: stripe_types::Timestamp,
57    /// 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.
58    pub transfer_data: Option<stripe_shared::SubscriptionTransferData>,
59    /// If set to true the entire phase is counted as a trial and the customer will not be charged for any fees.
60    pub trial: Option<bool>,
61    /// When the trial ends within the phase.
62    pub trial_end: Option<stripe_types::Timestamp>,
63}
64#[cfg(feature = "redact-generated-debug")]
65impl std::fmt::Debug for SubscriptionSchedulePhaseConfiguration {
66    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
67        f.debug_struct("SubscriptionSchedulePhaseConfiguration").finish_non_exhaustive()
68    }
69}
70#[doc(hidden)]
71pub struct SubscriptionSchedulePhaseConfigurationBuilder {
72    add_invoice_items: Option<Vec<stripe_shared::SubscriptionScheduleAddInvoiceItem>>,
73    application_fee_percent: Option<Option<f64>>,
74    automatic_tax: Option<Option<stripe_shared::SchedulesPhaseAutomaticTax>>,
75    billing_cycle_anchor: Option<Option<SubscriptionSchedulePhaseConfigurationBillingCycleAnchor>>,
76    billing_thresholds: Option<Option<stripe_shared::SubscriptionBillingThresholds>>,
77    collection_method: Option<Option<SubscriptionSchedulePhaseConfigurationCollectionMethod>>,
78    currency: Option<stripe_types::Currency>,
79    default_payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
80    default_tax_rates: Option<Option<Vec<stripe_shared::TaxRate>>>,
81    description: Option<Option<String>>,
82    discounts: Option<Vec<stripe_shared::StackableDiscountWithDiscountSettingsAndDiscountEnd>>,
83    end_date: Option<stripe_types::Timestamp>,
84    invoice_settings: Option<Option<stripe_shared::InvoiceSettingSubscriptionSchedulePhaseSetting>>,
85    items: Option<Vec<stripe_shared::SubscriptionScheduleConfigurationItem>>,
86    metadata: Option<Option<std::collections::HashMap<String, String>>>,
87    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
88    proration_behavior: Option<SubscriptionSchedulePhaseConfigurationProrationBehavior>,
89    start_date: Option<stripe_types::Timestamp>,
90    transfer_data: Option<Option<stripe_shared::SubscriptionTransferData>>,
91    trial: Option<Option<bool>>,
92    trial_end: Option<Option<stripe_types::Timestamp>>,
93}
94
95#[allow(
96    unused_variables,
97    irrefutable_let_patterns,
98    clippy::let_unit_value,
99    clippy::match_single_binding,
100    clippy::single_match
101)]
102const _: () = {
103    use miniserde::de::{Map, Visitor};
104    use miniserde::json::Value;
105    use miniserde::{Deserialize, Result, make_place};
106    use stripe_types::miniserde_helpers::FromValueOpt;
107    use stripe_types::{MapBuilder, ObjectDeser};
108
109    make_place!(Place);
110
111    impl Deserialize for SubscriptionSchedulePhaseConfiguration {
112        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
113            Place::new(out)
114        }
115    }
116
117    struct Builder<'a> {
118        out: &'a mut Option<SubscriptionSchedulePhaseConfiguration>,
119        builder: SubscriptionSchedulePhaseConfigurationBuilder,
120    }
121
122    impl Visitor for Place<SubscriptionSchedulePhaseConfiguration> {
123        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
124            Ok(Box::new(Builder {
125                out: &mut self.out,
126                builder: SubscriptionSchedulePhaseConfigurationBuilder::deser_default(),
127            }))
128        }
129    }
130
131    impl MapBuilder for SubscriptionSchedulePhaseConfigurationBuilder {
132        type Out = SubscriptionSchedulePhaseConfiguration;
133        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
134            Ok(match k {
135                "add_invoice_items" => Deserialize::begin(&mut self.add_invoice_items),
136                "application_fee_percent" => Deserialize::begin(&mut self.application_fee_percent),
137                "automatic_tax" => Deserialize::begin(&mut self.automatic_tax),
138                "billing_cycle_anchor" => Deserialize::begin(&mut self.billing_cycle_anchor),
139                "billing_thresholds" => Deserialize::begin(&mut self.billing_thresholds),
140                "collection_method" => Deserialize::begin(&mut self.collection_method),
141                "currency" => Deserialize::begin(&mut self.currency),
142                "default_payment_method" => Deserialize::begin(&mut self.default_payment_method),
143                "default_tax_rates" => Deserialize::begin(&mut self.default_tax_rates),
144                "description" => Deserialize::begin(&mut self.description),
145                "discounts" => Deserialize::begin(&mut self.discounts),
146                "end_date" => Deserialize::begin(&mut self.end_date),
147                "invoice_settings" => Deserialize::begin(&mut self.invoice_settings),
148                "items" => Deserialize::begin(&mut self.items),
149                "metadata" => Deserialize::begin(&mut self.metadata),
150                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
151                "proration_behavior" => Deserialize::begin(&mut self.proration_behavior),
152                "start_date" => Deserialize::begin(&mut self.start_date),
153                "transfer_data" => Deserialize::begin(&mut self.transfer_data),
154                "trial" => Deserialize::begin(&mut self.trial),
155                "trial_end" => Deserialize::begin(&mut self.trial_end),
156                _ => <dyn Visitor>::ignore(),
157            })
158        }
159
160        fn deser_default() -> Self {
161            Self {
162                add_invoice_items: None,
163                application_fee_percent: Some(None),
164                automatic_tax: Some(None),
165                billing_cycle_anchor: Some(None),
166                billing_thresholds: Some(None),
167                collection_method: Some(None),
168                currency: None,
169                default_payment_method: Some(None),
170                default_tax_rates: Some(None),
171                description: Some(None),
172                discounts: None,
173                end_date: None,
174                invoice_settings: Some(None),
175                items: None,
176                metadata: Some(None),
177                on_behalf_of: Some(None),
178                proration_behavior: None,
179                start_date: None,
180                transfer_data: Some(None),
181                trial: Some(None),
182                trial_end: Some(None),
183            }
184        }
185
186        fn take_out(&mut self) -> Option<Self::Out> {
187            let (
188                Some(add_invoice_items),
189                Some(application_fee_percent),
190                Some(automatic_tax),
191                Some(billing_cycle_anchor),
192                Some(billing_thresholds),
193                Some(collection_method),
194                Some(currency),
195                Some(default_payment_method),
196                Some(default_tax_rates),
197                Some(description),
198                Some(discounts),
199                Some(end_date),
200                Some(invoice_settings),
201                Some(items),
202                Some(metadata),
203                Some(on_behalf_of),
204                Some(proration_behavior),
205                Some(start_date),
206                Some(transfer_data),
207                Some(trial),
208                Some(trial_end),
209            ) = (
210                self.add_invoice_items.take(),
211                self.application_fee_percent,
212                self.automatic_tax.take(),
213                self.billing_cycle_anchor.take(),
214                self.billing_thresholds,
215                self.collection_method.take(),
216                self.currency.take(),
217                self.default_payment_method.take(),
218                self.default_tax_rates.take(),
219                self.description.take(),
220                self.discounts.take(),
221                self.end_date,
222                self.invoice_settings.take(),
223                self.items.take(),
224                self.metadata.take(),
225                self.on_behalf_of.take(),
226                self.proration_behavior.take(),
227                self.start_date,
228                self.transfer_data.take(),
229                self.trial,
230                self.trial_end,
231            )
232            else {
233                return None;
234            };
235            Some(Self::Out {
236                add_invoice_items,
237                application_fee_percent,
238                automatic_tax,
239                billing_cycle_anchor,
240                billing_thresholds,
241                collection_method,
242                currency,
243                default_payment_method,
244                default_tax_rates,
245                description,
246                discounts,
247                end_date,
248                invoice_settings,
249                items,
250                metadata,
251                on_behalf_of,
252                proration_behavior,
253                start_date,
254                transfer_data,
255                trial,
256                trial_end,
257            })
258        }
259    }
260
261    impl Map for Builder<'_> {
262        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
263            self.builder.key(k)
264        }
265
266        fn finish(&mut self) -> Result<()> {
267            *self.out = self.builder.take_out();
268            Ok(())
269        }
270    }
271
272    impl ObjectDeser for SubscriptionSchedulePhaseConfiguration {
273        type Builder = SubscriptionSchedulePhaseConfigurationBuilder;
274    }
275
276    impl FromValueOpt for SubscriptionSchedulePhaseConfiguration {
277        fn from_value(v: Value) -> Option<Self> {
278            let Value::Object(obj) = v else {
279                return None;
280            };
281            let mut b = SubscriptionSchedulePhaseConfigurationBuilder::deser_default();
282            for (k, v) in obj {
283                match k.as_str() {
284                    "add_invoice_items" => b.add_invoice_items = FromValueOpt::from_value(v),
285                    "application_fee_percent" => {
286                        b.application_fee_percent = FromValueOpt::from_value(v)
287                    }
288                    "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
289                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
290                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
291                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
292                    "currency" => b.currency = FromValueOpt::from_value(v),
293                    "default_payment_method" => {
294                        b.default_payment_method = FromValueOpt::from_value(v)
295                    }
296                    "default_tax_rates" => b.default_tax_rates = FromValueOpt::from_value(v),
297                    "description" => b.description = FromValueOpt::from_value(v),
298                    "discounts" => b.discounts = FromValueOpt::from_value(v),
299                    "end_date" => b.end_date = FromValueOpt::from_value(v),
300                    "invoice_settings" => b.invoice_settings = FromValueOpt::from_value(v),
301                    "items" => b.items = FromValueOpt::from_value(v),
302                    "metadata" => b.metadata = FromValueOpt::from_value(v),
303                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
304                    "proration_behavior" => b.proration_behavior = FromValueOpt::from_value(v),
305                    "start_date" => b.start_date = FromValueOpt::from_value(v),
306                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
307                    "trial" => b.trial = FromValueOpt::from_value(v),
308                    "trial_end" => b.trial_end = FromValueOpt::from_value(v),
309                    _ => {}
310                }
311            }
312            b.take_out()
313        }
314    }
315};
316/// Possible values are `phase_start` or `automatic`.
317/// If `phase_start` then billing cycle anchor of the subscription is set to the start of the phase when entering the phase.
318/// If `automatic` then the billing cycle anchor is automatically modified as needed when entering the phase.
319/// For more information, see the billing cycle [documentation](https://docs.stripe.com/billing/subscriptions/billing-cycle).
320#[derive(Clone, Eq, PartialEq)]
321#[non_exhaustive]
322pub enum SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
323    Automatic,
324    PhaseStart,
325    /// An unrecognized value from Stripe. Should not be used as a request parameter.
326    Unknown(String),
327}
328impl SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
329    pub fn as_str(&self) -> &str {
330        use SubscriptionSchedulePhaseConfigurationBillingCycleAnchor::*;
331        match self {
332            Automatic => "automatic",
333            PhaseStart => "phase_start",
334            Unknown(v) => v,
335        }
336    }
337}
338
339impl std::str::FromStr for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
340    type Err = std::convert::Infallible;
341    fn from_str(s: &str) -> Result<Self, Self::Err> {
342        use SubscriptionSchedulePhaseConfigurationBillingCycleAnchor::*;
343        match s {
344            "automatic" => Ok(Automatic),
345            "phase_start" => Ok(PhaseStart),
346            v => {
347                tracing::warn!(
348                    "Unknown value '{}' for enum '{}'",
349                    v,
350                    "SubscriptionSchedulePhaseConfigurationBillingCycleAnchor"
351                );
352                Ok(Unknown(v.to_owned()))
353            }
354        }
355    }
356}
357impl std::fmt::Display for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
358    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
359        f.write_str(self.as_str())
360    }
361}
362
363#[cfg(not(feature = "redact-generated-debug"))]
364impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
365    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
366        f.write_str(self.as_str())
367    }
368}
369#[cfg(feature = "redact-generated-debug")]
370impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
371    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
372        f.debug_struct(stringify!(SubscriptionSchedulePhaseConfigurationBillingCycleAnchor))
373            .finish_non_exhaustive()
374    }
375}
376#[cfg(feature = "serialize")]
377impl serde::Serialize for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
378    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
379    where
380        S: serde::Serializer,
381    {
382        serializer.serialize_str(self.as_str())
383    }
384}
385impl miniserde::Deserialize for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
386    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
387        crate::Place::new(out)
388    }
389}
390
391impl miniserde::de::Visitor
392    for crate::Place<SubscriptionSchedulePhaseConfigurationBillingCycleAnchor>
393{
394    fn string(&mut self, s: &str) -> miniserde::Result<()> {
395        use std::str::FromStr;
396        self.out = Some(
397            SubscriptionSchedulePhaseConfigurationBillingCycleAnchor::from_str(s)
398                .expect("infallible"),
399        );
400        Ok(())
401    }
402}
403
404stripe_types::impl_from_val_with_from_str!(
405    SubscriptionSchedulePhaseConfigurationBillingCycleAnchor
406);
407#[cfg(feature = "deserialize")]
408impl<'de> serde::Deserialize<'de> for SubscriptionSchedulePhaseConfigurationBillingCycleAnchor {
409    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
410        use std::str::FromStr;
411        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
412        Ok(Self::from_str(&s).expect("infallible"))
413    }
414}
415/// Either `charge_automatically`, or `send_invoice`.
416/// 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.
417/// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
418#[derive(Clone, Eq, PartialEq)]
419#[non_exhaustive]
420pub enum SubscriptionSchedulePhaseConfigurationCollectionMethod {
421    ChargeAutomatically,
422    SendInvoice,
423    /// An unrecognized value from Stripe. Should not be used as a request parameter.
424    Unknown(String),
425}
426impl SubscriptionSchedulePhaseConfigurationCollectionMethod {
427    pub fn as_str(&self) -> &str {
428        use SubscriptionSchedulePhaseConfigurationCollectionMethod::*;
429        match self {
430            ChargeAutomatically => "charge_automatically",
431            SendInvoice => "send_invoice",
432            Unknown(v) => v,
433        }
434    }
435}
436
437impl std::str::FromStr for SubscriptionSchedulePhaseConfigurationCollectionMethod {
438    type Err = std::convert::Infallible;
439    fn from_str(s: &str) -> Result<Self, Self::Err> {
440        use SubscriptionSchedulePhaseConfigurationCollectionMethod::*;
441        match s {
442            "charge_automatically" => Ok(ChargeAutomatically),
443            "send_invoice" => Ok(SendInvoice),
444            v => {
445                tracing::warn!(
446                    "Unknown value '{}' for enum '{}'",
447                    v,
448                    "SubscriptionSchedulePhaseConfigurationCollectionMethod"
449                );
450                Ok(Unknown(v.to_owned()))
451            }
452        }
453    }
454}
455impl std::fmt::Display for SubscriptionSchedulePhaseConfigurationCollectionMethod {
456    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
457        f.write_str(self.as_str())
458    }
459}
460
461#[cfg(not(feature = "redact-generated-debug"))]
462impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationCollectionMethod {
463    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
464        f.write_str(self.as_str())
465    }
466}
467#[cfg(feature = "redact-generated-debug")]
468impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationCollectionMethod {
469    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
470        f.debug_struct(stringify!(SubscriptionSchedulePhaseConfigurationCollectionMethod))
471            .finish_non_exhaustive()
472    }
473}
474#[cfg(feature = "serialize")]
475impl serde::Serialize for SubscriptionSchedulePhaseConfigurationCollectionMethod {
476    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
477    where
478        S: serde::Serializer,
479    {
480        serializer.serialize_str(self.as_str())
481    }
482}
483impl miniserde::Deserialize for SubscriptionSchedulePhaseConfigurationCollectionMethod {
484    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
485        crate::Place::new(out)
486    }
487}
488
489impl miniserde::de::Visitor
490    for crate::Place<SubscriptionSchedulePhaseConfigurationCollectionMethod>
491{
492    fn string(&mut self, s: &str) -> miniserde::Result<()> {
493        use std::str::FromStr;
494        self.out = Some(
495            SubscriptionSchedulePhaseConfigurationCollectionMethod::from_str(s)
496                .expect("infallible"),
497        );
498        Ok(())
499    }
500}
501
502stripe_types::impl_from_val_with_from_str!(SubscriptionSchedulePhaseConfigurationCollectionMethod);
503#[cfg(feature = "deserialize")]
504impl<'de> serde::Deserialize<'de> for SubscriptionSchedulePhaseConfigurationCollectionMethod {
505    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
506        use std::str::FromStr;
507        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
508        Ok(Self::from_str(&s).expect("infallible"))
509    }
510}
511/// When transitioning phases, controls how prorations are handled (if any).
512/// Possible values are `create_prorations`, `none`, and `always_invoice`.
513#[derive(Clone, Eq, PartialEq)]
514#[non_exhaustive]
515pub enum SubscriptionSchedulePhaseConfigurationProrationBehavior {
516    AlwaysInvoice,
517    CreateProrations,
518    None,
519    /// An unrecognized value from Stripe. Should not be used as a request parameter.
520    Unknown(String),
521}
522impl SubscriptionSchedulePhaseConfigurationProrationBehavior {
523    pub fn as_str(&self) -> &str {
524        use SubscriptionSchedulePhaseConfigurationProrationBehavior::*;
525        match self {
526            AlwaysInvoice => "always_invoice",
527            CreateProrations => "create_prorations",
528            None => "none",
529            Unknown(v) => v,
530        }
531    }
532}
533
534impl std::str::FromStr for SubscriptionSchedulePhaseConfigurationProrationBehavior {
535    type Err = std::convert::Infallible;
536    fn from_str(s: &str) -> Result<Self, Self::Err> {
537        use SubscriptionSchedulePhaseConfigurationProrationBehavior::*;
538        match s {
539            "always_invoice" => Ok(AlwaysInvoice),
540            "create_prorations" => Ok(CreateProrations),
541            "none" => Ok(None),
542            v => {
543                tracing::warn!(
544                    "Unknown value '{}' for enum '{}'",
545                    v,
546                    "SubscriptionSchedulePhaseConfigurationProrationBehavior"
547                );
548                Ok(Unknown(v.to_owned()))
549            }
550        }
551    }
552}
553impl std::fmt::Display for SubscriptionSchedulePhaseConfigurationProrationBehavior {
554    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
555        f.write_str(self.as_str())
556    }
557}
558
559#[cfg(not(feature = "redact-generated-debug"))]
560impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationProrationBehavior {
561    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
562        f.write_str(self.as_str())
563    }
564}
565#[cfg(feature = "redact-generated-debug")]
566impl std::fmt::Debug for SubscriptionSchedulePhaseConfigurationProrationBehavior {
567    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
568        f.debug_struct(stringify!(SubscriptionSchedulePhaseConfigurationProrationBehavior))
569            .finish_non_exhaustive()
570    }
571}
572#[cfg(feature = "serialize")]
573impl serde::Serialize for SubscriptionSchedulePhaseConfigurationProrationBehavior {
574    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
575    where
576        S: serde::Serializer,
577    {
578        serializer.serialize_str(self.as_str())
579    }
580}
581impl miniserde::Deserialize for SubscriptionSchedulePhaseConfigurationProrationBehavior {
582    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
583        crate::Place::new(out)
584    }
585}
586
587impl miniserde::de::Visitor
588    for crate::Place<SubscriptionSchedulePhaseConfigurationProrationBehavior>
589{
590    fn string(&mut self, s: &str) -> miniserde::Result<()> {
591        use std::str::FromStr;
592        self.out = Some(
593            SubscriptionSchedulePhaseConfigurationProrationBehavior::from_str(s)
594                .expect("infallible"),
595        );
596        Ok(())
597    }
598}
599
600stripe_types::impl_from_val_with_from_str!(SubscriptionSchedulePhaseConfigurationProrationBehavior);
601#[cfg(feature = "deserialize")]
602impl<'de> serde::Deserialize<'de> for SubscriptionSchedulePhaseConfigurationProrationBehavior {
603    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
604        use std::str::FromStr;
605        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
606        Ok(Self::from_str(&s).expect("infallible"))
607    }
608}