stripe_shared/
checkout_customer_balance_payment_method_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutCustomerBalancePaymentMethodOptions {
5    pub bank_transfer:
6        Option<stripe_shared::CheckoutCustomerBalanceBankTransferPaymentMethodOptions>,
7    /// The funding method type to be used when there are not enough funds in the customer balance.
8    /// Permitted values include: `bank_transfer`.
9    pub funding_type: Option<CheckoutCustomerBalancePaymentMethodOptionsFundingType>,
10    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
11    ///
12    /// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
13    /// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
14    ///
15    /// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
16    ///
17    /// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
18    pub setup_future_usage: Option<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>,
19}
20#[doc(hidden)]
21pub struct CheckoutCustomerBalancePaymentMethodOptionsBuilder {
22    bank_transfer:
23        Option<Option<stripe_shared::CheckoutCustomerBalanceBankTransferPaymentMethodOptions>>,
24    funding_type: Option<Option<CheckoutCustomerBalancePaymentMethodOptionsFundingType>>,
25    setup_future_usage: Option<Option<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>>,
26}
27
28#[allow(
29    unused_variables,
30    irrefutable_let_patterns,
31    clippy::let_unit_value,
32    clippy::match_single_binding,
33    clippy::single_match
34)]
35const _: () = {
36    use miniserde::de::{Map, Visitor};
37    use miniserde::json::Value;
38    use miniserde::{make_place, Deserialize, Result};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for CheckoutCustomerBalancePaymentMethodOptions {
45        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
46            Place::new(out)
47        }
48    }
49
50    struct Builder<'a> {
51        out: &'a mut Option<CheckoutCustomerBalancePaymentMethodOptions>,
52        builder: CheckoutCustomerBalancePaymentMethodOptionsBuilder,
53    }
54
55    impl Visitor for Place<CheckoutCustomerBalancePaymentMethodOptions> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: CheckoutCustomerBalancePaymentMethodOptionsBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for CheckoutCustomerBalancePaymentMethodOptionsBuilder {
65        type Out = CheckoutCustomerBalancePaymentMethodOptions;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "bank_transfer" => Deserialize::begin(&mut self.bank_transfer),
69                "funding_type" => Deserialize::begin(&mut self.funding_type),
70                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
71
72                _ => <dyn Visitor>::ignore(),
73            })
74        }
75
76        fn deser_default() -> Self {
77            Self {
78                bank_transfer: Deserialize::default(),
79                funding_type: Deserialize::default(),
80                setup_future_usage: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (Some(bank_transfer), Some(funding_type), Some(setup_future_usage)) =
86                (self.bank_transfer.take(), self.funding_type, self.setup_future_usage)
87            else {
88                return None;
89            };
90            Some(Self::Out { bank_transfer, funding_type, setup_future_usage })
91        }
92    }
93
94    impl Map for Builder<'_> {
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            self.builder.key(k)
97        }
98
99        fn finish(&mut self) -> Result<()> {
100            *self.out = self.builder.take_out();
101            Ok(())
102        }
103    }
104
105    impl ObjectDeser for CheckoutCustomerBalancePaymentMethodOptions {
106        type Builder = CheckoutCustomerBalancePaymentMethodOptionsBuilder;
107    }
108
109    impl FromValueOpt for CheckoutCustomerBalancePaymentMethodOptions {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = CheckoutCustomerBalancePaymentMethodOptionsBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "bank_transfer" => b.bank_transfer = FromValueOpt::from_value(v),
118                    "funding_type" => b.funding_type = FromValueOpt::from_value(v),
119                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
120
121                    _ => {}
122                }
123            }
124            b.take_out()
125        }
126    }
127};
128/// The funding method type to be used when there are not enough funds in the customer balance.
129/// Permitted values include: `bank_transfer`.
130#[derive(Copy, Clone, Eq, PartialEq)]
131pub enum CheckoutCustomerBalancePaymentMethodOptionsFundingType {
132    BankTransfer,
133}
134impl CheckoutCustomerBalancePaymentMethodOptionsFundingType {
135    pub fn as_str(self) -> &'static str {
136        use CheckoutCustomerBalancePaymentMethodOptionsFundingType::*;
137        match self {
138            BankTransfer => "bank_transfer",
139        }
140    }
141}
142
143impl std::str::FromStr for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
144    type Err = stripe_types::StripeParseError;
145    fn from_str(s: &str) -> Result<Self, Self::Err> {
146        use CheckoutCustomerBalancePaymentMethodOptionsFundingType::*;
147        match s {
148            "bank_transfer" => Ok(BankTransfer),
149            _ => Err(stripe_types::StripeParseError),
150        }
151    }
152}
153impl std::fmt::Display for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158
159impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164#[cfg(feature = "serialize")]
165impl serde::Serialize for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
166    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
167    where
168        S: serde::Serializer,
169    {
170        serializer.serialize_str(self.as_str())
171    }
172}
173impl miniserde::Deserialize for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
174    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
175        crate::Place::new(out)
176    }
177}
178
179impl miniserde::de::Visitor
180    for crate::Place<CheckoutCustomerBalancePaymentMethodOptionsFundingType>
181{
182    fn string(&mut self, s: &str) -> miniserde::Result<()> {
183        use std::str::FromStr;
184        self.out = Some(
185            CheckoutCustomerBalancePaymentMethodOptionsFundingType::from_str(s)
186                .map_err(|_| miniserde::Error)?,
187        );
188        Ok(())
189    }
190}
191
192stripe_types::impl_from_val_with_from_str!(CheckoutCustomerBalancePaymentMethodOptionsFundingType);
193#[cfg(feature = "deserialize")]
194impl<'de> serde::Deserialize<'de> for CheckoutCustomerBalancePaymentMethodOptionsFundingType {
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 CheckoutCustomerBalancePaymentMethodOptionsFundingType",
201            )
202        })
203    }
204}
205/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
206///
207/// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
208/// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
209///
210/// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
211///
212/// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
213#[derive(Copy, Clone, Eq, PartialEq)]
214pub enum CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
215    None,
216}
217impl CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
218    pub fn as_str(self) -> &'static str {
219        use CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::*;
220        match self {
221            None => "none",
222        }
223    }
224}
225
226impl std::str::FromStr for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
227    type Err = stripe_types::StripeParseError;
228    fn from_str(s: &str) -> Result<Self, Self::Err> {
229        use CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::*;
230        match s {
231            "none" => Ok(None),
232            _ => Err(stripe_types::StripeParseError),
233        }
234    }
235}
236impl std::fmt::Display for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
237    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238        f.write_str(self.as_str())
239    }
240}
241
242impl std::fmt::Debug for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
243    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244        f.write_str(self.as_str())
245    }
246}
247#[cfg(feature = "serialize")]
248impl serde::Serialize for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
249    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
250    where
251        S: serde::Serializer,
252    {
253        serializer.serialize_str(self.as_str())
254    }
255}
256impl miniserde::Deserialize for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
257    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
258        crate::Place::new(out)
259    }
260}
261
262impl miniserde::de::Visitor
263    for crate::Place<CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage>
264{
265    fn string(&mut self, s: &str) -> miniserde::Result<()> {
266        use std::str::FromStr;
267        self.out = Some(
268            CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage::from_str(s)
269                .map_err(|_| miniserde::Error)?,
270        );
271        Ok(())
272    }
273}
274
275stripe_types::impl_from_val_with_from_str!(
276    CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage
277);
278#[cfg(feature = "deserialize")]
279impl<'de> serde::Deserialize<'de> for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage {
280    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
281        use std::str::FromStr;
282        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
283        Self::from_str(&s).map_err(|_| {
284            serde::de::Error::custom(
285                "Unknown value for CheckoutCustomerBalancePaymentMethodOptionsSetupFutureUsage",
286            )
287        })
288    }
289}