stripe_shared/
payment_method_us_bank_account_blocked.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodUsBankAccountBlocked {
5    /// The ACH network code that resulted in this block.
6    pub network_code: Option<PaymentMethodUsBankAccountBlockedNetworkCode>,
7    /// The reason why this PaymentMethod's fingerprint has been blocked
8    pub reason: Option<PaymentMethodUsBankAccountBlockedReason>,
9}
10#[doc(hidden)]
11pub struct PaymentMethodUsBankAccountBlockedBuilder {
12    network_code: Option<Option<PaymentMethodUsBankAccountBlockedNetworkCode>>,
13    reason: Option<Option<PaymentMethodUsBankAccountBlockedReason>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for PaymentMethodUsBankAccountBlocked {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<PaymentMethodUsBankAccountBlocked>,
40        builder: PaymentMethodUsBankAccountBlockedBuilder,
41    }
42
43    impl Visitor for Place<PaymentMethodUsBankAccountBlocked> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PaymentMethodUsBankAccountBlockedBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PaymentMethodUsBankAccountBlockedBuilder {
53        type Out = PaymentMethodUsBankAccountBlocked;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "network_code" => Deserialize::begin(&mut self.network_code),
57                "reason" => Deserialize::begin(&mut self.reason),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { network_code: Deserialize::default(), reason: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(network_code), Some(reason)) = (self.network_code.take(), self.reason.take())
68            else {
69                return None;
70            };
71            Some(Self::Out { network_code, reason })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for PaymentMethodUsBankAccountBlocked {
87        type Builder = PaymentMethodUsBankAccountBlockedBuilder;
88    }
89
90    impl FromValueOpt for PaymentMethodUsBankAccountBlocked {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = PaymentMethodUsBankAccountBlockedBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "network_code" => b.network_code = FromValueOpt::from_value(v),
99                    "reason" => b.reason = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// The ACH network code that resulted in this block.
108#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum PaymentMethodUsBankAccountBlockedNetworkCode {
111    R02,
112    R03,
113    R04,
114    R05,
115    R07,
116    R08,
117    R10,
118    R11,
119    R16,
120    R20,
121    R29,
122    R31,
123    /// An unrecognized value from Stripe. Should not be used as a request parameter.
124    Unknown(String),
125}
126impl PaymentMethodUsBankAccountBlockedNetworkCode {
127    pub fn as_str(&self) -> &str {
128        use PaymentMethodUsBankAccountBlockedNetworkCode::*;
129        match self {
130            R02 => "R02",
131            R03 => "R03",
132            R04 => "R04",
133            R05 => "R05",
134            R07 => "R07",
135            R08 => "R08",
136            R10 => "R10",
137            R11 => "R11",
138            R16 => "R16",
139            R20 => "R20",
140            R29 => "R29",
141            R31 => "R31",
142            Unknown(v) => v,
143        }
144    }
145}
146
147impl std::str::FromStr for PaymentMethodUsBankAccountBlockedNetworkCode {
148    type Err = std::convert::Infallible;
149    fn from_str(s: &str) -> Result<Self, Self::Err> {
150        use PaymentMethodUsBankAccountBlockedNetworkCode::*;
151        match s {
152            "R02" => Ok(R02),
153            "R03" => Ok(R03),
154            "R04" => Ok(R04),
155            "R05" => Ok(R05),
156            "R07" => Ok(R07),
157            "R08" => Ok(R08),
158            "R10" => Ok(R10),
159            "R11" => Ok(R11),
160            "R16" => Ok(R16),
161            "R20" => Ok(R20),
162            "R29" => Ok(R29),
163            "R31" => Ok(R31),
164            v => {
165                tracing::warn!(
166                    "Unknown value '{}' for enum '{}'",
167                    v,
168                    "PaymentMethodUsBankAccountBlockedNetworkCode"
169                );
170                Ok(Unknown(v.to_owned()))
171            }
172        }
173    }
174}
175impl std::fmt::Display for PaymentMethodUsBankAccountBlockedNetworkCode {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.write_str(self.as_str())
178    }
179}
180
181impl std::fmt::Debug for PaymentMethodUsBankAccountBlockedNetworkCode {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.write_str(self.as_str())
184    }
185}
186#[cfg(feature = "serialize")]
187impl serde::Serialize for PaymentMethodUsBankAccountBlockedNetworkCode {
188    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
189    where
190        S: serde::Serializer,
191    {
192        serializer.serialize_str(self.as_str())
193    }
194}
195impl miniserde::Deserialize for PaymentMethodUsBankAccountBlockedNetworkCode {
196    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
197        crate::Place::new(out)
198    }
199}
200
201impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountBlockedNetworkCode> {
202    fn string(&mut self, s: &str) -> miniserde::Result<()> {
203        use std::str::FromStr;
204        self.out =
205            Some(PaymentMethodUsBankAccountBlockedNetworkCode::from_str(s).expect("infallible"));
206        Ok(())
207    }
208}
209
210stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountBlockedNetworkCode);
211#[cfg(feature = "deserialize")]
212impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountBlockedNetworkCode {
213    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
214        use std::str::FromStr;
215        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
216        Ok(Self::from_str(&s).expect("infallible"))
217    }
218}
219/// The reason why this PaymentMethod's fingerprint has been blocked
220#[derive(Clone, Eq, PartialEq)]
221#[non_exhaustive]
222pub enum PaymentMethodUsBankAccountBlockedReason {
223    BankAccountClosed,
224    BankAccountFrozen,
225    BankAccountInvalidDetails,
226    BankAccountRestricted,
227    BankAccountUnusable,
228    DebitNotAuthorized,
229    TokenizedAccountNumberDeactivated,
230    /// An unrecognized value from Stripe. Should not be used as a request parameter.
231    Unknown(String),
232}
233impl PaymentMethodUsBankAccountBlockedReason {
234    pub fn as_str(&self) -> &str {
235        use PaymentMethodUsBankAccountBlockedReason::*;
236        match self {
237            BankAccountClosed => "bank_account_closed",
238            BankAccountFrozen => "bank_account_frozen",
239            BankAccountInvalidDetails => "bank_account_invalid_details",
240            BankAccountRestricted => "bank_account_restricted",
241            BankAccountUnusable => "bank_account_unusable",
242            DebitNotAuthorized => "debit_not_authorized",
243            TokenizedAccountNumberDeactivated => "tokenized_account_number_deactivated",
244            Unknown(v) => v,
245        }
246    }
247}
248
249impl std::str::FromStr for PaymentMethodUsBankAccountBlockedReason {
250    type Err = std::convert::Infallible;
251    fn from_str(s: &str) -> Result<Self, Self::Err> {
252        use PaymentMethodUsBankAccountBlockedReason::*;
253        match s {
254            "bank_account_closed" => Ok(BankAccountClosed),
255            "bank_account_frozen" => Ok(BankAccountFrozen),
256            "bank_account_invalid_details" => Ok(BankAccountInvalidDetails),
257            "bank_account_restricted" => Ok(BankAccountRestricted),
258            "bank_account_unusable" => Ok(BankAccountUnusable),
259            "debit_not_authorized" => Ok(DebitNotAuthorized),
260            "tokenized_account_number_deactivated" => Ok(TokenizedAccountNumberDeactivated),
261            v => {
262                tracing::warn!(
263                    "Unknown value '{}' for enum '{}'",
264                    v,
265                    "PaymentMethodUsBankAccountBlockedReason"
266                );
267                Ok(Unknown(v.to_owned()))
268            }
269        }
270    }
271}
272impl std::fmt::Display for PaymentMethodUsBankAccountBlockedReason {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        f.write_str(self.as_str())
275    }
276}
277
278impl std::fmt::Debug for PaymentMethodUsBankAccountBlockedReason {
279    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
280        f.write_str(self.as_str())
281    }
282}
283#[cfg(feature = "serialize")]
284impl serde::Serialize for PaymentMethodUsBankAccountBlockedReason {
285    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
286    where
287        S: serde::Serializer,
288    {
289        serializer.serialize_str(self.as_str())
290    }
291}
292impl miniserde::Deserialize for PaymentMethodUsBankAccountBlockedReason {
293    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
294        crate::Place::new(out)
295    }
296}
297
298impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountBlockedReason> {
299    fn string(&mut self, s: &str) -> miniserde::Result<()> {
300        use std::str::FromStr;
301        self.out = Some(PaymentMethodUsBankAccountBlockedReason::from_str(s).expect("infallible"));
302        Ok(())
303    }
304}
305
306stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountBlockedReason);
307#[cfg(feature = "deserialize")]
308impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountBlockedReason {
309    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
310        use std::str::FromStr;
311        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
312        Ok(Self::from_str(&s).expect("infallible"))
313    }
314}