stripe_shared/
payment_method_bacs_debit.rs

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