stripe_shared/
issuing_card_wallets.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardWallets {
5    pub apple_pay: stripe_shared::IssuingCardApplePay,
6    pub google_pay: stripe_shared::IssuingCardGooglePay,
7    /// Unique identifier for a card used with digital wallets
8    pub primary_account_identifier: Option<String>,
9}
10#[doc(hidden)]
11pub struct IssuingCardWalletsBuilder {
12    apple_pay: Option<stripe_shared::IssuingCardApplePay>,
13    google_pay: Option<stripe_shared::IssuingCardGooglePay>,
14    primary_account_identifier: Option<Option<String>>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for IssuingCardWallets {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<IssuingCardWallets>,
41        builder: IssuingCardWalletsBuilder,
42    }
43
44    impl Visitor for Place<IssuingCardWallets> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: IssuingCardWalletsBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for IssuingCardWalletsBuilder {
54        type Out = IssuingCardWallets;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "apple_pay" => Deserialize::begin(&mut self.apple_pay),
58                "google_pay" => Deserialize::begin(&mut self.google_pay),
59                "primary_account_identifier" => {
60                    Deserialize::begin(&mut self.primary_account_identifier)
61                }
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                apple_pay: Deserialize::default(),
69                google_pay: Deserialize::default(),
70                primary_account_identifier: Deserialize::default(),
71            }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(apple_pay), Some(google_pay), Some(primary_account_identifier)) =
76                (self.apple_pay, self.google_pay, self.primary_account_identifier.take())
77            else {
78                return None;
79            };
80            Some(Self::Out { apple_pay, google_pay, primary_account_identifier })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for IssuingCardWallets {
96        type Builder = IssuingCardWalletsBuilder;
97    }
98
99    impl FromValueOpt for IssuingCardWallets {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = IssuingCardWalletsBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "apple_pay" => b.apple_pay = FromValueOpt::from_value(v),
108                    "google_pay" => b.google_pay = FromValueOpt::from_value(v),
109                    "primary_account_identifier" => {
110                        b.primary_account_identifier = FromValueOpt::from_value(v)
111                    }
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};