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_.take(),
96                self.unit.take(),
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(Clone, Eq, PartialEq)]
151#[non_exhaustive]
152pub enum IssuingAuthorizationFuelDataType {
153    Diesel,
154    Other,
155    UnleadedPlus,
156    UnleadedRegular,
157    UnleadedSuper,
158    /// An unrecognized value from Stripe. Should not be used as a request parameter.
159    Unknown(String),
160}
161impl IssuingAuthorizationFuelDataType {
162    pub fn as_str(&self) -> &str {
163        use IssuingAuthorizationFuelDataType::*;
164        match self {
165            Diesel => "diesel",
166            Other => "other",
167            UnleadedPlus => "unleaded_plus",
168            UnleadedRegular => "unleaded_regular",
169            UnleadedSuper => "unleaded_super",
170            Unknown(v) => v,
171        }
172    }
173}
174
175impl std::str::FromStr for IssuingAuthorizationFuelDataType {
176    type Err = std::convert::Infallible;
177    fn from_str(s: &str) -> Result<Self, Self::Err> {
178        use IssuingAuthorizationFuelDataType::*;
179        match s {
180            "diesel" => Ok(Diesel),
181            "other" => Ok(Other),
182            "unleaded_plus" => Ok(UnleadedPlus),
183            "unleaded_regular" => Ok(UnleadedRegular),
184            "unleaded_super" => Ok(UnleadedSuper),
185            v => {
186                tracing::warn!(
187                    "Unknown value '{}' for enum '{}'",
188                    v,
189                    "IssuingAuthorizationFuelDataType"
190                );
191                Ok(Unknown(v.to_owned()))
192            }
193        }
194    }
195}
196impl std::fmt::Display for IssuingAuthorizationFuelDataType {
197    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
198        f.write_str(self.as_str())
199    }
200}
201
202impl std::fmt::Debug for IssuingAuthorizationFuelDataType {
203    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
204        f.write_str(self.as_str())
205    }
206}
207#[cfg(feature = "serialize")]
208impl serde::Serialize for IssuingAuthorizationFuelDataType {
209    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
210    where
211        S: serde::Serializer,
212    {
213        serializer.serialize_str(self.as_str())
214    }
215}
216impl miniserde::Deserialize for IssuingAuthorizationFuelDataType {
217    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
218        crate::Place::new(out)
219    }
220}
221
222impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFuelDataType> {
223    fn string(&mut self, s: &str) -> miniserde::Result<()> {
224        use std::str::FromStr;
225        self.out = Some(IssuingAuthorizationFuelDataType::from_str(s).expect("infallible"));
226        Ok(())
227    }
228}
229
230stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFuelDataType);
231#[cfg(feature = "deserialize")]
232impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFuelDataType {
233    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
234        use std::str::FromStr;
235        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
236        Ok(Self::from_str(&s).expect("infallible"))
237    }
238}
239/// The units for `quantity_decimal`.
240#[derive(Clone, Eq, PartialEq)]
241#[non_exhaustive]
242pub enum IssuingAuthorizationFuelDataUnit {
243    ChargingMinute,
244    ImperialGallon,
245    Kilogram,
246    KilowattHour,
247    Liter,
248    Other,
249    Pound,
250    UsGallon,
251    /// An unrecognized value from Stripe. Should not be used as a request parameter.
252    Unknown(String),
253}
254impl IssuingAuthorizationFuelDataUnit {
255    pub fn as_str(&self) -> &str {
256        use IssuingAuthorizationFuelDataUnit::*;
257        match self {
258            ChargingMinute => "charging_minute",
259            ImperialGallon => "imperial_gallon",
260            Kilogram => "kilogram",
261            KilowattHour => "kilowatt_hour",
262            Liter => "liter",
263            Other => "other",
264            Pound => "pound",
265            UsGallon => "us_gallon",
266            Unknown(v) => v,
267        }
268    }
269}
270
271impl std::str::FromStr for IssuingAuthorizationFuelDataUnit {
272    type Err = std::convert::Infallible;
273    fn from_str(s: &str) -> Result<Self, Self::Err> {
274        use IssuingAuthorizationFuelDataUnit::*;
275        match s {
276            "charging_minute" => Ok(ChargingMinute),
277            "imperial_gallon" => Ok(ImperialGallon),
278            "kilogram" => Ok(Kilogram),
279            "kilowatt_hour" => Ok(KilowattHour),
280            "liter" => Ok(Liter),
281            "other" => Ok(Other),
282            "pound" => Ok(Pound),
283            "us_gallon" => Ok(UsGallon),
284            v => {
285                tracing::warn!(
286                    "Unknown value '{}' for enum '{}'",
287                    v,
288                    "IssuingAuthorizationFuelDataUnit"
289                );
290                Ok(Unknown(v.to_owned()))
291            }
292        }
293    }
294}
295impl std::fmt::Display for IssuingAuthorizationFuelDataUnit {
296    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
297        f.write_str(self.as_str())
298    }
299}
300
301impl std::fmt::Debug for IssuingAuthorizationFuelDataUnit {
302    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
303        f.write_str(self.as_str())
304    }
305}
306#[cfg(feature = "serialize")]
307impl serde::Serialize for IssuingAuthorizationFuelDataUnit {
308    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
309    where
310        S: serde::Serializer,
311    {
312        serializer.serialize_str(self.as_str())
313    }
314}
315impl miniserde::Deserialize for IssuingAuthorizationFuelDataUnit {
316    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
317        crate::Place::new(out)
318    }
319}
320
321impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFuelDataUnit> {
322    fn string(&mut self, s: &str) -> miniserde::Result<()> {
323        use std::str::FromStr;
324        self.out = Some(IssuingAuthorizationFuelDataUnit::from_str(s).expect("infallible"));
325        Ok(())
326    }
327}
328
329stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFuelDataUnit);
330#[cfg(feature = "deserialize")]
331impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFuelDataUnit {
332    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
333        use std::str::FromStr;
334        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
335        Ok(Self::from_str(&s).expect("infallible"))
336    }
337}