Skip to main content

stripe_shared/
payment_method_us_bank_account_blocked.rs

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