Skip to main content

stripe_shared/
issuing_card_wallets.rs

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