stripe_shared/
issuing_authorization_fleet_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingAuthorizationFleetData {
5    /// Answers to prompts presented to the cardholder at the point of sale.
6    /// Prompted fields vary depending on the configuration of your physical fleet cards.
7    /// Typical points of sale support only numeric entry.
8    pub cardholder_prompt_data:
9        Option<stripe_shared::IssuingAuthorizationFleetCardholderPromptData>,
10    /// The type of purchase.
11    pub purchase_type: Option<IssuingAuthorizationFleetDataPurchaseType>,
12    /// More information about the total amount.
13    /// Typically this information is received from the merchant after the authorization has been approved and the fuel dispensed.
14    /// This information is not guaranteed to be accurate as some merchants may provide unreliable data.
15    pub reported_breakdown: Option<stripe_shared::IssuingAuthorizationFleetReportedBreakdown>,
16    /// The type of fuel service.
17    pub service_type: Option<IssuingAuthorizationFleetDataServiceType>,
18}
19#[doc(hidden)]
20pub struct IssuingAuthorizationFleetDataBuilder {
21    cardholder_prompt_data:
22        Option<Option<stripe_shared::IssuingAuthorizationFleetCardholderPromptData>>,
23    purchase_type: Option<Option<IssuingAuthorizationFleetDataPurchaseType>>,
24    reported_breakdown: Option<Option<stripe_shared::IssuingAuthorizationFleetReportedBreakdown>>,
25    service_type: Option<Option<IssuingAuthorizationFleetDataServiceType>>,
26}
27
28#[allow(
29    unused_variables,
30    irrefutable_let_patterns,
31    clippy::let_unit_value,
32    clippy::match_single_binding,
33    clippy::single_match
34)]
35const _: () = {
36    use miniserde::de::{Map, Visitor};
37    use miniserde::json::Value;
38    use miniserde::{make_place, Deserialize, Result};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for IssuingAuthorizationFleetData {
45        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
46            Place::new(out)
47        }
48    }
49
50    struct Builder<'a> {
51        out: &'a mut Option<IssuingAuthorizationFleetData>,
52        builder: IssuingAuthorizationFleetDataBuilder,
53    }
54
55    impl Visitor for Place<IssuingAuthorizationFleetData> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: IssuingAuthorizationFleetDataBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for IssuingAuthorizationFleetDataBuilder {
65        type Out = IssuingAuthorizationFleetData;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "cardholder_prompt_data" => Deserialize::begin(&mut self.cardholder_prompt_data),
69                "purchase_type" => Deserialize::begin(&mut self.purchase_type),
70                "reported_breakdown" => Deserialize::begin(&mut self.reported_breakdown),
71                "service_type" => Deserialize::begin(&mut self.service_type),
72
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                cardholder_prompt_data: Deserialize::default(),
80                purchase_type: Deserialize::default(),
81                reported_breakdown: Deserialize::default(),
82                service_type: Deserialize::default(),
83            }
84        }
85
86        fn take_out(&mut self) -> Option<Self::Out> {
87            let (
88                Some(cardholder_prompt_data),
89                Some(purchase_type),
90                Some(reported_breakdown),
91                Some(service_type),
92            ) = (
93                self.cardholder_prompt_data.take(),
94                self.purchase_type,
95                self.reported_breakdown.take(),
96                self.service_type,
97            )
98            else {
99                return None;
100            };
101            Some(Self::Out {
102                cardholder_prompt_data,
103                purchase_type,
104                reported_breakdown,
105                service_type,
106            })
107        }
108    }
109
110    impl<'a> Map for Builder<'a> {
111        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
112            self.builder.key(k)
113        }
114
115        fn finish(&mut self) -> Result<()> {
116            *self.out = self.builder.take_out();
117            Ok(())
118        }
119    }
120
121    impl ObjectDeser for IssuingAuthorizationFleetData {
122        type Builder = IssuingAuthorizationFleetDataBuilder;
123    }
124
125    impl FromValueOpt for IssuingAuthorizationFleetData {
126        fn from_value(v: Value) -> Option<Self> {
127            let Value::Object(obj) = v else {
128                return None;
129            };
130            let mut b = IssuingAuthorizationFleetDataBuilder::deser_default();
131            for (k, v) in obj {
132                match k.as_str() {
133                    "cardholder_prompt_data" => {
134                        b.cardholder_prompt_data = FromValueOpt::from_value(v)
135                    }
136                    "purchase_type" => b.purchase_type = FromValueOpt::from_value(v),
137                    "reported_breakdown" => b.reported_breakdown = FromValueOpt::from_value(v),
138                    "service_type" => b.service_type = FromValueOpt::from_value(v),
139
140                    _ => {}
141                }
142            }
143            b.take_out()
144        }
145    }
146};
147/// The type of purchase.
148#[derive(Copy, Clone, Eq, PartialEq)]
149pub enum IssuingAuthorizationFleetDataPurchaseType {
150    FuelAndNonFuelPurchase,
151    FuelPurchase,
152    NonFuelPurchase,
153}
154impl IssuingAuthorizationFleetDataPurchaseType {
155    pub fn as_str(self) -> &'static str {
156        use IssuingAuthorizationFleetDataPurchaseType::*;
157        match self {
158            FuelAndNonFuelPurchase => "fuel_and_non_fuel_purchase",
159            FuelPurchase => "fuel_purchase",
160            NonFuelPurchase => "non_fuel_purchase",
161        }
162    }
163}
164
165impl std::str::FromStr for IssuingAuthorizationFleetDataPurchaseType {
166    type Err = stripe_types::StripeParseError;
167    fn from_str(s: &str) -> Result<Self, Self::Err> {
168        use IssuingAuthorizationFleetDataPurchaseType::*;
169        match s {
170            "fuel_and_non_fuel_purchase" => Ok(FuelAndNonFuelPurchase),
171            "fuel_purchase" => Ok(FuelPurchase),
172            "non_fuel_purchase" => Ok(NonFuelPurchase),
173            _ => Err(stripe_types::StripeParseError),
174        }
175    }
176}
177impl std::fmt::Display for IssuingAuthorizationFleetDataPurchaseType {
178    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179        f.write_str(self.as_str())
180    }
181}
182
183impl std::fmt::Debug for IssuingAuthorizationFleetDataPurchaseType {
184    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185        f.write_str(self.as_str())
186    }
187}
188#[cfg(feature = "serialize")]
189impl serde::Serialize for IssuingAuthorizationFleetDataPurchaseType {
190    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
191    where
192        S: serde::Serializer,
193    {
194        serializer.serialize_str(self.as_str())
195    }
196}
197impl miniserde::Deserialize for IssuingAuthorizationFleetDataPurchaseType {
198    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
199        crate::Place::new(out)
200    }
201}
202
203impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFleetDataPurchaseType> {
204    fn string(&mut self, s: &str) -> miniserde::Result<()> {
205        use std::str::FromStr;
206        self.out = Some(
207            IssuingAuthorizationFleetDataPurchaseType::from_str(s).map_err(|_| miniserde::Error)?,
208        );
209        Ok(())
210    }
211}
212
213stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFleetDataPurchaseType);
214#[cfg(feature = "deserialize")]
215impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFleetDataPurchaseType {
216    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
217        use std::str::FromStr;
218        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
219        Self::from_str(&s).map_err(|_| {
220            serde::de::Error::custom("Unknown value for IssuingAuthorizationFleetDataPurchaseType")
221        })
222    }
223}
224/// The type of fuel service.
225#[derive(Copy, Clone, Eq, PartialEq)]
226pub enum IssuingAuthorizationFleetDataServiceType {
227    FullService,
228    NonFuelTransaction,
229    SelfService,
230}
231impl IssuingAuthorizationFleetDataServiceType {
232    pub fn as_str(self) -> &'static str {
233        use IssuingAuthorizationFleetDataServiceType::*;
234        match self {
235            FullService => "full_service",
236            NonFuelTransaction => "non_fuel_transaction",
237            SelfService => "self_service",
238        }
239    }
240}
241
242impl std::str::FromStr for IssuingAuthorizationFleetDataServiceType {
243    type Err = stripe_types::StripeParseError;
244    fn from_str(s: &str) -> Result<Self, Self::Err> {
245        use IssuingAuthorizationFleetDataServiceType::*;
246        match s {
247            "full_service" => Ok(FullService),
248            "non_fuel_transaction" => Ok(NonFuelTransaction),
249            "self_service" => Ok(SelfService),
250            _ => Err(stripe_types::StripeParseError),
251        }
252    }
253}
254impl std::fmt::Display for IssuingAuthorizationFleetDataServiceType {
255    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
256        f.write_str(self.as_str())
257    }
258}
259
260impl std::fmt::Debug for IssuingAuthorizationFleetDataServiceType {
261    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
262        f.write_str(self.as_str())
263    }
264}
265#[cfg(feature = "serialize")]
266impl serde::Serialize for IssuingAuthorizationFleetDataServiceType {
267    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
268    where
269        S: serde::Serializer,
270    {
271        serializer.serialize_str(self.as_str())
272    }
273}
274impl miniserde::Deserialize for IssuingAuthorizationFleetDataServiceType {
275    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
276        crate::Place::new(out)
277    }
278}
279
280impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFleetDataServiceType> {
281    fn string(&mut self, s: &str) -> miniserde::Result<()> {
282        use std::str::FromStr;
283        self.out = Some(
284            IssuingAuthorizationFleetDataServiceType::from_str(s).map_err(|_| miniserde::Error)?,
285        );
286        Ok(())
287    }
288}
289
290stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFleetDataServiceType);
291#[cfg(feature = "deserialize")]
292impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFleetDataServiceType {
293    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
294        use std::str::FromStr;
295        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
296        Self::from_str(&s).map_err(|_| {
297            serde::de::Error::custom("Unknown value for IssuingAuthorizationFleetDataServiceType")
298        })
299    }
300}