Skip to main content

stripe_shared/
payment_method_sepa_debit.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 PaymentMethodSepaDebit {
6    /// Bank code of bank associated with the bank account.
7    pub bank_code: Option<String>,
8    /// Branch code of bank associated with the bank account.
9    pub branch_code: Option<String>,
10    /// Two-letter ISO code representing the country the bank account is located in.
11    pub country: Option<String>,
12    /// Uniquely identifies this particular bank account.
13    /// You can use this attribute to check whether two bank accounts are the same.
14    pub fingerprint: Option<String>,
15    /// Information about the object that generated this PaymentMethod.
16    pub generated_from: Option<stripe_shared::SepaDebitGeneratedFrom>,
17    /// Last four characters of the IBAN.
18    pub last4: Option<String>,
19}
20#[cfg(feature = "redact-generated-debug")]
21impl std::fmt::Debug for PaymentMethodSepaDebit {
22    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23        f.debug_struct("PaymentMethodSepaDebit").finish_non_exhaustive()
24    }
25}
26#[doc(hidden)]
27pub struct PaymentMethodSepaDebitBuilder {
28    bank_code: Option<Option<String>>,
29    branch_code: Option<Option<String>>,
30    country: Option<Option<String>>,
31    fingerprint: Option<Option<String>>,
32    generated_from: Option<Option<stripe_shared::SepaDebitGeneratedFrom>>,
33    last4: Option<Option<String>>,
34}
35
36#[allow(
37    unused_variables,
38    irrefutable_let_patterns,
39    clippy::let_unit_value,
40    clippy::match_single_binding,
41    clippy::single_match
42)]
43const _: () = {
44    use miniserde::de::{Map, Visitor};
45    use miniserde::json::Value;
46    use miniserde::{Deserialize, Result, make_place};
47    use stripe_types::miniserde_helpers::FromValueOpt;
48    use stripe_types::{MapBuilder, ObjectDeser};
49
50    make_place!(Place);
51
52    impl Deserialize for PaymentMethodSepaDebit {
53        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
54            Place::new(out)
55        }
56    }
57
58    struct Builder<'a> {
59        out: &'a mut Option<PaymentMethodSepaDebit>,
60        builder: PaymentMethodSepaDebitBuilder,
61    }
62
63    impl Visitor for Place<PaymentMethodSepaDebit> {
64        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
65            Ok(Box::new(Builder {
66                out: &mut self.out,
67                builder: PaymentMethodSepaDebitBuilder::deser_default(),
68            }))
69        }
70    }
71
72    impl MapBuilder for PaymentMethodSepaDebitBuilder {
73        type Out = PaymentMethodSepaDebit;
74        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
75            Ok(match k {
76                "bank_code" => Deserialize::begin(&mut self.bank_code),
77                "branch_code" => Deserialize::begin(&mut self.branch_code),
78                "country" => Deserialize::begin(&mut self.country),
79                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
80                "generated_from" => Deserialize::begin(&mut self.generated_from),
81                "last4" => Deserialize::begin(&mut self.last4),
82                _ => <dyn Visitor>::ignore(),
83            })
84        }
85
86        fn deser_default() -> Self {
87            Self {
88                bank_code: Some(None),
89                branch_code: Some(None),
90                country: Some(None),
91                fingerprint: Some(None),
92                generated_from: Some(None),
93                last4: Some(None),
94            }
95        }
96
97        fn take_out(&mut self) -> Option<Self::Out> {
98            let (
99                Some(bank_code),
100                Some(branch_code),
101                Some(country),
102                Some(fingerprint),
103                Some(generated_from),
104                Some(last4),
105            ) = (
106                self.bank_code.take(),
107                self.branch_code.take(),
108                self.country.take(),
109                self.fingerprint.take(),
110                self.generated_from.take(),
111                self.last4.take(),
112            )
113            else {
114                return None;
115            };
116            Some(Self::Out { bank_code, branch_code, country, fingerprint, generated_from, last4 })
117        }
118    }
119
120    impl Map for Builder<'_> {
121        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
122            self.builder.key(k)
123        }
124
125        fn finish(&mut self) -> Result<()> {
126            *self.out = self.builder.take_out();
127            Ok(())
128        }
129    }
130
131    impl ObjectDeser for PaymentMethodSepaDebit {
132        type Builder = PaymentMethodSepaDebitBuilder;
133    }
134
135    impl FromValueOpt for PaymentMethodSepaDebit {
136        fn from_value(v: Value) -> Option<Self> {
137            let Value::Object(obj) = v else {
138                return None;
139            };
140            let mut b = PaymentMethodSepaDebitBuilder::deser_default();
141            for (k, v) in obj {
142                match k.as_str() {
143                    "bank_code" => b.bank_code = FromValueOpt::from_value(v),
144                    "branch_code" => b.branch_code = FromValueOpt::from_value(v),
145                    "country" => b.country = FromValueOpt::from_value(v),
146                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
147                    "generated_from" => b.generated_from = FromValueOpt::from_value(v),
148                    "last4" => b.last4 = FromValueOpt::from_value(v),
149                    _ => {}
150                }
151            }
152            b.take_out()
153        }
154    }
155};