stripe_shared/
billing_credit_grants_resource_scope.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BillingCreditGrantsResourceScope {
5    /// The price type that credit grants can apply to.
6    /// We currently only support the `metered` price type.
7    /// This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them.
8    /// Cannot be used in combination with `prices`.
9    pub price_type: Option<BillingCreditGrantsResourceScopePriceType>,
10    /// The prices that credit grants can apply to.
11    /// We currently only support `metered` prices.
12    /// This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them.
13    /// Cannot be used in combination with `price_type`.
14    pub prices: Option<Vec<stripe_shared::BillingCreditGrantsResourceApplicablePrice>>,
15}
16#[doc(hidden)]
17pub struct BillingCreditGrantsResourceScopeBuilder {
18    price_type: Option<Option<BillingCreditGrantsResourceScopePriceType>>,
19    prices: Option<Option<Vec<stripe_shared::BillingCreditGrantsResourceApplicablePrice>>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for BillingCreditGrantsResourceScope {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<BillingCreditGrantsResourceScope>,
46        builder: BillingCreditGrantsResourceScopeBuilder,
47    }
48
49    impl Visitor for Place<BillingCreditGrantsResourceScope> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: BillingCreditGrantsResourceScopeBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for BillingCreditGrantsResourceScopeBuilder {
59        type Out = BillingCreditGrantsResourceScope;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "price_type" => Deserialize::begin(&mut self.price_type),
63                "prices" => Deserialize::begin(&mut self.prices),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self { price_type: Deserialize::default(), prices: Deserialize::default() }
70        }
71
72        fn take_out(&mut self) -> Option<Self::Out> {
73            let (Some(price_type), Some(prices)) = (self.price_type, self.prices.take()) else {
74                return None;
75            };
76            Some(Self::Out { price_type, prices })
77        }
78    }
79
80    impl Map for Builder<'_> {
81        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
82            self.builder.key(k)
83        }
84
85        fn finish(&mut self) -> Result<()> {
86            *self.out = self.builder.take_out();
87            Ok(())
88        }
89    }
90
91    impl ObjectDeser for BillingCreditGrantsResourceScope {
92        type Builder = BillingCreditGrantsResourceScopeBuilder;
93    }
94
95    impl FromValueOpt for BillingCreditGrantsResourceScope {
96        fn from_value(v: Value) -> Option<Self> {
97            let Value::Object(obj) = v else {
98                return None;
99            };
100            let mut b = BillingCreditGrantsResourceScopeBuilder::deser_default();
101            for (k, v) in obj {
102                match k.as_str() {
103                    "price_type" => b.price_type = FromValueOpt::from_value(v),
104                    "prices" => b.prices = FromValueOpt::from_value(v),
105                    _ => {}
106                }
107            }
108            b.take_out()
109        }
110    }
111};
112/// The price type that credit grants can apply to.
113/// We currently only support the `metered` price type.
114/// This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them.
115/// Cannot be used in combination with `prices`.
116#[derive(Copy, Clone, Eq, PartialEq)]
117pub enum BillingCreditGrantsResourceScopePriceType {
118    Metered,
119}
120impl BillingCreditGrantsResourceScopePriceType {
121    pub fn as_str(self) -> &'static str {
122        use BillingCreditGrantsResourceScopePriceType::*;
123        match self {
124            Metered => "metered",
125        }
126    }
127}
128
129impl std::str::FromStr for BillingCreditGrantsResourceScopePriceType {
130    type Err = stripe_types::StripeParseError;
131    fn from_str(s: &str) -> Result<Self, Self::Err> {
132        use BillingCreditGrantsResourceScopePriceType::*;
133        match s {
134            "metered" => Ok(Metered),
135            _ => Err(stripe_types::StripeParseError),
136        }
137    }
138}
139impl std::fmt::Display for BillingCreditGrantsResourceScopePriceType {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144
145impl std::fmt::Debug for BillingCreditGrantsResourceScopePriceType {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150#[cfg(feature = "serialize")]
151impl serde::Serialize for BillingCreditGrantsResourceScopePriceType {
152    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
153    where
154        S: serde::Serializer,
155    {
156        serializer.serialize_str(self.as_str())
157    }
158}
159impl miniserde::Deserialize for BillingCreditGrantsResourceScopePriceType {
160    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
161        crate::Place::new(out)
162    }
163}
164
165impl miniserde::de::Visitor for crate::Place<BillingCreditGrantsResourceScopePriceType> {
166    fn string(&mut self, s: &str) -> miniserde::Result<()> {
167        use std::str::FromStr;
168        self.out = Some(
169            BillingCreditGrantsResourceScopePriceType::from_str(s).map_err(|_| miniserde::Error)?,
170        );
171        Ok(())
172    }
173}
174
175stripe_types::impl_from_val_with_from_str!(BillingCreditGrantsResourceScopePriceType);
176#[cfg(feature = "deserialize")]
177impl<'de> serde::Deserialize<'de> for BillingCreditGrantsResourceScopePriceType {
178    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
179        use std::str::FromStr;
180        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
181        Self::from_str(&s).map_err(|_| {
182            serde::de::Error::custom("Unknown value for BillingCreditGrantsResourceScopePriceType")
183        })
184    }
185}