stripe_shared/
payment_method_details_sepa_debit.rs

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