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.take(),
92                self.id.take(),
93                self.livemode,
94                self.name.take(),
95                self.status.take(),
96                self.type_.take(),
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(Clone, Eq, PartialEq)]
168#[non_exhaustive]
169pub enum IssuingPhysicalBundleStatus {
170    Active,
171    Inactive,
172    Review,
173    /// An unrecognized value from Stripe. Should not be used as a request parameter.
174    Unknown(String),
175}
176impl IssuingPhysicalBundleStatus {
177    pub fn as_str(&self) -> &str {
178        use IssuingPhysicalBundleStatus::*;
179        match self {
180            Active => "active",
181            Inactive => "inactive",
182            Review => "review",
183            Unknown(v) => v,
184        }
185    }
186}
187
188impl std::str::FromStr for IssuingPhysicalBundleStatus {
189    type Err = std::convert::Infallible;
190    fn from_str(s: &str) -> Result<Self, Self::Err> {
191        use IssuingPhysicalBundleStatus::*;
192        match s {
193            "active" => Ok(Active),
194            "inactive" => Ok(Inactive),
195            "review" => Ok(Review),
196            v => {
197                tracing::warn!(
198                    "Unknown value '{}' for enum '{}'",
199                    v,
200                    "IssuingPhysicalBundleStatus"
201                );
202                Ok(Unknown(v.to_owned()))
203            }
204        }
205    }
206}
207impl std::fmt::Display for IssuingPhysicalBundleStatus {
208    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
209        f.write_str(self.as_str())
210    }
211}
212
213impl std::fmt::Debug for IssuingPhysicalBundleStatus {
214    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
215        f.write_str(self.as_str())
216    }
217}
218impl serde::Serialize for IssuingPhysicalBundleStatus {
219    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
220    where
221        S: serde::Serializer,
222    {
223        serializer.serialize_str(self.as_str())
224    }
225}
226impl miniserde::Deserialize for IssuingPhysicalBundleStatus {
227    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
228        crate::Place::new(out)
229    }
230}
231
232impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleStatus> {
233    fn string(&mut self, s: &str) -> miniserde::Result<()> {
234        use std::str::FromStr;
235        self.out = Some(IssuingPhysicalBundleStatus::from_str(s).expect("infallible"));
236        Ok(())
237    }
238}
239
240stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleStatus);
241#[cfg(feature = "deserialize")]
242impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleStatus {
243    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
244        use std::str::FromStr;
245        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
246        Ok(Self::from_str(&s).expect("infallible"))
247    }
248}
249#[derive(Clone, Eq, PartialEq)]
250#[non_exhaustive]
251pub enum IssuingPhysicalBundleType {
252    Custom,
253    Standard,
254    /// An unrecognized value from Stripe. Should not be used as a request parameter.
255    Unknown(String),
256}
257impl IssuingPhysicalBundleType {
258    pub fn as_str(&self) -> &str {
259        use IssuingPhysicalBundleType::*;
260        match self {
261            Custom => "custom",
262            Standard => "standard",
263            Unknown(v) => v,
264        }
265    }
266}
267
268impl std::str::FromStr for IssuingPhysicalBundleType {
269    type Err = std::convert::Infallible;
270    fn from_str(s: &str) -> Result<Self, Self::Err> {
271        use IssuingPhysicalBundleType::*;
272        match s {
273            "custom" => Ok(Custom),
274            "standard" => Ok(Standard),
275            v => {
276                tracing::warn!("Unknown value '{}' for enum '{}'", v, "IssuingPhysicalBundleType");
277                Ok(Unknown(v.to_owned()))
278            }
279        }
280    }
281}
282impl std::fmt::Display for IssuingPhysicalBundleType {
283    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284        f.write_str(self.as_str())
285    }
286}
287
288impl std::fmt::Debug for IssuingPhysicalBundleType {
289    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
290        f.write_str(self.as_str())
291    }
292}
293impl serde::Serialize for IssuingPhysicalBundleType {
294    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
295    where
296        S: serde::Serializer,
297    {
298        serializer.serialize_str(self.as_str())
299    }
300}
301impl miniserde::Deserialize for IssuingPhysicalBundleType {
302    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
303        crate::Place::new(out)
304    }
305}
306
307impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleType> {
308    fn string(&mut self, s: &str) -> miniserde::Result<()> {
309        use std::str::FromStr;
310        self.out = Some(IssuingPhysicalBundleType::from_str(s).expect("infallible"));
311        Ok(())
312    }
313}
314
315stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleType);
316#[cfg(feature = "deserialize")]
317impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleType {
318    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
319        use std::str::FromStr;
320        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
321        Ok(Self::from_str(&s).expect("infallible"))
322    }
323}