stripe_shared/
price.rs

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