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::{make_place, Deserialize, Result};
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
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                arrival_date: Deserialize::default(),
72                hosted_verification_url: Deserialize::default(),
73                microdeposit_type: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(arrival_date), Some(hosted_verification_url), Some(microdeposit_type)) =
79                (self.arrival_date, self.hosted_verification_url.take(), self.microdeposit_type)
80            else {
81                return None;
82            };
83            Some(Self::Out { arrival_date, hosted_verification_url, microdeposit_type })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for PaymentIntentNextActionVerifyWithMicrodeposits {
99        type Builder = PaymentIntentNextActionVerifyWithMicrodepositsBuilder;
100    }
101
102    impl FromValueOpt for PaymentIntentNextActionVerifyWithMicrodeposits {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentIntentNextActionVerifyWithMicrodepositsBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
111                    "hosted_verification_url" => {
112                        b.hosted_verification_url = FromValueOpt::from_value(v)
113                    }
114                    "microdeposit_type" => b.microdeposit_type = FromValueOpt::from_value(v),
115
116                    _ => {}
117                }
118            }
119            b.take_out()
120        }
121    }
122};
123/// The type of the microdeposit sent to the customer.
124/// Used to distinguish between different verification methods.
125#[derive(Copy, Clone, Eq, PartialEq)]
126pub enum PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
127    Amounts,
128    DescriptorCode,
129}
130impl PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
131    pub fn as_str(self) -> &'static str {
132        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
133        match self {
134            Amounts => "amounts",
135            DescriptorCode => "descriptor_code",
136        }
137    }
138}
139
140impl std::str::FromStr for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
141    type Err = stripe_types::StripeParseError;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
144        match s {
145            "amounts" => Ok(Amounts),
146            "descriptor_code" => Ok(DescriptorCode),
147            _ => Err(stripe_types::StripeParseError),
148        }
149    }
150}
151impl std::fmt::Display for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156
157impl std::fmt::Debug for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.write_str(self.as_str())
160    }
161}
162#[cfg(feature = "serialize")]
163impl serde::Serialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
164    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
165    where
166        S: serde::Serializer,
167    {
168        serializer.serialize_str(self.as_str())
169    }
170}
171impl miniserde::Deserialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
172    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
173        crate::Place::new(out)
174    }
175}
176
177impl miniserde::de::Visitor
178    for crate::Place<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>
179{
180    fn string(&mut self, s: &str) -> miniserde::Result<()> {
181        use std::str::FromStr;
182        self.out = Some(
183            PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::from_str(s)
184                .map_err(|_| miniserde::Error)?,
185        );
186        Ok(())
187    }
188}
189
190stripe_types::impl_from_val_with_from_str!(
191    PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
192);
193#[cfg(feature = "deserialize")]
194impl<'de> serde::Deserialize<'de>
195    for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
196{
197    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
198        use std::str::FromStr;
199        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
200        Self::from_str(&s).map_err(|_| {
201            serde::de::Error::custom(
202                "Unknown value for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType",
203            )
204        })
205    }
206}