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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
73            })
74        }
75
76        fn deser_default() -> Self {
77            Self {
78                cardholder_prompt_data: Deserialize::default(),
79                purchase_type: Deserialize::default(),
80                reported_breakdown: Deserialize::default(),
81                service_type: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (
87                Some(cardholder_prompt_data),
88                Some(purchase_type),
89                Some(reported_breakdown),
90                Some(service_type),
91            ) = (
92                self.cardholder_prompt_data.take(),
93                self.purchase_type,
94                self.reported_breakdown.take(),
95                self.service_type,
96            )
97            else {
98                return None;
99            };
100            Some(Self::Out {
101                cardholder_prompt_data,
102                purchase_type,
103                reported_breakdown,
104                service_type,
105            })
106        }
107    }
108
109    impl Map for Builder<'_> {
110        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
111            self.builder.key(k)
112        }
113
114        fn finish(&mut self) -> Result<()> {
115            *self.out = self.builder.take_out();
116            Ok(())
117        }
118    }
119
120    impl ObjectDeser for IssuingAuthorizationFleetData {
121        type Builder = IssuingAuthorizationFleetDataBuilder;
122    }
123
124    impl FromValueOpt for IssuingAuthorizationFleetData {
125        fn from_value(v: Value) -> Option<Self> {
126            let Value::Object(obj) = v else {
127                return None;
128            };
129            let mut b = IssuingAuthorizationFleetDataBuilder::deser_default();
130            for (k, v) in obj {
131                match k.as_str() {
132                    "cardholder_prompt_data" => {
133                        b.cardholder_prompt_data = FromValueOpt::from_value(v)
134                    }
135                    "purchase_type" => b.purchase_type = FromValueOpt::from_value(v),
136                    "reported_breakdown" => b.reported_breakdown = FromValueOpt::from_value(v),
137                    "service_type" => b.service_type = FromValueOpt::from_value(v),
138                    _ => {}
139                }
140            }
141            b.take_out()
142        }
143    }
144};
145/// The type of purchase.
146#[derive(Copy, Clone, Eq, PartialEq)]
147pub enum IssuingAuthorizationFleetDataPurchaseType {
148    FuelAndNonFuelPurchase,
149    FuelPurchase,
150    NonFuelPurchase,
151}
152impl IssuingAuthorizationFleetDataPurchaseType {
153    pub fn as_str(self) -> &'static str {
154        use IssuingAuthorizationFleetDataPurchaseType::*;
155        match self {
156            FuelAndNonFuelPurchase => "fuel_and_non_fuel_purchase",
157            FuelPurchase => "fuel_purchase",
158            NonFuelPurchase => "non_fuel_purchase",
159        }
160    }
161}
162
163impl std::str::FromStr for IssuingAuthorizationFleetDataPurchaseType {
164    type Err = stripe_types::StripeParseError;
165    fn from_str(s: &str) -> Result<Self, Self::Err> {
166        use IssuingAuthorizationFleetDataPurchaseType::*;
167        match s {
168            "fuel_and_non_fuel_purchase" => Ok(FuelAndNonFuelPurchase),
169            "fuel_purchase" => Ok(FuelPurchase),
170            "non_fuel_purchase" => Ok(NonFuelPurchase),
171            _ => Err(stripe_types::StripeParseError),
172        }
173    }
174}
175impl std::fmt::Display for IssuingAuthorizationFleetDataPurchaseType {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.write_str(self.as_str())
178    }
179}
180
181impl std::fmt::Debug for IssuingAuthorizationFleetDataPurchaseType {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.write_str(self.as_str())
184    }
185}
186#[cfg(feature = "serialize")]
187impl serde::Serialize for IssuingAuthorizationFleetDataPurchaseType {
188    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
189    where
190        S: serde::Serializer,
191    {
192        serializer.serialize_str(self.as_str())
193    }
194}
195impl miniserde::Deserialize for IssuingAuthorizationFleetDataPurchaseType {
196    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
197        crate::Place::new(out)
198    }
199}
200
201impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFleetDataPurchaseType> {
202    fn string(&mut self, s: &str) -> miniserde::Result<()> {
203        use std::str::FromStr;
204        self.out = Some(
205            IssuingAuthorizationFleetDataPurchaseType::from_str(s).map_err(|_| miniserde::Error)?,
206        );
207        Ok(())
208    }
209}
210
211stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFleetDataPurchaseType);
212#[cfg(feature = "deserialize")]
213impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFleetDataPurchaseType {
214    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
215        use std::str::FromStr;
216        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
217        Self::from_str(&s).map_err(|_| {
218            serde::de::Error::custom("Unknown value for IssuingAuthorizationFleetDataPurchaseType")
219        })
220    }
221}
222/// The type of fuel service.
223#[derive(Copy, Clone, Eq, PartialEq)]
224pub enum IssuingAuthorizationFleetDataServiceType {
225    FullService,
226    NonFuelTransaction,
227    SelfService,
228}
229impl IssuingAuthorizationFleetDataServiceType {
230    pub fn as_str(self) -> &'static str {
231        use IssuingAuthorizationFleetDataServiceType::*;
232        match self {
233            FullService => "full_service",
234            NonFuelTransaction => "non_fuel_transaction",
235            SelfService => "self_service",
236        }
237    }
238}
239
240impl std::str::FromStr for IssuingAuthorizationFleetDataServiceType {
241    type Err = stripe_types::StripeParseError;
242    fn from_str(s: &str) -> Result<Self, Self::Err> {
243        use IssuingAuthorizationFleetDataServiceType::*;
244        match s {
245            "full_service" => Ok(FullService),
246            "non_fuel_transaction" => Ok(NonFuelTransaction),
247            "self_service" => Ok(SelfService),
248            _ => Err(stripe_types::StripeParseError),
249        }
250    }
251}
252impl std::fmt::Display for IssuingAuthorizationFleetDataServiceType {
253    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
254        f.write_str(self.as_str())
255    }
256}
257
258impl std::fmt::Debug for IssuingAuthorizationFleetDataServiceType {
259    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260        f.write_str(self.as_str())
261    }
262}
263#[cfg(feature = "serialize")]
264impl serde::Serialize for IssuingAuthorizationFleetDataServiceType {
265    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
266    where
267        S: serde::Serializer,
268    {
269        serializer.serialize_str(self.as_str())
270    }
271}
272impl miniserde::Deserialize for IssuingAuthorizationFleetDataServiceType {
273    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
274        crate::Place::new(out)
275    }
276}
277
278impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFleetDataServiceType> {
279    fn string(&mut self, s: &str) -> miniserde::Result<()> {
280        use std::str::FromStr;
281        self.out = Some(
282            IssuingAuthorizationFleetDataServiceType::from_str(s).map_err(|_| miniserde::Error)?,
283        );
284        Ok(())
285    }
286}
287
288stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFleetDataServiceType);
289#[cfg(feature = "deserialize")]
290impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFleetDataServiceType {
291    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
292        use std::str::FromStr;
293        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
294        Self::from_str(&s).map_err(|_| {
295            serde::de::Error::custom("Unknown value for IssuingAuthorizationFleetDataServiceType")
296        })
297    }
298}