stripe_shared/
funding_instructions_bank_transfer_spei_record.rs

1/// SPEI Records contain Mexico bank account details per the SPEI format.
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct FundingInstructionsBankTransferSpeiRecord {
6    pub account_holder_address: stripe_shared::Address,
7    /// The account holder name
8    pub account_holder_name: String,
9    pub bank_address: stripe_shared::Address,
10    /// The three-digit bank code
11    pub bank_code: String,
12    /// The short banking institution name
13    pub bank_name: String,
14    /// The CLABE number
15    pub clabe: String,
16}
17#[doc(hidden)]
18pub struct FundingInstructionsBankTransferSpeiRecordBuilder {
19    account_holder_address: Option<stripe_shared::Address>,
20    account_holder_name: Option<String>,
21    bank_address: Option<stripe_shared::Address>,
22    bank_code: Option<String>,
23    bank_name: Option<String>,
24    clabe: Option<String>,
25}
26
27#[allow(
28    unused_variables,
29    irrefutable_let_patterns,
30    clippy::let_unit_value,
31    clippy::match_single_binding,
32    clippy::single_match
33)]
34const _: () = {
35    use miniserde::de::{Map, Visitor};
36    use miniserde::json::Value;
37    use miniserde::{Deserialize, Result, make_place};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for FundingInstructionsBankTransferSpeiRecord {
44        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
45            Place::new(out)
46        }
47    }
48
49    struct Builder<'a> {
50        out: &'a mut Option<FundingInstructionsBankTransferSpeiRecord>,
51        builder: FundingInstructionsBankTransferSpeiRecordBuilder,
52    }
53
54    impl Visitor for Place<FundingInstructionsBankTransferSpeiRecord> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: FundingInstructionsBankTransferSpeiRecordBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for FundingInstructionsBankTransferSpeiRecordBuilder {
64        type Out = FundingInstructionsBankTransferSpeiRecord;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "account_holder_address" => Deserialize::begin(&mut self.account_holder_address),
68                "account_holder_name" => Deserialize::begin(&mut self.account_holder_name),
69                "bank_address" => Deserialize::begin(&mut self.bank_address),
70                "bank_code" => Deserialize::begin(&mut self.bank_code),
71                "bank_name" => Deserialize::begin(&mut self.bank_name),
72                "clabe" => Deserialize::begin(&mut self.clabe),
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                account_holder_address: Deserialize::default(),
80                account_holder_name: Deserialize::default(),
81                bank_address: Deserialize::default(),
82                bank_code: Deserialize::default(),
83                bank_name: Deserialize::default(),
84                clabe: Deserialize::default(),
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (
90                Some(account_holder_address),
91                Some(account_holder_name),
92                Some(bank_address),
93                Some(bank_code),
94                Some(bank_name),
95                Some(clabe),
96            ) = (
97                self.account_holder_address.take(),
98                self.account_holder_name.take(),
99                self.bank_address.take(),
100                self.bank_code.take(),
101                self.bank_name.take(),
102                self.clabe.take(),
103            )
104            else {
105                return None;
106            };
107            Some(Self::Out {
108                account_holder_address,
109                account_holder_name,
110                bank_address,
111                bank_code,
112                bank_name,
113                clabe,
114            })
115        }
116    }
117
118    impl Map for Builder<'_> {
119        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
120            self.builder.key(k)
121        }
122
123        fn finish(&mut self) -> Result<()> {
124            *self.out = self.builder.take_out();
125            Ok(())
126        }
127    }
128
129    impl ObjectDeser for FundingInstructionsBankTransferSpeiRecord {
130        type Builder = FundingInstructionsBankTransferSpeiRecordBuilder;
131    }
132
133    impl FromValueOpt for FundingInstructionsBankTransferSpeiRecord {
134        fn from_value(v: Value) -> Option<Self> {
135            let Value::Object(obj) = v else {
136                return None;
137            };
138            let mut b = FundingInstructionsBankTransferSpeiRecordBuilder::deser_default();
139            for (k, v) in obj {
140                match k.as_str() {
141                    "account_holder_address" => {
142                        b.account_holder_address = FromValueOpt::from_value(v)
143                    }
144                    "account_holder_name" => b.account_holder_name = FromValueOpt::from_value(v),
145                    "bank_address" => b.bank_address = FromValueOpt::from_value(v),
146                    "bank_code" => b.bank_code = FromValueOpt::from_value(v),
147                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
148                    "clabe" => b.clabe = FromValueOpt::from_value(v),
149                    _ => {}
150                }
151            }
152            b.take_out()
153        }
154    }
155};