stripe_shared/
issuing_authorization_fuel_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingAuthorizationFuelData {
5    /// [Conexxus Payment System Product Code](https://www.conexxus.org/conexxus-payment-system-product-codes) identifying the primary fuel product purchased.
6    pub industry_product_code: Option<String>,
7    /// The quantity of `unit`s of fuel that was dispensed, represented as a decimal string with at most 12 decimal places.
8    pub quantity_decimal: Option<String>,
9    /// The type of fuel that was purchased.
10    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11    pub type_: Option<IssuingAuthorizationFuelDataType>,
12    /// The units for `quantity_decimal`.
13    pub unit: Option<IssuingAuthorizationFuelDataUnit>,
14    /// The cost in cents per each unit of fuel, represented as a decimal string with at most 12 decimal places.
15    pub unit_cost_decimal: Option<String>,
16}
17#[doc(hidden)]
18pub struct IssuingAuthorizationFuelDataBuilder {
19    industry_product_code: Option<Option<String>>,
20    quantity_decimal: Option<Option<String>>,
21    type_: Option<Option<IssuingAuthorizationFuelDataType>>,
22    unit: Option<Option<IssuingAuthorizationFuelDataUnit>>,
23    unit_cost_decimal: Option<Option<String>>,
24}
25
26#[allow(
27    unused_variables,
28    irrefutable_let_patterns,
29    clippy::let_unit_value,
30    clippy::match_single_binding,
31    clippy::single_match
32)]
33const _: () = {
34    use miniserde::de::{Map, Visitor};
35    use miniserde::json::Value;
36    use miniserde::{Deserialize, Result, make_place};
37    use stripe_types::miniserde_helpers::FromValueOpt;
38    use stripe_types::{MapBuilder, ObjectDeser};
39
40    make_place!(Place);
41
42    impl Deserialize for IssuingAuthorizationFuelData {
43        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
44            Place::new(out)
45        }
46    }
47
48    struct Builder<'a> {
49        out: &'a mut Option<IssuingAuthorizationFuelData>,
50        builder: IssuingAuthorizationFuelDataBuilder,
51    }
52
53    impl Visitor for Place<IssuingAuthorizationFuelData> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: IssuingAuthorizationFuelDataBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for IssuingAuthorizationFuelDataBuilder {
63        type Out = IssuingAuthorizationFuelData;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "industry_product_code" => Deserialize::begin(&mut self.industry_product_code),
67                "quantity_decimal" => Deserialize::begin(&mut self.quantity_decimal),
68                "type" => Deserialize::begin(&mut self.type_),
69                "unit" => Deserialize::begin(&mut self.unit),
70                "unit_cost_decimal" => Deserialize::begin(&mut self.unit_cost_decimal),
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self {
77                industry_product_code: Deserialize::default(),
78                quantity_decimal: Deserialize::default(),
79                type_: Deserialize::default(),
80                unit: Deserialize::default(),
81                unit_cost_decimal: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (
87                Some(industry_product_code),
88                Some(quantity_decimal),
89                Some(type_),
90                Some(unit),
91                Some(unit_cost_decimal),
92            ) = (
93                self.industry_product_code.take(),
94                self.quantity_decimal.take(),
95                self.type_,
96                self.unit,
97                self.unit_cost_decimal.take(),
98            )
99            else {
100                return None;
101            };
102            Some(Self::Out {
103                industry_product_code,
104                quantity_decimal,
105                type_,
106                unit,
107                unit_cost_decimal,
108            })
109        }
110    }
111
112    impl Map for Builder<'_> {
113        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
114            self.builder.key(k)
115        }
116
117        fn finish(&mut self) -> Result<()> {
118            *self.out = self.builder.take_out();
119            Ok(())
120        }
121    }
122
123    impl ObjectDeser for IssuingAuthorizationFuelData {
124        type Builder = IssuingAuthorizationFuelDataBuilder;
125    }
126
127    impl FromValueOpt for IssuingAuthorizationFuelData {
128        fn from_value(v: Value) -> Option<Self> {
129            let Value::Object(obj) = v else {
130                return None;
131            };
132            let mut b = IssuingAuthorizationFuelDataBuilder::deser_default();
133            for (k, v) in obj {
134                match k.as_str() {
135                    "industry_product_code" => {
136                        b.industry_product_code = FromValueOpt::from_value(v)
137                    }
138                    "quantity_decimal" => b.quantity_decimal = FromValueOpt::from_value(v),
139                    "type" => b.type_ = FromValueOpt::from_value(v),
140                    "unit" => b.unit = FromValueOpt::from_value(v),
141                    "unit_cost_decimal" => b.unit_cost_decimal = FromValueOpt::from_value(v),
142                    _ => {}
143                }
144            }
145            b.take_out()
146        }
147    }
148};
149/// The type of fuel that was purchased.
150#[derive(Copy, Clone, Eq, PartialEq)]
151pub enum IssuingAuthorizationFuelDataType {
152    Diesel,
153    Other,
154    UnleadedPlus,
155    UnleadedRegular,
156    UnleadedSuper,
157}
158impl IssuingAuthorizationFuelDataType {
159    pub fn as_str(self) -> &'static str {
160        use IssuingAuthorizationFuelDataType::*;
161        match self {
162            Diesel => "diesel",
163            Other => "other",
164            UnleadedPlus => "unleaded_plus",
165            UnleadedRegular => "unleaded_regular",
166            UnleadedSuper => "unleaded_super",
167        }
168    }
169}
170
171impl std::str::FromStr for IssuingAuthorizationFuelDataType {
172    type Err = stripe_types::StripeParseError;
173    fn from_str(s: &str) -> Result<Self, Self::Err> {
174        use IssuingAuthorizationFuelDataType::*;
175        match s {
176            "diesel" => Ok(Diesel),
177            "other" => Ok(Other),
178            "unleaded_plus" => Ok(UnleadedPlus),
179            "unleaded_regular" => Ok(UnleadedRegular),
180            "unleaded_super" => Ok(UnleadedSuper),
181            _ => Err(stripe_types::StripeParseError),
182        }
183    }
184}
185impl std::fmt::Display for IssuingAuthorizationFuelDataType {
186    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
187        f.write_str(self.as_str())
188    }
189}
190
191impl std::fmt::Debug for IssuingAuthorizationFuelDataType {
192    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193        f.write_str(self.as_str())
194    }
195}
196#[cfg(feature = "serialize")]
197impl serde::Serialize for IssuingAuthorizationFuelDataType {
198    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
199    where
200        S: serde::Serializer,
201    {
202        serializer.serialize_str(self.as_str())
203    }
204}
205impl miniserde::Deserialize for IssuingAuthorizationFuelDataType {
206    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
207        crate::Place::new(out)
208    }
209}
210
211impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFuelDataType> {
212    fn string(&mut self, s: &str) -> miniserde::Result<()> {
213        use std::str::FromStr;
214        self.out =
215            Some(IssuingAuthorizationFuelDataType::from_str(s).map_err(|_| miniserde::Error)?);
216        Ok(())
217    }
218}
219
220stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFuelDataType);
221#[cfg(feature = "deserialize")]
222impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFuelDataType {
223    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
224        use std::str::FromStr;
225        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
226        Self::from_str(&s).map_err(|_| {
227            serde::de::Error::custom("Unknown value for IssuingAuthorizationFuelDataType")
228        })
229    }
230}
231/// The units for `quantity_decimal`.
232#[derive(Copy, Clone, Eq, PartialEq)]
233pub enum IssuingAuthorizationFuelDataUnit {
234    ChargingMinute,
235    ImperialGallon,
236    Kilogram,
237    KilowattHour,
238    Liter,
239    Other,
240    Pound,
241    UsGallon,
242}
243impl IssuingAuthorizationFuelDataUnit {
244    pub fn as_str(self) -> &'static str {
245        use IssuingAuthorizationFuelDataUnit::*;
246        match self {
247            ChargingMinute => "charging_minute",
248            ImperialGallon => "imperial_gallon",
249            Kilogram => "kilogram",
250            KilowattHour => "kilowatt_hour",
251            Liter => "liter",
252            Other => "other",
253            Pound => "pound",
254            UsGallon => "us_gallon",
255        }
256    }
257}
258
259impl std::str::FromStr for IssuingAuthorizationFuelDataUnit {
260    type Err = stripe_types::StripeParseError;
261    fn from_str(s: &str) -> Result<Self, Self::Err> {
262        use IssuingAuthorizationFuelDataUnit::*;
263        match s {
264            "charging_minute" => Ok(ChargingMinute),
265            "imperial_gallon" => Ok(ImperialGallon),
266            "kilogram" => Ok(Kilogram),
267            "kilowatt_hour" => Ok(KilowattHour),
268            "liter" => Ok(Liter),
269            "other" => Ok(Other),
270            "pound" => Ok(Pound),
271            "us_gallon" => Ok(UsGallon),
272            _ => Err(stripe_types::StripeParseError),
273        }
274    }
275}
276impl std::fmt::Display for IssuingAuthorizationFuelDataUnit {
277    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
278        f.write_str(self.as_str())
279    }
280}
281
282impl std::fmt::Debug for IssuingAuthorizationFuelDataUnit {
283    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284        f.write_str(self.as_str())
285    }
286}
287#[cfg(feature = "serialize")]
288impl serde::Serialize for IssuingAuthorizationFuelDataUnit {
289    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
290    where
291        S: serde::Serializer,
292    {
293        serializer.serialize_str(self.as_str())
294    }
295}
296impl miniserde::Deserialize for IssuingAuthorizationFuelDataUnit {
297    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
298        crate::Place::new(out)
299    }
300}
301
302impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFuelDataUnit> {
303    fn string(&mut self, s: &str) -> miniserde::Result<()> {
304        use std::str::FromStr;
305        self.out =
306            Some(IssuingAuthorizationFuelDataUnit::from_str(s).map_err(|_| miniserde::Error)?);
307        Ok(())
308    }
309}
310
311stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFuelDataUnit);
312#[cfg(feature = "deserialize")]
313impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFuelDataUnit {
314    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
315        use std::str::FromStr;
316        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
317        Self::from_str(&s).map_err(|_| {
318            serde::de::Error::custom("Unknown value for IssuingAuthorizationFuelDataUnit")
319        })
320    }
321}