Skip to main content

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