stripe_shared/
payment_intent_next_action_display_bank_transfer_instructions.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentNextActionDisplayBankTransferInstructions {
5    /// The remaining amount that needs to be transferred to complete the payment.
6    pub amount_remaining: Option<i64>,
7    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
8    /// Must be a [supported currency](https://stripe.com/docs/currencies).
9    pub currency: Option<stripe_types::Currency>,
10    /// A list of financial addresses that can be used to fund the customer balance
11    pub financial_addresses:
12        Option<Vec<stripe_shared::FundingInstructionsBankTransferFinancialAddress>>,
13    /// A link to a hosted page that guides your customer through completing the transfer.
14    pub hosted_instructions_url: Option<String>,
15    /// A string identifying this payment.
16    /// Instruct your customer to include this code in the reference or memo field of their bank transfer.
17    pub reference: Option<String>,
18    /// Type of bank transfer
19    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
20    pub type_: PaymentIntentNextActionDisplayBankTransferInstructionsType,
21}
22#[doc(hidden)]
23pub struct PaymentIntentNextActionDisplayBankTransferInstructionsBuilder {
24    amount_remaining: Option<Option<i64>>,
25    currency: Option<Option<stripe_types::Currency>>,
26    financial_addresses:
27        Option<Option<Vec<stripe_shared::FundingInstructionsBankTransferFinancialAddress>>>,
28    hosted_instructions_url: Option<Option<String>>,
29    reference: Option<Option<String>>,
30    type_: Option<PaymentIntentNextActionDisplayBankTransferInstructionsType>,
31}
32
33#[allow(
34    unused_variables,
35    irrefutable_let_patterns,
36    clippy::let_unit_value,
37    clippy::match_single_binding,
38    clippy::single_match
39)]
40const _: () = {
41    use miniserde::de::{Map, Visitor};
42    use miniserde::json::Value;
43    use miniserde::{Deserialize, Result, make_place};
44    use stripe_types::miniserde_helpers::FromValueOpt;
45    use stripe_types::{MapBuilder, ObjectDeser};
46
47    make_place!(Place);
48
49    impl Deserialize for PaymentIntentNextActionDisplayBankTransferInstructions {
50        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
51            Place::new(out)
52        }
53    }
54
55    struct Builder<'a> {
56        out: &'a mut Option<PaymentIntentNextActionDisplayBankTransferInstructions>,
57        builder: PaymentIntentNextActionDisplayBankTransferInstructionsBuilder,
58    }
59
60    impl Visitor for Place<PaymentIntentNextActionDisplayBankTransferInstructions> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder:
65                    PaymentIntentNextActionDisplayBankTransferInstructionsBuilder::deser_default(),
66            }))
67        }
68    }
69
70    impl MapBuilder for PaymentIntentNextActionDisplayBankTransferInstructionsBuilder {
71        type Out = PaymentIntentNextActionDisplayBankTransferInstructions;
72        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
73            Ok(match k {
74                "amount_remaining" => Deserialize::begin(&mut self.amount_remaining),
75                "currency" => Deserialize::begin(&mut self.currency),
76                "financial_addresses" => Deserialize::begin(&mut self.financial_addresses),
77                "hosted_instructions_url" => Deserialize::begin(&mut self.hosted_instructions_url),
78                "reference" => Deserialize::begin(&mut self.reference),
79                "type" => Deserialize::begin(&mut self.type_),
80                _ => <dyn Visitor>::ignore(),
81            })
82        }
83
84        fn deser_default() -> Self {
85            Self {
86                amount_remaining: Deserialize::default(),
87                currency: Deserialize::default(),
88                financial_addresses: Deserialize::default(),
89                hosted_instructions_url: Deserialize::default(),
90                reference: Deserialize::default(),
91                type_: Deserialize::default(),
92            }
93        }
94
95        fn take_out(&mut self) -> Option<Self::Out> {
96            let (
97                Some(amount_remaining),
98                Some(currency),
99                Some(financial_addresses),
100                Some(hosted_instructions_url),
101                Some(reference),
102                Some(type_),
103            ) = (
104                self.amount_remaining,
105                self.currency.take(),
106                self.financial_addresses.take(),
107                self.hosted_instructions_url.take(),
108                self.reference.take(),
109                self.type_,
110            )
111            else {
112                return None;
113            };
114            Some(Self::Out {
115                amount_remaining,
116                currency,
117                financial_addresses,
118                hosted_instructions_url,
119                reference,
120                type_,
121            })
122        }
123    }
124
125    impl Map for Builder<'_> {
126        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
127            self.builder.key(k)
128        }
129
130        fn finish(&mut self) -> Result<()> {
131            *self.out = self.builder.take_out();
132            Ok(())
133        }
134    }
135
136    impl ObjectDeser for PaymentIntentNextActionDisplayBankTransferInstructions {
137        type Builder = PaymentIntentNextActionDisplayBankTransferInstructionsBuilder;
138    }
139
140    impl FromValueOpt for PaymentIntentNextActionDisplayBankTransferInstructions {
141        fn from_value(v: Value) -> Option<Self> {
142            let Value::Object(obj) = v else {
143                return None;
144            };
145            let mut b =
146                PaymentIntentNextActionDisplayBankTransferInstructionsBuilder::deser_default();
147            for (k, v) in obj {
148                match k.as_str() {
149                    "amount_remaining" => b.amount_remaining = FromValueOpt::from_value(v),
150                    "currency" => b.currency = FromValueOpt::from_value(v),
151                    "financial_addresses" => b.financial_addresses = FromValueOpt::from_value(v),
152                    "hosted_instructions_url" => {
153                        b.hosted_instructions_url = FromValueOpt::from_value(v)
154                    }
155                    "reference" => b.reference = FromValueOpt::from_value(v),
156                    "type" => b.type_ = FromValueOpt::from_value(v),
157                    _ => {}
158                }
159            }
160            b.take_out()
161        }
162    }
163};
164/// Type of bank transfer
165#[derive(Copy, Clone, Eq, PartialEq)]
166pub enum PaymentIntentNextActionDisplayBankTransferInstructionsType {
167    EuBankTransfer,
168    GbBankTransfer,
169    JpBankTransfer,
170    MxBankTransfer,
171    UsBankTransfer,
172}
173impl PaymentIntentNextActionDisplayBankTransferInstructionsType {
174    pub fn as_str(self) -> &'static str {
175        use PaymentIntentNextActionDisplayBankTransferInstructionsType::*;
176        match self {
177            EuBankTransfer => "eu_bank_transfer",
178            GbBankTransfer => "gb_bank_transfer",
179            JpBankTransfer => "jp_bank_transfer",
180            MxBankTransfer => "mx_bank_transfer",
181            UsBankTransfer => "us_bank_transfer",
182        }
183    }
184}
185
186impl std::str::FromStr for PaymentIntentNextActionDisplayBankTransferInstructionsType {
187    type Err = stripe_types::StripeParseError;
188    fn from_str(s: &str) -> Result<Self, Self::Err> {
189        use PaymentIntentNextActionDisplayBankTransferInstructionsType::*;
190        match s {
191            "eu_bank_transfer" => Ok(EuBankTransfer),
192            "gb_bank_transfer" => Ok(GbBankTransfer),
193            "jp_bank_transfer" => Ok(JpBankTransfer),
194            "mx_bank_transfer" => Ok(MxBankTransfer),
195            "us_bank_transfer" => Ok(UsBankTransfer),
196            _ => Err(stripe_types::StripeParseError),
197        }
198    }
199}
200impl std::fmt::Display for PaymentIntentNextActionDisplayBankTransferInstructionsType {
201    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
202        f.write_str(self.as_str())
203    }
204}
205
206impl std::fmt::Debug for PaymentIntentNextActionDisplayBankTransferInstructionsType {
207    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
208        f.write_str(self.as_str())
209    }
210}
211#[cfg(feature = "serialize")]
212impl serde::Serialize for PaymentIntentNextActionDisplayBankTransferInstructionsType {
213    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
214    where
215        S: serde::Serializer,
216    {
217        serializer.serialize_str(self.as_str())
218    }
219}
220impl miniserde::Deserialize for PaymentIntentNextActionDisplayBankTransferInstructionsType {
221    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
222        crate::Place::new(out)
223    }
224}
225
226impl miniserde::de::Visitor
227    for crate::Place<PaymentIntentNextActionDisplayBankTransferInstructionsType>
228{
229    fn string(&mut self, s: &str) -> miniserde::Result<()> {
230        use std::str::FromStr;
231        self.out = Some(
232            PaymentIntentNextActionDisplayBankTransferInstructionsType::from_str(s)
233                .map_err(|_| miniserde::Error)?,
234        );
235        Ok(())
236    }
237}
238
239stripe_types::impl_from_val_with_from_str!(
240    PaymentIntentNextActionDisplayBankTransferInstructionsType
241);
242#[cfg(feature = "deserialize")]
243impl<'de> serde::Deserialize<'de> for PaymentIntentNextActionDisplayBankTransferInstructionsType {
244    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
245        use std::str::FromStr;
246        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
247        Self::from_str(&s).map_err(|_| {
248            serde::de::Error::custom(
249                "Unknown value for PaymentIntentNextActionDisplayBankTransferInstructionsType",
250            )
251        })
252    }
253}