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