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