Skip to main content

stripe_shared/
plan.rs

1/// You can now model subscriptions more flexibly using the [Prices API](https://api.stripe.com#prices).
2/// It replaces the Plans API and is backwards compatible to simplify your migration.
3///
4/// Plans define the base price, currency, and billing cycle for recurring purchases of products.
5/// [Products](https://api.stripe.com#products) help you track inventory or provisioning, and plans help you track pricing.
6/// Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans.
7/// This approach lets you change prices without having to change your provisioning scheme.
8///
9/// For example, you might have a single "gold" product that has plans for $10/month, $100/year, €9/month, and €90/year.
10///
11/// Related guides: [Set up a subscription](https://docs.stripe.com/billing/subscriptions/set-up-subscription) and more about [products and prices](https://docs.stripe.com/products-prices/overview).
12///
13/// For more details see <<https://stripe.com/docs/api/plans/object>>.
14#[derive(Clone)]
15#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
16#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
17pub struct Plan {
18    /// Whether the plan can be used for new purchases.
19    pub active: bool,
20    /// The unit amount in cents (or local equivalent) to be charged, represented as a whole integer if possible.
21    /// Only set if `billing_scheme=per_unit`.
22    pub amount: Option<i64>,
23    /// The unit amount in cents (or local equivalent) to be charged, represented as a decimal string with at most 12 decimal places.
24    /// Only set if `billing_scheme=per_unit`.
25    pub amount_decimal: Option<String>,
26    /// Describes how to compute the price per period.
27    /// Either `per_unit` or `tiered`.
28    /// `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`).
29    /// `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
30    pub billing_scheme: stripe_shared::PlanBillingScheme,
31    /// Time at which the object was created. Measured in seconds since the Unix epoch.
32    pub created: stripe_types::Timestamp,
33    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
34    /// Must be a [supported currency](https://stripe.com/docs/currencies).
35    pub currency: stripe_types::Currency,
36    /// Unique identifier for the object.
37    pub id: stripe_shared::PlanId,
38    /// The frequency at which a subscription is billed. One of `day`, `week`, `month` or `year`.
39    pub interval: stripe_shared::PlanInterval,
40    /// The number of intervals (specified in the `interval` attribute) between subscription billings.
41    /// For example, `interval=month` and `interval_count=3` bills every 3 months.
42    pub interval_count: u64,
43    /// If the object exists in live mode, the value is `true`.
44    /// If the object exists in test mode, the value is `false`.
45    pub livemode: bool,
46    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
47    /// This can be useful for storing additional information about the object in a structured format.
48    pub metadata: Option<std::collections::HashMap<String, String>>,
49    /// The meter tracking the usage of a metered price
50    pub meter: Option<String>,
51    /// A brief description of the plan, hidden from customers.
52    pub nickname: Option<String>,
53    /// The product whose pricing this plan determines.
54    pub product: Option<stripe_types::Expandable<stripe_shared::Product>>,
55    /// Each element represents a pricing tier.
56    /// This parameter requires `billing_scheme` to be set to `tiered`.
57    /// See also the documentation for `billing_scheme`.
58    pub tiers: Option<Vec<stripe_shared::PlanTier>>,
59    /// Defines if the tiering price should be `graduated` or `volume` based.
60    /// In `volume`-based tiering, the maximum quantity within a period determines the per unit price.
61    /// In `graduated` tiering, pricing can change as the quantity grows.
62    pub tiers_mode: Option<stripe_shared::PlanTiersMode>,
63    /// Apply a transformation to the reported usage or set quantity before computing the amount billed.
64    /// Cannot be combined with `tiers`.
65    pub transform_usage: Option<stripe_shared::TransformUsage>,
66    /// Default number of trial days when subscribing a customer to this plan using [`trial_from_plan=true`](https://docs.stripe.com/api#create_subscription-trial_from_plan).
67    pub trial_period_days: Option<u32>,
68    /// Configures how the quantity per period should be determined.
69    /// Can be either `metered` or `licensed`.
70    /// `licensed` automatically bills the `quantity` set when adding it to a subscription.
71    /// `metered` aggregates the total usage based on usage records.
72    /// Defaults to `licensed`.
73    pub usage_type: stripe_shared::PlanUsageType,
74}
75#[cfg(feature = "redact-generated-debug")]
76impl std::fmt::Debug for Plan {
77    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
78        f.debug_struct("Plan").finish_non_exhaustive()
79    }
80}
81#[doc(hidden)]
82pub struct PlanBuilder {
83    active: Option<bool>,
84    amount: Option<Option<i64>>,
85    amount_decimal: Option<Option<String>>,
86    billing_scheme: Option<stripe_shared::PlanBillingScheme>,
87    created: Option<stripe_types::Timestamp>,
88    currency: Option<stripe_types::Currency>,
89    id: Option<stripe_shared::PlanId>,
90    interval: Option<stripe_shared::PlanInterval>,
91    interval_count: Option<u64>,
92    livemode: Option<bool>,
93    metadata: Option<Option<std::collections::HashMap<String, String>>>,
94    meter: Option<Option<String>>,
95    nickname: Option<Option<String>>,
96    product: Option<Option<stripe_types::Expandable<stripe_shared::Product>>>,
97    tiers: Option<Option<Vec<stripe_shared::PlanTier>>>,
98    tiers_mode: Option<Option<stripe_shared::PlanTiersMode>>,
99    transform_usage: Option<Option<stripe_shared::TransformUsage>>,
100    trial_period_days: Option<Option<u32>>,
101    usage_type: Option<stripe_shared::PlanUsageType>,
102}
103
104#[allow(
105    unused_variables,
106    irrefutable_let_patterns,
107    clippy::let_unit_value,
108    clippy::match_single_binding,
109    clippy::single_match
110)]
111const _: () = {
112    use miniserde::de::{Map, Visitor};
113    use miniserde::json::Value;
114    use miniserde::{Deserialize, Result, make_place};
115    use stripe_types::miniserde_helpers::FromValueOpt;
116    use stripe_types::{MapBuilder, ObjectDeser};
117
118    make_place!(Place);
119
120    impl Deserialize for Plan {
121        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
122            Place::new(out)
123        }
124    }
125
126    struct Builder<'a> {
127        out: &'a mut Option<Plan>,
128        builder: PlanBuilder,
129    }
130
131    impl Visitor for Place<Plan> {
132        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
133            Ok(Box::new(Builder { out: &mut self.out, builder: PlanBuilder::deser_default() }))
134        }
135    }
136
137    impl MapBuilder for PlanBuilder {
138        type Out = Plan;
139        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
140            Ok(match k {
141                "active" => Deserialize::begin(&mut self.active),
142                "amount" => Deserialize::begin(&mut self.amount),
143                "amount_decimal" => Deserialize::begin(&mut self.amount_decimal),
144                "billing_scheme" => Deserialize::begin(&mut self.billing_scheme),
145                "created" => Deserialize::begin(&mut self.created),
146                "currency" => Deserialize::begin(&mut self.currency),
147                "id" => Deserialize::begin(&mut self.id),
148                "interval" => Deserialize::begin(&mut self.interval),
149                "interval_count" => Deserialize::begin(&mut self.interval_count),
150                "livemode" => Deserialize::begin(&mut self.livemode),
151                "metadata" => Deserialize::begin(&mut self.metadata),
152                "meter" => Deserialize::begin(&mut self.meter),
153                "nickname" => Deserialize::begin(&mut self.nickname),
154                "product" => Deserialize::begin(&mut self.product),
155                "tiers" => Deserialize::begin(&mut self.tiers),
156                "tiers_mode" => Deserialize::begin(&mut self.tiers_mode),
157                "transform_usage" => Deserialize::begin(&mut self.transform_usage),
158                "trial_period_days" => Deserialize::begin(&mut self.trial_period_days),
159                "usage_type" => Deserialize::begin(&mut self.usage_type),
160                _ => <dyn Visitor>::ignore(),
161            })
162        }
163
164        fn deser_default() -> Self {
165            Self {
166                active: None,
167                amount: Some(None),
168                amount_decimal: Some(None),
169                billing_scheme: None,
170                created: None,
171                currency: None,
172                id: None,
173                interval: None,
174                interval_count: None,
175                livemode: None,
176                metadata: Some(None),
177                meter: Some(None),
178                nickname: Some(None),
179                product: Some(None),
180                tiers: Some(None),
181                tiers_mode: Some(None),
182                transform_usage: Some(None),
183                trial_period_days: Some(None),
184                usage_type: None,
185            }
186        }
187
188        fn take_out(&mut self) -> Option<Self::Out> {
189            let (
190                Some(active),
191                Some(amount),
192                Some(amount_decimal),
193                Some(billing_scheme),
194                Some(created),
195                Some(currency),
196                Some(id),
197                Some(interval),
198                Some(interval_count),
199                Some(livemode),
200                Some(metadata),
201                Some(meter),
202                Some(nickname),
203                Some(product),
204                Some(tiers),
205                Some(tiers_mode),
206                Some(transform_usage),
207                Some(trial_period_days),
208                Some(usage_type),
209            ) = (
210                self.active,
211                self.amount,
212                self.amount_decimal.take(),
213                self.billing_scheme.take(),
214                self.created,
215                self.currency.take(),
216                self.id.take(),
217                self.interval.take(),
218                self.interval_count,
219                self.livemode,
220                self.metadata.take(),
221                self.meter.take(),
222                self.nickname.take(),
223                self.product.take(),
224                self.tiers.take(),
225                self.tiers_mode.take(),
226                self.transform_usage.take(),
227                self.trial_period_days,
228                self.usage_type.take(),
229            )
230            else {
231                return None;
232            };
233            Some(Self::Out {
234                active,
235                amount,
236                amount_decimal,
237                billing_scheme,
238                created,
239                currency,
240                id,
241                interval,
242                interval_count,
243                livemode,
244                metadata,
245                meter,
246                nickname,
247                product,
248                tiers,
249                tiers_mode,
250                transform_usage,
251                trial_period_days,
252                usage_type,
253            })
254        }
255    }
256
257    impl Map for Builder<'_> {
258        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
259            self.builder.key(k)
260        }
261
262        fn finish(&mut self) -> Result<()> {
263            *self.out = self.builder.take_out();
264            Ok(())
265        }
266    }
267
268    impl ObjectDeser for Plan {
269        type Builder = PlanBuilder;
270    }
271
272    impl FromValueOpt for Plan {
273        fn from_value(v: Value) -> Option<Self> {
274            let Value::Object(obj) = v else {
275                return None;
276            };
277            let mut b = PlanBuilder::deser_default();
278            for (k, v) in obj {
279                match k.as_str() {
280                    "active" => b.active = FromValueOpt::from_value(v),
281                    "amount" => b.amount = FromValueOpt::from_value(v),
282                    "amount_decimal" => b.amount_decimal = FromValueOpt::from_value(v),
283                    "billing_scheme" => b.billing_scheme = FromValueOpt::from_value(v),
284                    "created" => b.created = FromValueOpt::from_value(v),
285                    "currency" => b.currency = FromValueOpt::from_value(v),
286                    "id" => b.id = FromValueOpt::from_value(v),
287                    "interval" => b.interval = FromValueOpt::from_value(v),
288                    "interval_count" => b.interval_count = FromValueOpt::from_value(v),
289                    "livemode" => b.livemode = FromValueOpt::from_value(v),
290                    "metadata" => b.metadata = FromValueOpt::from_value(v),
291                    "meter" => b.meter = FromValueOpt::from_value(v),
292                    "nickname" => b.nickname = FromValueOpt::from_value(v),
293                    "product" => b.product = FromValueOpt::from_value(v),
294                    "tiers" => b.tiers = FromValueOpt::from_value(v),
295                    "tiers_mode" => b.tiers_mode = FromValueOpt::from_value(v),
296                    "transform_usage" => b.transform_usage = FromValueOpt::from_value(v),
297                    "trial_period_days" => b.trial_period_days = FromValueOpt::from_value(v),
298                    "usage_type" => b.usage_type = FromValueOpt::from_value(v),
299                    _ => {}
300                }
301            }
302            b.take_out()
303        }
304    }
305};
306#[cfg(feature = "serialize")]
307impl serde::Serialize for Plan {
308    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
309        use serde::ser::SerializeStruct;
310        let mut s = s.serialize_struct("Plan", 20)?;
311        s.serialize_field("active", &self.active)?;
312        s.serialize_field("amount", &self.amount)?;
313        s.serialize_field("amount_decimal", &self.amount_decimal)?;
314        s.serialize_field("billing_scheme", &self.billing_scheme)?;
315        s.serialize_field("created", &self.created)?;
316        s.serialize_field("currency", &self.currency)?;
317        s.serialize_field("id", &self.id)?;
318        s.serialize_field("interval", &self.interval)?;
319        s.serialize_field("interval_count", &self.interval_count)?;
320        s.serialize_field("livemode", &self.livemode)?;
321        s.serialize_field("metadata", &self.metadata)?;
322        s.serialize_field("meter", &self.meter)?;
323        s.serialize_field("nickname", &self.nickname)?;
324        s.serialize_field("product", &self.product)?;
325        s.serialize_field("tiers", &self.tiers)?;
326        s.serialize_field("tiers_mode", &self.tiers_mode)?;
327        s.serialize_field("transform_usage", &self.transform_usage)?;
328        s.serialize_field("trial_period_days", &self.trial_period_days)?;
329        s.serialize_field("usage_type", &self.usage_type)?;
330
331        s.serialize_field("object", "plan")?;
332        s.end()
333    }
334}
335impl stripe_types::Object for Plan {
336    type Id = stripe_shared::PlanId;
337    fn id(&self) -> &Self::Id {
338        &self.id
339    }
340
341    fn into_id(self) -> Self::Id {
342        self.id
343    }
344}
345stripe_types::def_id!(PlanId);
346#[derive(Clone, Eq, PartialEq)]
347#[non_exhaustive]
348pub enum PlanBillingScheme {
349    PerUnit,
350    Tiered,
351    /// An unrecognized value from Stripe. Should not be used as a request parameter.
352    Unknown(String),
353}
354impl PlanBillingScheme {
355    pub fn as_str(&self) -> &str {
356        use PlanBillingScheme::*;
357        match self {
358            PerUnit => "per_unit",
359            Tiered => "tiered",
360            Unknown(v) => v,
361        }
362    }
363}
364
365impl std::str::FromStr for PlanBillingScheme {
366    type Err = std::convert::Infallible;
367    fn from_str(s: &str) -> Result<Self, Self::Err> {
368        use PlanBillingScheme::*;
369        match s {
370            "per_unit" => Ok(PerUnit),
371            "tiered" => Ok(Tiered),
372            v => {
373                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PlanBillingScheme");
374                Ok(Unknown(v.to_owned()))
375            }
376        }
377    }
378}
379impl std::fmt::Display for PlanBillingScheme {
380    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
381        f.write_str(self.as_str())
382    }
383}
384
385#[cfg(not(feature = "redact-generated-debug"))]
386impl std::fmt::Debug for PlanBillingScheme {
387    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
388        f.write_str(self.as_str())
389    }
390}
391#[cfg(feature = "redact-generated-debug")]
392impl std::fmt::Debug for PlanBillingScheme {
393    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
394        f.debug_struct(stringify!(PlanBillingScheme)).finish_non_exhaustive()
395    }
396}
397impl serde::Serialize for PlanBillingScheme {
398    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
399    where
400        S: serde::Serializer,
401    {
402        serializer.serialize_str(self.as_str())
403    }
404}
405impl miniserde::Deserialize for PlanBillingScheme {
406    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
407        crate::Place::new(out)
408    }
409}
410
411impl miniserde::de::Visitor for crate::Place<PlanBillingScheme> {
412    fn string(&mut self, s: &str) -> miniserde::Result<()> {
413        use std::str::FromStr;
414        self.out = Some(PlanBillingScheme::from_str(s).expect("infallible"));
415        Ok(())
416    }
417}
418
419stripe_types::impl_from_val_with_from_str!(PlanBillingScheme);
420#[cfg(feature = "deserialize")]
421impl<'de> serde::Deserialize<'de> for PlanBillingScheme {
422    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
423        use std::str::FromStr;
424        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
425        Ok(Self::from_str(&s).expect("infallible"))
426    }
427}
428#[derive(Clone, Eq, PartialEq)]
429#[non_exhaustive]
430pub enum PlanInterval {
431    Day,
432    Month,
433    Week,
434    Year,
435    /// An unrecognized value from Stripe. Should not be used as a request parameter.
436    Unknown(String),
437}
438impl PlanInterval {
439    pub fn as_str(&self) -> &str {
440        use PlanInterval::*;
441        match self {
442            Day => "day",
443            Month => "month",
444            Week => "week",
445            Year => "year",
446            Unknown(v) => v,
447        }
448    }
449}
450
451impl std::str::FromStr for PlanInterval {
452    type Err = std::convert::Infallible;
453    fn from_str(s: &str) -> Result<Self, Self::Err> {
454        use PlanInterval::*;
455        match s {
456            "day" => Ok(Day),
457            "month" => Ok(Month),
458            "week" => Ok(Week),
459            "year" => Ok(Year),
460            v => {
461                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PlanInterval");
462                Ok(Unknown(v.to_owned()))
463            }
464        }
465    }
466}
467impl std::fmt::Display for PlanInterval {
468    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
469        f.write_str(self.as_str())
470    }
471}
472
473#[cfg(not(feature = "redact-generated-debug"))]
474impl std::fmt::Debug for PlanInterval {
475    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
476        f.write_str(self.as_str())
477    }
478}
479#[cfg(feature = "redact-generated-debug")]
480impl std::fmt::Debug for PlanInterval {
481    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
482        f.debug_struct(stringify!(PlanInterval)).finish_non_exhaustive()
483    }
484}
485impl serde::Serialize for PlanInterval {
486    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
487    where
488        S: serde::Serializer,
489    {
490        serializer.serialize_str(self.as_str())
491    }
492}
493impl miniserde::Deserialize for PlanInterval {
494    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
495        crate::Place::new(out)
496    }
497}
498
499impl miniserde::de::Visitor for crate::Place<PlanInterval> {
500    fn string(&mut self, s: &str) -> miniserde::Result<()> {
501        use std::str::FromStr;
502        self.out = Some(PlanInterval::from_str(s).expect("infallible"));
503        Ok(())
504    }
505}
506
507stripe_types::impl_from_val_with_from_str!(PlanInterval);
508#[cfg(feature = "deserialize")]
509impl<'de> serde::Deserialize<'de> for PlanInterval {
510    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
511        use std::str::FromStr;
512        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
513        Ok(Self::from_str(&s).expect("infallible"))
514    }
515}
516#[derive(Clone, Eq, PartialEq)]
517#[non_exhaustive]
518pub enum PlanTiersMode {
519    Graduated,
520    Volume,
521    /// An unrecognized value from Stripe. Should not be used as a request parameter.
522    Unknown(String),
523}
524impl PlanTiersMode {
525    pub fn as_str(&self) -> &str {
526        use PlanTiersMode::*;
527        match self {
528            Graduated => "graduated",
529            Volume => "volume",
530            Unknown(v) => v,
531        }
532    }
533}
534
535impl std::str::FromStr for PlanTiersMode {
536    type Err = std::convert::Infallible;
537    fn from_str(s: &str) -> Result<Self, Self::Err> {
538        use PlanTiersMode::*;
539        match s {
540            "graduated" => Ok(Graduated),
541            "volume" => Ok(Volume),
542            v => {
543                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PlanTiersMode");
544                Ok(Unknown(v.to_owned()))
545            }
546        }
547    }
548}
549impl std::fmt::Display for PlanTiersMode {
550    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
551        f.write_str(self.as_str())
552    }
553}
554
555#[cfg(not(feature = "redact-generated-debug"))]
556impl std::fmt::Debug for PlanTiersMode {
557    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
558        f.write_str(self.as_str())
559    }
560}
561#[cfg(feature = "redact-generated-debug")]
562impl std::fmt::Debug for PlanTiersMode {
563    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
564        f.debug_struct(stringify!(PlanTiersMode)).finish_non_exhaustive()
565    }
566}
567impl serde::Serialize for PlanTiersMode {
568    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
569    where
570        S: serde::Serializer,
571    {
572        serializer.serialize_str(self.as_str())
573    }
574}
575impl miniserde::Deserialize for PlanTiersMode {
576    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
577        crate::Place::new(out)
578    }
579}
580
581impl miniserde::de::Visitor for crate::Place<PlanTiersMode> {
582    fn string(&mut self, s: &str) -> miniserde::Result<()> {
583        use std::str::FromStr;
584        self.out = Some(PlanTiersMode::from_str(s).expect("infallible"));
585        Ok(())
586    }
587}
588
589stripe_types::impl_from_val_with_from_str!(PlanTiersMode);
590#[cfg(feature = "deserialize")]
591impl<'de> serde::Deserialize<'de> for PlanTiersMode {
592    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
593        use std::str::FromStr;
594        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
595        Ok(Self::from_str(&s).expect("infallible"))
596    }
597}
598#[derive(Clone, Eq, PartialEq)]
599#[non_exhaustive]
600pub enum PlanUsageType {
601    Licensed,
602    Metered,
603    /// An unrecognized value from Stripe. Should not be used as a request parameter.
604    Unknown(String),
605}
606impl PlanUsageType {
607    pub fn as_str(&self) -> &str {
608        use PlanUsageType::*;
609        match self {
610            Licensed => "licensed",
611            Metered => "metered",
612            Unknown(v) => v,
613        }
614    }
615}
616
617impl std::str::FromStr for PlanUsageType {
618    type Err = std::convert::Infallible;
619    fn from_str(s: &str) -> Result<Self, Self::Err> {
620        use PlanUsageType::*;
621        match s {
622            "licensed" => Ok(Licensed),
623            "metered" => Ok(Metered),
624            v => {
625                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PlanUsageType");
626                Ok(Unknown(v.to_owned()))
627            }
628        }
629    }
630}
631impl std::fmt::Display for PlanUsageType {
632    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
633        f.write_str(self.as_str())
634    }
635}
636
637#[cfg(not(feature = "redact-generated-debug"))]
638impl std::fmt::Debug for PlanUsageType {
639    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
640        f.write_str(self.as_str())
641    }
642}
643#[cfg(feature = "redact-generated-debug")]
644impl std::fmt::Debug for PlanUsageType {
645    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
646        f.debug_struct(stringify!(PlanUsageType)).finish_non_exhaustive()
647    }
648}
649impl serde::Serialize for PlanUsageType {
650    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
651    where
652        S: serde::Serializer,
653    {
654        serializer.serialize_str(self.as_str())
655    }
656}
657impl miniserde::Deserialize for PlanUsageType {
658    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
659        crate::Place::new(out)
660    }
661}
662
663impl miniserde::de::Visitor for crate::Place<PlanUsageType> {
664    fn string(&mut self, s: &str) -> miniserde::Result<()> {
665        use std::str::FromStr;
666        self.out = Some(PlanUsageType::from_str(s).expect("infallible"));
667        Ok(())
668    }
669}
670
671stripe_types::impl_from_val_with_from_str!(PlanUsageType);
672#[cfg(feature = "deserialize")]
673impl<'de> serde::Deserialize<'de> for PlanUsageType {
674    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
675        use std::str::FromStr;
676        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
677        Ok(Self::from_str(&s).expect("infallible"))
678    }
679}