Skip to main content

stripe_shared/
payment_method_card_generated_card.rs

1#[derive(Clone)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentMethodCardGeneratedCard {
6    /// The charge that created this object.
7    pub charge: Option<String>,
8    /// Transaction-specific details of the payment method used in the payment.
9    pub payment_method_details: Option<stripe_shared::CardGeneratedFromPaymentMethodDetails>,
10    /// The ID of the SetupAttempt that generated this PaymentMethod, if any.
11    pub setup_attempt: Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for PaymentMethodCardGeneratedCard {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        f.debug_struct("PaymentMethodCardGeneratedCard").finish_non_exhaustive()
17    }
18}
19#[doc(hidden)]
20pub struct PaymentMethodCardGeneratedCardBuilder {
21    charge: Option<Option<String>>,
22    payment_method_details: Option<Option<stripe_shared::CardGeneratedFromPaymentMethodDetails>>,
23    setup_attempt: Option<Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>>,
24}
25
26#[allow(
27    unused_variables,
28    irrefutable_let_patterns,
29    clippy::let_unit_value,
30    clippy::match_single_binding,
31    clippy::single_match
32)]
33const _: () = {
34    use miniserde::de::{Map, Visitor};
35    use miniserde::json::Value;
36    use miniserde::{Deserialize, Result, make_place};
37    use stripe_types::miniserde_helpers::FromValueOpt;
38    use stripe_types::{MapBuilder, ObjectDeser};
39
40    make_place!(Place);
41
42    impl Deserialize for PaymentMethodCardGeneratedCard {
43        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
44            Place::new(out)
45        }
46    }
47
48    struct Builder<'a> {
49        out: &'a mut Option<PaymentMethodCardGeneratedCard>,
50        builder: PaymentMethodCardGeneratedCardBuilder,
51    }
52
53    impl Visitor for Place<PaymentMethodCardGeneratedCard> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: PaymentMethodCardGeneratedCardBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for PaymentMethodCardGeneratedCardBuilder {
63        type Out = PaymentMethodCardGeneratedCard;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "charge" => Deserialize::begin(&mut self.charge),
67                "payment_method_details" => Deserialize::begin(&mut self.payment_method_details),
68                "setup_attempt" => Deserialize::begin(&mut self.setup_attempt),
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                charge: Some(None),
76                payment_method_details: Some(None),
77                setup_attempt: Some(None),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(charge), Some(payment_method_details), Some(setup_attempt)) =
83                (self.charge.take(), self.payment_method_details.take(), self.setup_attempt.take())
84            else {
85                return None;
86            };
87            Some(Self::Out { charge, payment_method_details, setup_attempt })
88        }
89    }
90
91    impl Map for Builder<'_> {
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            self.builder.key(k)
94        }
95
96        fn finish(&mut self) -> Result<()> {
97            *self.out = self.builder.take_out();
98            Ok(())
99        }
100    }
101
102    impl ObjectDeser for PaymentMethodCardGeneratedCard {
103        type Builder = PaymentMethodCardGeneratedCardBuilder;
104    }
105
106    impl FromValueOpt for PaymentMethodCardGeneratedCard {
107        fn from_value(v: Value) -> Option<Self> {
108            let Value::Object(obj) = v else {
109                return None;
110            };
111            let mut b = PaymentMethodCardGeneratedCardBuilder::deser_default();
112            for (k, v) in obj {
113                match k.as_str() {
114                    "charge" => b.charge = FromValueOpt::from_value(v),
115                    "payment_method_details" => {
116                        b.payment_method_details = FromValueOpt::from_value(v)
117                    }
118                    "setup_attempt" => b.setup_attempt = FromValueOpt::from_value(v),
119                    _ => {}
120                }
121            }
122            b.take_out()
123        }
124    }
125};