stripe_shared/
issuing_physical_bundle.rs

1/// A Physical Bundle represents the bundle of physical items - card stock, carrier letter, and envelope - that is shipped to a cardholder when you create a physical card.
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingPhysicalBundle {
5    pub features: stripe_shared::IssuingPhysicalBundleFeatures,
6    /// Unique identifier for the object.
7    pub id: stripe_shared::IssuingPhysicalBundleId,
8    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
9    pub livemode: bool,
10    /// Friendly display name.
11    pub name: String,
12    /// Whether this physical bundle can be used to create cards.
13    pub status: stripe_shared::IssuingPhysicalBundleStatus,
14    /// Whether this physical bundle is a standard Stripe offering or custom-made for you.
15    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
16    pub type_: stripe_shared::IssuingPhysicalBundleType,
17}
18#[doc(hidden)]
19pub struct IssuingPhysicalBundleBuilder {
20    features: Option<stripe_shared::IssuingPhysicalBundleFeatures>,
21    id: Option<stripe_shared::IssuingPhysicalBundleId>,
22    livemode: Option<bool>,
23    name: Option<String>,
24    status: Option<stripe_shared::IssuingPhysicalBundleStatus>,
25    type_: Option<stripe_shared::IssuingPhysicalBundleType>,
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 IssuingPhysicalBundle {
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<IssuingPhysicalBundle>,
52        builder: IssuingPhysicalBundleBuilder,
53    }
54
55    impl Visitor for Place<IssuingPhysicalBundle> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: IssuingPhysicalBundleBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for IssuingPhysicalBundleBuilder {
65        type Out = IssuingPhysicalBundle;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "features" => Deserialize::begin(&mut self.features),
69                "id" => Deserialize::begin(&mut self.id),
70                "livemode" => Deserialize::begin(&mut self.livemode),
71                "name" => Deserialize::begin(&mut self.name),
72                "status" => Deserialize::begin(&mut self.status),
73                "type" => Deserialize::begin(&mut self.type_),
74
75                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self {
81                features: Deserialize::default(),
82                id: Deserialize::default(),
83                livemode: Deserialize::default(),
84                name: Deserialize::default(),
85                status: Deserialize::default(),
86                type_: Deserialize::default(),
87            }
88        }
89
90        fn take_out(&mut self) -> Option<Self::Out> {
91            let (Some(features), Some(id), Some(livemode), Some(name), Some(status), Some(type_)) = (
92                self.features,
93                self.id.take(),
94                self.livemode,
95                self.name.take(),
96                self.status,
97                self.type_,
98            ) else {
99                return None;
100            };
101            Some(Self::Out { features, id, livemode, name, status, type_ })
102        }
103    }
104
105    impl Map for Builder<'_> {
106        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
107            self.builder.key(k)
108        }
109
110        fn finish(&mut self) -> Result<()> {
111            *self.out = self.builder.take_out();
112            Ok(())
113        }
114    }
115
116    impl ObjectDeser for IssuingPhysicalBundle {
117        type Builder = IssuingPhysicalBundleBuilder;
118    }
119
120    impl FromValueOpt for IssuingPhysicalBundle {
121        fn from_value(v: Value) -> Option<Self> {
122            let Value::Object(obj) = v else {
123                return None;
124            };
125            let mut b = IssuingPhysicalBundleBuilder::deser_default();
126            for (k, v) in obj {
127                match k.as_str() {
128                    "features" => b.features = FromValueOpt::from_value(v),
129                    "id" => b.id = FromValueOpt::from_value(v),
130                    "livemode" => b.livemode = FromValueOpt::from_value(v),
131                    "name" => b.name = FromValueOpt::from_value(v),
132                    "status" => b.status = FromValueOpt::from_value(v),
133                    "type" => b.type_ = FromValueOpt::from_value(v),
134
135                    _ => {}
136                }
137            }
138            b.take_out()
139        }
140    }
141};
142#[cfg(feature = "serialize")]
143impl serde::Serialize for IssuingPhysicalBundle {
144    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
145        use serde::ser::SerializeStruct;
146        let mut s = s.serialize_struct("IssuingPhysicalBundle", 7)?;
147        s.serialize_field("features", &self.features)?;
148        s.serialize_field("id", &self.id)?;
149        s.serialize_field("livemode", &self.livemode)?;
150        s.serialize_field("name", &self.name)?;
151        s.serialize_field("status", &self.status)?;
152        s.serialize_field("type", &self.type_)?;
153
154        s.serialize_field("object", "issuing.physical_bundle")?;
155        s.end()
156    }
157}
158impl stripe_types::Object for IssuingPhysicalBundle {
159    type Id = stripe_shared::IssuingPhysicalBundleId;
160    fn id(&self) -> &Self::Id {
161        &self.id
162    }
163
164    fn into_id(self) -> Self::Id {
165        self.id
166    }
167}
168stripe_types::def_id!(IssuingPhysicalBundleId);
169#[derive(Copy, Clone, Eq, PartialEq)]
170pub enum IssuingPhysicalBundleStatus {
171    Active,
172    Inactive,
173    Review,
174}
175impl IssuingPhysicalBundleStatus {
176    pub fn as_str(self) -> &'static str {
177        use IssuingPhysicalBundleStatus::*;
178        match self {
179            Active => "active",
180            Inactive => "inactive",
181            Review => "review",
182        }
183    }
184}
185
186impl std::str::FromStr for IssuingPhysicalBundleStatus {
187    type Err = stripe_types::StripeParseError;
188    fn from_str(s: &str) -> Result<Self, Self::Err> {
189        use IssuingPhysicalBundleStatus::*;
190        match s {
191            "active" => Ok(Active),
192            "inactive" => Ok(Inactive),
193            "review" => Ok(Review),
194            _ => Err(stripe_types::StripeParseError),
195        }
196    }
197}
198impl std::fmt::Display for IssuingPhysicalBundleStatus {
199    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
200        f.write_str(self.as_str())
201    }
202}
203
204impl std::fmt::Debug for IssuingPhysicalBundleStatus {
205    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
206        f.write_str(self.as_str())
207    }
208}
209impl serde::Serialize for IssuingPhysicalBundleStatus {
210    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
211    where
212        S: serde::Serializer,
213    {
214        serializer.serialize_str(self.as_str())
215    }
216}
217impl miniserde::Deserialize for IssuingPhysicalBundleStatus {
218    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
219        crate::Place::new(out)
220    }
221}
222
223impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleStatus> {
224    fn string(&mut self, s: &str) -> miniserde::Result<()> {
225        use std::str::FromStr;
226        self.out = Some(IssuingPhysicalBundleStatus::from_str(s).map_err(|_| miniserde::Error)?);
227        Ok(())
228    }
229}
230
231stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleStatus);
232#[cfg(feature = "deserialize")]
233impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleStatus {
234    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
235        use std::str::FromStr;
236        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
237        Self::from_str(&s)
238            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingPhysicalBundleStatus"))
239    }
240}
241#[derive(Copy, Clone, Eq, PartialEq)]
242pub enum IssuingPhysicalBundleType {
243    Custom,
244    Standard,
245}
246impl IssuingPhysicalBundleType {
247    pub fn as_str(self) -> &'static str {
248        use IssuingPhysicalBundleType::*;
249        match self {
250            Custom => "custom",
251            Standard => "standard",
252        }
253    }
254}
255
256impl std::str::FromStr for IssuingPhysicalBundleType {
257    type Err = stripe_types::StripeParseError;
258    fn from_str(s: &str) -> Result<Self, Self::Err> {
259        use IssuingPhysicalBundleType::*;
260        match s {
261            "custom" => Ok(Custom),
262            "standard" => Ok(Standard),
263            _ => Err(stripe_types::StripeParseError),
264        }
265    }
266}
267impl std::fmt::Display for IssuingPhysicalBundleType {
268    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
269        f.write_str(self.as_str())
270    }
271}
272
273impl std::fmt::Debug for IssuingPhysicalBundleType {
274    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275        f.write_str(self.as_str())
276    }
277}
278impl serde::Serialize for IssuingPhysicalBundleType {
279    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
280    where
281        S: serde::Serializer,
282    {
283        serializer.serialize_str(self.as_str())
284    }
285}
286impl miniserde::Deserialize for IssuingPhysicalBundleType {
287    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
288        crate::Place::new(out)
289    }
290}
291
292impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleType> {
293    fn string(&mut self, s: &str) -> miniserde::Result<()> {
294        use std::str::FromStr;
295        self.out = Some(IssuingPhysicalBundleType::from_str(s).map_err(|_| miniserde::Error)?);
296        Ok(())
297    }
298}
299
300stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleType);
301#[cfg(feature = "deserialize")]
302impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleType {
303    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
304        use std::str::FromStr;
305        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
306        Self::from_str(&s)
307            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingPhysicalBundleType"))
308    }
309}