stripe_shared/
payment_intent_next_action_verify_with_microdeposits.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentNextActionVerifyWithMicrodeposits {
5    /// The timestamp when the microdeposits are expected to land.
6    pub arrival_date: stripe_types::Timestamp,
7    /// The URL for the hosted verification page, which allows customers to verify their bank account.
8    pub hosted_verification_url: String,
9    /// The type of the microdeposit sent to the customer.
10    /// Used to distinguish between different verification methods.
11    pub microdeposit_type: Option<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>,
12}
13#[doc(hidden)]
14pub struct PaymentIntentNextActionVerifyWithMicrodepositsBuilder {
15    arrival_date: Option<stripe_types::Timestamp>,
16    hosted_verification_url: Option<String>,
17    microdeposit_type:
18        Option<Option<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for PaymentIntentNextActionVerifyWithMicrodeposits {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<PaymentIntentNextActionVerifyWithMicrodeposits>,
45        builder: PaymentIntentNextActionVerifyWithMicrodepositsBuilder,
46    }
47
48    impl Visitor for Place<PaymentIntentNextActionVerifyWithMicrodeposits> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: PaymentIntentNextActionVerifyWithMicrodepositsBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for PaymentIntentNextActionVerifyWithMicrodepositsBuilder {
58        type Out = PaymentIntentNextActionVerifyWithMicrodeposits;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "arrival_date" => Deserialize::begin(&mut self.arrival_date),
62                "hosted_verification_url" => Deserialize::begin(&mut self.hosted_verification_url),
63                "microdeposit_type" => Deserialize::begin(&mut self.microdeposit_type),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                arrival_date: Deserialize::default(),
71                hosted_verification_url: Deserialize::default(),
72                microdeposit_type: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(arrival_date), Some(hosted_verification_url), Some(microdeposit_type)) =
78                (self.arrival_date, self.hosted_verification_url.take(), self.microdeposit_type)
79            else {
80                return None;
81            };
82            Some(Self::Out { arrival_date, hosted_verification_url, microdeposit_type })
83        }
84    }
85
86    impl Map for Builder<'_> {
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 PaymentIntentNextActionVerifyWithMicrodeposits {
98        type Builder = PaymentIntentNextActionVerifyWithMicrodepositsBuilder;
99    }
100
101    impl FromValueOpt for PaymentIntentNextActionVerifyWithMicrodeposits {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentIntentNextActionVerifyWithMicrodepositsBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
110                    "hosted_verification_url" => {
111                        b.hosted_verification_url = FromValueOpt::from_value(v)
112                    }
113                    "microdeposit_type" => b.microdeposit_type = FromValueOpt::from_value(v),
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// The type of the microdeposit sent to the customer.
122/// Used to distinguish between different verification methods.
123#[derive(Copy, Clone, Eq, PartialEq)]
124pub enum PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
125    Amounts,
126    DescriptorCode,
127}
128impl PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
129    pub fn as_str(self) -> &'static str {
130        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
131        match self {
132            Amounts => "amounts",
133            DescriptorCode => "descriptor_code",
134        }
135    }
136}
137
138impl std::str::FromStr for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
139    type Err = stripe_types::StripeParseError;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
142        match s {
143            "amounts" => Ok(Amounts),
144            "descriptor_code" => Ok(DescriptorCode),
145            _ => Err(stripe_types::StripeParseError),
146        }
147    }
148}
149impl std::fmt::Display for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154
155impl std::fmt::Debug for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
156    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157        f.write_str(self.as_str())
158    }
159}
160#[cfg(feature = "serialize")]
161impl serde::Serialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
162    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163    where
164        S: serde::Serializer,
165    {
166        serializer.serialize_str(self.as_str())
167    }
168}
169impl miniserde::Deserialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
170    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
171        crate::Place::new(out)
172    }
173}
174
175impl miniserde::de::Visitor
176    for crate::Place<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>
177{
178    fn string(&mut self, s: &str) -> miniserde::Result<()> {
179        use std::str::FromStr;
180        self.out = Some(
181            PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::from_str(s)
182                .map_err(|_| miniserde::Error)?,
183        );
184        Ok(())
185    }
186}
187
188stripe_types::impl_from_val_with_from_str!(
189    PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
190);
191#[cfg(feature = "deserialize")]
192impl<'de> serde::Deserialize<'de>
193    for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
194{
195    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
196        use std::str::FromStr;
197        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
198        Self::from_str(&s).map_err(|_| {
199            serde::de::Error::custom(
200                "Unknown value for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType",
201            )
202        })
203    }
204}