stripe_shared/
issuing_card_shipping.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardShipping {
5    pub address: stripe_shared::Address,
6    /// Address validation details for the shipment.
7    pub address_validation: Option<stripe_shared::IssuingCardShippingAddressValidation>,
8    /// The delivery company that shipped a card.
9    pub carrier: Option<IssuingCardShippingCarrier>,
10    /// Additional information that may be required for clearing customs.
11    pub customs: Option<stripe_shared::IssuingCardShippingCustoms>,
12    /// A unix timestamp representing a best estimate of when the card will be delivered.
13    pub eta: Option<stripe_types::Timestamp>,
14    /// Recipient name.
15    pub name: String,
16    /// The phone number of the receiver of the shipment.
17    /// Our courier partners will use this number to contact you in the event of card delivery issues.
18    /// For individual shipments to the EU/UK, if this field is empty, we will provide them with the phone number provided when the cardholder was initially created.
19    pub phone_number: Option<String>,
20    /// Whether a signature is required for card delivery.
21    /// This feature is only supported for US users.
22    /// Standard shipping service does not support signature on delivery.
23    /// The default value for standard shipping service is false and for express and priority services is true.
24    pub require_signature: Option<bool>,
25    /// Shipment service, such as `standard` or `express`.
26    pub service: IssuingCardShippingService,
27    /// The delivery status of the card.
28    pub status: Option<IssuingCardShippingStatus>,
29    /// A tracking number for a card shipment.
30    pub tracking_number: Option<String>,
31    /// A link to the shipping carrier's site where you can view detailed information about a card shipment.
32    pub tracking_url: Option<String>,
33    /// Packaging options.
34    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
35    pub type_: IssuingCardShippingType,
36}
37#[doc(hidden)]
38pub struct IssuingCardShippingBuilder {
39    address: Option<stripe_shared::Address>,
40    address_validation: Option<Option<stripe_shared::IssuingCardShippingAddressValidation>>,
41    carrier: Option<Option<IssuingCardShippingCarrier>>,
42    customs: Option<Option<stripe_shared::IssuingCardShippingCustoms>>,
43    eta: Option<Option<stripe_types::Timestamp>>,
44    name: Option<String>,
45    phone_number: Option<Option<String>>,
46    require_signature: Option<Option<bool>>,
47    service: Option<IssuingCardShippingService>,
48    status: Option<Option<IssuingCardShippingStatus>>,
49    tracking_number: Option<Option<String>>,
50    tracking_url: Option<Option<String>>,
51    type_: Option<IssuingCardShippingType>,
52}
53
54#[allow(
55    unused_variables,
56    irrefutable_let_patterns,
57    clippy::let_unit_value,
58    clippy::match_single_binding,
59    clippy::single_match
60)]
61const _: () = {
62    use miniserde::de::{Map, Visitor};
63    use miniserde::json::Value;
64    use miniserde::{Deserialize, Result, make_place};
65    use stripe_types::miniserde_helpers::FromValueOpt;
66    use stripe_types::{MapBuilder, ObjectDeser};
67
68    make_place!(Place);
69
70    impl Deserialize for IssuingCardShipping {
71        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
72            Place::new(out)
73        }
74    }
75
76    struct Builder<'a> {
77        out: &'a mut Option<IssuingCardShipping>,
78        builder: IssuingCardShippingBuilder,
79    }
80
81    impl Visitor for Place<IssuingCardShipping> {
82        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
83            Ok(Box::new(Builder {
84                out: &mut self.out,
85                builder: IssuingCardShippingBuilder::deser_default(),
86            }))
87        }
88    }
89
90    impl MapBuilder for IssuingCardShippingBuilder {
91        type Out = IssuingCardShipping;
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            Ok(match k {
94                "address" => Deserialize::begin(&mut self.address),
95                "address_validation" => Deserialize::begin(&mut self.address_validation),
96                "carrier" => Deserialize::begin(&mut self.carrier),
97                "customs" => Deserialize::begin(&mut self.customs),
98                "eta" => Deserialize::begin(&mut self.eta),
99                "name" => Deserialize::begin(&mut self.name),
100                "phone_number" => Deserialize::begin(&mut self.phone_number),
101                "require_signature" => Deserialize::begin(&mut self.require_signature),
102                "service" => Deserialize::begin(&mut self.service),
103                "status" => Deserialize::begin(&mut self.status),
104                "tracking_number" => Deserialize::begin(&mut self.tracking_number),
105                "tracking_url" => Deserialize::begin(&mut self.tracking_url),
106                "type" => Deserialize::begin(&mut self.type_),
107                _ => <dyn Visitor>::ignore(),
108            })
109        }
110
111        fn deser_default() -> Self {
112            Self {
113                address: Deserialize::default(),
114                address_validation: Deserialize::default(),
115                carrier: Deserialize::default(),
116                customs: Deserialize::default(),
117                eta: Deserialize::default(),
118                name: Deserialize::default(),
119                phone_number: Deserialize::default(),
120                require_signature: Deserialize::default(),
121                service: Deserialize::default(),
122                status: Deserialize::default(),
123                tracking_number: Deserialize::default(),
124                tracking_url: Deserialize::default(),
125                type_: Deserialize::default(),
126            }
127        }
128
129        fn take_out(&mut self) -> Option<Self::Out> {
130            let (
131                Some(address),
132                Some(address_validation),
133                Some(carrier),
134                Some(customs),
135                Some(eta),
136                Some(name),
137                Some(phone_number),
138                Some(require_signature),
139                Some(service),
140                Some(status),
141                Some(tracking_number),
142                Some(tracking_url),
143                Some(type_),
144            ) = (
145                self.address.take(),
146                self.address_validation.take(),
147                self.carrier.take(),
148                self.customs.take(),
149                self.eta,
150                self.name.take(),
151                self.phone_number.take(),
152                self.require_signature,
153                self.service.take(),
154                self.status.take(),
155                self.tracking_number.take(),
156                self.tracking_url.take(),
157                self.type_.take(),
158            )
159            else {
160                return None;
161            };
162            Some(Self::Out {
163                address,
164                address_validation,
165                carrier,
166                customs,
167                eta,
168                name,
169                phone_number,
170                require_signature,
171                service,
172                status,
173                tracking_number,
174                tracking_url,
175                type_,
176            })
177        }
178    }
179
180    impl Map for Builder<'_> {
181        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
182            self.builder.key(k)
183        }
184
185        fn finish(&mut self) -> Result<()> {
186            *self.out = self.builder.take_out();
187            Ok(())
188        }
189    }
190
191    impl ObjectDeser for IssuingCardShipping {
192        type Builder = IssuingCardShippingBuilder;
193    }
194
195    impl FromValueOpt for IssuingCardShipping {
196        fn from_value(v: Value) -> Option<Self> {
197            let Value::Object(obj) = v else {
198                return None;
199            };
200            let mut b = IssuingCardShippingBuilder::deser_default();
201            for (k, v) in obj {
202                match k.as_str() {
203                    "address" => b.address = FromValueOpt::from_value(v),
204                    "address_validation" => b.address_validation = FromValueOpt::from_value(v),
205                    "carrier" => b.carrier = FromValueOpt::from_value(v),
206                    "customs" => b.customs = FromValueOpt::from_value(v),
207                    "eta" => b.eta = FromValueOpt::from_value(v),
208                    "name" => b.name = FromValueOpt::from_value(v),
209                    "phone_number" => b.phone_number = FromValueOpt::from_value(v),
210                    "require_signature" => b.require_signature = FromValueOpt::from_value(v),
211                    "service" => b.service = FromValueOpt::from_value(v),
212                    "status" => b.status = FromValueOpt::from_value(v),
213                    "tracking_number" => b.tracking_number = FromValueOpt::from_value(v),
214                    "tracking_url" => b.tracking_url = FromValueOpt::from_value(v),
215                    "type" => b.type_ = FromValueOpt::from_value(v),
216                    _ => {}
217                }
218            }
219            b.take_out()
220        }
221    }
222};
223/// The delivery company that shipped a card.
224#[derive(Clone, Eq, PartialEq)]
225#[non_exhaustive]
226pub enum IssuingCardShippingCarrier {
227    Dhl,
228    Fedex,
229    RoyalMail,
230    Usps,
231    /// An unrecognized value from Stripe. Should not be used as a request parameter.
232    Unknown(String),
233}
234impl IssuingCardShippingCarrier {
235    pub fn as_str(&self) -> &str {
236        use IssuingCardShippingCarrier::*;
237        match self {
238            Dhl => "dhl",
239            Fedex => "fedex",
240            RoyalMail => "royal_mail",
241            Usps => "usps",
242            Unknown(v) => v,
243        }
244    }
245}
246
247impl std::str::FromStr for IssuingCardShippingCarrier {
248    type Err = std::convert::Infallible;
249    fn from_str(s: &str) -> Result<Self, Self::Err> {
250        use IssuingCardShippingCarrier::*;
251        match s {
252            "dhl" => Ok(Dhl),
253            "fedex" => Ok(Fedex),
254            "royal_mail" => Ok(RoyalMail),
255            "usps" => Ok(Usps),
256            v => {
257                tracing::warn!("Unknown value '{}' for enum '{}'", v, "IssuingCardShippingCarrier");
258                Ok(Unknown(v.to_owned()))
259            }
260        }
261    }
262}
263impl std::fmt::Display for IssuingCardShippingCarrier {
264    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265        f.write_str(self.as_str())
266    }
267}
268
269impl std::fmt::Debug for IssuingCardShippingCarrier {
270    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271        f.write_str(self.as_str())
272    }
273}
274#[cfg(feature = "serialize")]
275impl serde::Serialize for IssuingCardShippingCarrier {
276    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
277    where
278        S: serde::Serializer,
279    {
280        serializer.serialize_str(self.as_str())
281    }
282}
283impl miniserde::Deserialize for IssuingCardShippingCarrier {
284    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
285        crate::Place::new(out)
286    }
287}
288
289impl miniserde::de::Visitor for crate::Place<IssuingCardShippingCarrier> {
290    fn string(&mut self, s: &str) -> miniserde::Result<()> {
291        use std::str::FromStr;
292        self.out = Some(IssuingCardShippingCarrier::from_str(s).expect("infallible"));
293        Ok(())
294    }
295}
296
297stripe_types::impl_from_val_with_from_str!(IssuingCardShippingCarrier);
298#[cfg(feature = "deserialize")]
299impl<'de> serde::Deserialize<'de> for IssuingCardShippingCarrier {
300    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
301        use std::str::FromStr;
302        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
303        Ok(Self::from_str(&s).expect("infallible"))
304    }
305}
306/// Shipment service, such as `standard` or `express`.
307#[derive(Clone, Eq, PartialEq)]
308#[non_exhaustive]
309pub enum IssuingCardShippingService {
310    Express,
311    Priority,
312    Standard,
313    /// An unrecognized value from Stripe. Should not be used as a request parameter.
314    Unknown(String),
315}
316impl IssuingCardShippingService {
317    pub fn as_str(&self) -> &str {
318        use IssuingCardShippingService::*;
319        match self {
320            Express => "express",
321            Priority => "priority",
322            Standard => "standard",
323            Unknown(v) => v,
324        }
325    }
326}
327
328impl std::str::FromStr for IssuingCardShippingService {
329    type Err = std::convert::Infallible;
330    fn from_str(s: &str) -> Result<Self, Self::Err> {
331        use IssuingCardShippingService::*;
332        match s {
333            "express" => Ok(Express),
334            "priority" => Ok(Priority),
335            "standard" => Ok(Standard),
336            v => {
337                tracing::warn!("Unknown value '{}' for enum '{}'", v, "IssuingCardShippingService");
338                Ok(Unknown(v.to_owned()))
339            }
340        }
341    }
342}
343impl std::fmt::Display for IssuingCardShippingService {
344    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
345        f.write_str(self.as_str())
346    }
347}
348
349impl std::fmt::Debug for IssuingCardShippingService {
350    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
351        f.write_str(self.as_str())
352    }
353}
354#[cfg(feature = "serialize")]
355impl serde::Serialize for IssuingCardShippingService {
356    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
357    where
358        S: serde::Serializer,
359    {
360        serializer.serialize_str(self.as_str())
361    }
362}
363impl miniserde::Deserialize for IssuingCardShippingService {
364    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
365        crate::Place::new(out)
366    }
367}
368
369impl miniserde::de::Visitor for crate::Place<IssuingCardShippingService> {
370    fn string(&mut self, s: &str) -> miniserde::Result<()> {
371        use std::str::FromStr;
372        self.out = Some(IssuingCardShippingService::from_str(s).expect("infallible"));
373        Ok(())
374    }
375}
376
377stripe_types::impl_from_val_with_from_str!(IssuingCardShippingService);
378#[cfg(feature = "deserialize")]
379impl<'de> serde::Deserialize<'de> for IssuingCardShippingService {
380    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
381        use std::str::FromStr;
382        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
383        Ok(Self::from_str(&s).expect("infallible"))
384    }
385}
386/// The delivery status of the card.
387#[derive(Clone, Eq, PartialEq)]
388#[non_exhaustive]
389pub enum IssuingCardShippingStatus {
390    Canceled,
391    Delivered,
392    Failure,
393    Pending,
394    Returned,
395    Shipped,
396    Submitted,
397    /// An unrecognized value from Stripe. Should not be used as a request parameter.
398    Unknown(String),
399}
400impl IssuingCardShippingStatus {
401    pub fn as_str(&self) -> &str {
402        use IssuingCardShippingStatus::*;
403        match self {
404            Canceled => "canceled",
405            Delivered => "delivered",
406            Failure => "failure",
407            Pending => "pending",
408            Returned => "returned",
409            Shipped => "shipped",
410            Submitted => "submitted",
411            Unknown(v) => v,
412        }
413    }
414}
415
416impl std::str::FromStr for IssuingCardShippingStatus {
417    type Err = std::convert::Infallible;
418    fn from_str(s: &str) -> Result<Self, Self::Err> {
419        use IssuingCardShippingStatus::*;
420        match s {
421            "canceled" => Ok(Canceled),
422            "delivered" => Ok(Delivered),
423            "failure" => Ok(Failure),
424            "pending" => Ok(Pending),
425            "returned" => Ok(Returned),
426            "shipped" => Ok(Shipped),
427            "submitted" => Ok(Submitted),
428            v => {
429                tracing::warn!("Unknown value '{}' for enum '{}'", v, "IssuingCardShippingStatus");
430                Ok(Unknown(v.to_owned()))
431            }
432        }
433    }
434}
435impl std::fmt::Display for IssuingCardShippingStatus {
436    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
437        f.write_str(self.as_str())
438    }
439}
440
441impl std::fmt::Debug for IssuingCardShippingStatus {
442    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
443        f.write_str(self.as_str())
444    }
445}
446#[cfg(feature = "serialize")]
447impl serde::Serialize for IssuingCardShippingStatus {
448    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
449    where
450        S: serde::Serializer,
451    {
452        serializer.serialize_str(self.as_str())
453    }
454}
455impl miniserde::Deserialize for IssuingCardShippingStatus {
456    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
457        crate::Place::new(out)
458    }
459}
460
461impl miniserde::de::Visitor for crate::Place<IssuingCardShippingStatus> {
462    fn string(&mut self, s: &str) -> miniserde::Result<()> {
463        use std::str::FromStr;
464        self.out = Some(IssuingCardShippingStatus::from_str(s).expect("infallible"));
465        Ok(())
466    }
467}
468
469stripe_types::impl_from_val_with_from_str!(IssuingCardShippingStatus);
470#[cfg(feature = "deserialize")]
471impl<'de> serde::Deserialize<'de> for IssuingCardShippingStatus {
472    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
473        use std::str::FromStr;
474        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
475        Ok(Self::from_str(&s).expect("infallible"))
476    }
477}
478/// Packaging options.
479#[derive(Clone, Eq, PartialEq)]
480#[non_exhaustive]
481pub enum IssuingCardShippingType {
482    Bulk,
483    Individual,
484    /// An unrecognized value from Stripe. Should not be used as a request parameter.
485    Unknown(String),
486}
487impl IssuingCardShippingType {
488    pub fn as_str(&self) -> &str {
489        use IssuingCardShippingType::*;
490        match self {
491            Bulk => "bulk",
492            Individual => "individual",
493            Unknown(v) => v,
494        }
495    }
496}
497
498impl std::str::FromStr for IssuingCardShippingType {
499    type Err = std::convert::Infallible;
500    fn from_str(s: &str) -> Result<Self, Self::Err> {
501        use IssuingCardShippingType::*;
502        match s {
503            "bulk" => Ok(Bulk),
504            "individual" => Ok(Individual),
505            v => {
506                tracing::warn!("Unknown value '{}' for enum '{}'", v, "IssuingCardShippingType");
507                Ok(Unknown(v.to_owned()))
508            }
509        }
510    }
511}
512impl std::fmt::Display for IssuingCardShippingType {
513    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
514        f.write_str(self.as_str())
515    }
516}
517
518impl std::fmt::Debug for IssuingCardShippingType {
519    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
520        f.write_str(self.as_str())
521    }
522}
523#[cfg(feature = "serialize")]
524impl serde::Serialize for IssuingCardShippingType {
525    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
526    where
527        S: serde::Serializer,
528    {
529        serializer.serialize_str(self.as_str())
530    }
531}
532impl miniserde::Deserialize for IssuingCardShippingType {
533    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
534        crate::Place::new(out)
535    }
536}
537
538impl miniserde::de::Visitor for crate::Place<IssuingCardShippingType> {
539    fn string(&mut self, s: &str) -> miniserde::Result<()> {
540        use std::str::FromStr;
541        self.out = Some(IssuingCardShippingType::from_str(s).expect("infallible"));
542        Ok(())
543    }
544}
545
546stripe_types::impl_from_val_with_from_str!(IssuingCardShippingType);
547#[cfg(feature = "deserialize")]
548impl<'de> serde::Deserialize<'de> for IssuingCardShippingType {
549    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
550        use std::str::FromStr;
551        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
552        Ok(Self::from_str(&s).expect("infallible"))
553    }
554}