stripe_shared/
account_branding_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountBrandingSettings {
5    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) An icon for the account.
6    /// Must be square and at least 128px x 128px.
7    pub icon: Option<stripe_types::Expandable<stripe_shared::File>>,
8    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) A logo for the account that will be used in Checkout instead of the icon and without the account's name next to it if provided.
9    /// Must be at least 128px x 128px.
10    pub logo: Option<stripe_types::Expandable<stripe_shared::File>>,
11    /// A CSS hex color value representing the primary branding color for this account
12    pub primary_color: Option<String>,
13    /// A CSS hex color value representing the secondary branding color for this account
14    pub secondary_color: Option<String>,
15}
16#[doc(hidden)]
17pub struct AccountBrandingSettingsBuilder {
18    icon: Option<Option<stripe_types::Expandable<stripe_shared::File>>>,
19    logo: Option<Option<stripe_types::Expandable<stripe_shared::File>>>,
20    primary_color: Option<Option<String>>,
21    secondary_color: 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::{make_place, Deserialize, Result};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for AccountBrandingSettings {
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<AccountBrandingSettings>,
48        builder: AccountBrandingSettingsBuilder,
49    }
50
51    impl Visitor for Place<AccountBrandingSettings> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: AccountBrandingSettingsBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for AccountBrandingSettingsBuilder {
61        type Out = AccountBrandingSettings;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "icon" => Deserialize::begin(&mut self.icon),
65                "logo" => Deserialize::begin(&mut self.logo),
66                "primary_color" => Deserialize::begin(&mut self.primary_color),
67                "secondary_color" => Deserialize::begin(&mut self.secondary_color),
68
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                icon: Deserialize::default(),
76                logo: Deserialize::default(),
77                primary_color: Deserialize::default(),
78                secondary_color: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(icon), Some(logo), Some(primary_color), Some(secondary_color)) = (
84                self.icon.take(),
85                self.logo.take(),
86                self.primary_color.take(),
87                self.secondary_color.take(),
88            ) else {
89                return None;
90            };
91            Some(Self::Out { icon, logo, primary_color, secondary_color })
92        }
93    }
94
95    impl<'a> Map for Builder<'a> {
96        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
97            self.builder.key(k)
98        }
99
100        fn finish(&mut self) -> Result<()> {
101            *self.out = self.builder.take_out();
102            Ok(())
103        }
104    }
105
106    impl ObjectDeser for AccountBrandingSettings {
107        type Builder = AccountBrandingSettingsBuilder;
108    }
109
110    impl FromValueOpt for AccountBrandingSettings {
111        fn from_value(v: Value) -> Option<Self> {
112            let Value::Object(obj) = v else {
113                return None;
114            };
115            let mut b = AccountBrandingSettingsBuilder::deser_default();
116            for (k, v) in obj {
117                match k.as_str() {
118                    "icon" => b.icon = FromValueOpt::from_value(v),
119                    "logo" => b.logo = FromValueOpt::from_value(v),
120                    "primary_color" => b.primary_color = FromValueOpt::from_value(v),
121                    "secondary_color" => b.secondary_color = FromValueOpt::from_value(v),
122
123                    _ => {}
124                }
125            }
126            b.take_out()
127        }
128    }
129};