stripe_shared/
invoices_payment_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicesPaymentSettings {
5    /// ID of the mandate to be used for this invoice.
6    /// It must correspond to the payment method used to pay the invoice, including the invoice's default_payment_method or default_source, if set.
7    pub default_mandate: Option<String>,
8    /// Payment-method-specific configuration to provide to the invoice’s PaymentIntent.
9    pub payment_method_options: Option<stripe_shared::InvoicesPaymentMethodOptions>,
10    /// The list of payment method types (e.g.
11    /// card) to provide to the invoice’s PaymentIntent.
12    /// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
13    pub payment_method_types: Option<Vec<InvoicesPaymentSettingsPaymentMethodTypes>>,
14}
15#[doc(hidden)]
16pub struct InvoicesPaymentSettingsBuilder {
17    default_mandate: Option<Option<String>>,
18    payment_method_options: Option<Option<stripe_shared::InvoicesPaymentMethodOptions>>,
19    payment_method_types: Option<Option<Vec<InvoicesPaymentSettingsPaymentMethodTypes>>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for InvoicesPaymentSettings {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<InvoicesPaymentSettings>,
46        builder: InvoicesPaymentSettingsBuilder,
47    }
48
49    impl Visitor for Place<InvoicesPaymentSettings> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: InvoicesPaymentSettingsBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for InvoicesPaymentSettingsBuilder {
59        type Out = InvoicesPaymentSettings;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "default_mandate" => Deserialize::begin(&mut self.default_mandate),
63                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
64                "payment_method_types" => Deserialize::begin(&mut self.payment_method_types),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                default_mandate: Deserialize::default(),
72                payment_method_options: Deserialize::default(),
73                payment_method_types: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(default_mandate), Some(payment_method_options), Some(payment_method_types)) = (
79                self.default_mandate.take(),
80                self.payment_method_options.take(),
81                self.payment_method_types.take(),
82            ) else {
83                return None;
84            };
85            Some(Self::Out { default_mandate, payment_method_options, payment_method_types })
86        }
87    }
88
89    impl Map for Builder<'_> {
90        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
91            self.builder.key(k)
92        }
93
94        fn finish(&mut self) -> Result<()> {
95            *self.out = self.builder.take_out();
96            Ok(())
97        }
98    }
99
100    impl ObjectDeser for InvoicesPaymentSettings {
101        type Builder = InvoicesPaymentSettingsBuilder;
102    }
103
104    impl FromValueOpt for InvoicesPaymentSettings {
105        fn from_value(v: Value) -> Option<Self> {
106            let Value::Object(obj) = v else {
107                return None;
108            };
109            let mut b = InvoicesPaymentSettingsBuilder::deser_default();
110            for (k, v) in obj {
111                match k.as_str() {
112                    "default_mandate" => b.default_mandate = FromValueOpt::from_value(v),
113                    "payment_method_options" => {
114                        b.payment_method_options = FromValueOpt::from_value(v)
115                    }
116                    "payment_method_types" => b.payment_method_types = FromValueOpt::from_value(v),
117                    _ => {}
118                }
119            }
120            b.take_out()
121        }
122    }
123};
124/// The list of payment method types (e.g.
125/// card) to provide to the invoice’s PaymentIntent.
126/// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
127#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum InvoicesPaymentSettingsPaymentMethodTypes {
130    AchCreditTransfer,
131    AchDebit,
132    AcssDebit,
133    Affirm,
134    AmazonPay,
135    AuBecsDebit,
136    BacsDebit,
137    Bancontact,
138    Boleto,
139    Card,
140    Cashapp,
141    Crypto,
142    Custom,
143    CustomerBalance,
144    Eps,
145    Fpx,
146    Giropay,
147    Grabpay,
148    Ideal,
149    JpCreditTransfer,
150    KakaoPay,
151    Klarna,
152    Konbini,
153    KrCard,
154    Link,
155    Multibanco,
156    NaverPay,
157    NzBankAccount,
158    P24,
159    Payco,
160    Paynow,
161    Paypal,
162    Payto,
163    Promptpay,
164    RevolutPay,
165    SepaCreditTransfer,
166    SepaDebit,
167    Sofort,
168    Swish,
169    UsBankAccount,
170    WechatPay,
171    /// An unrecognized value from Stripe. Should not be used as a request parameter.
172    Unknown(String),
173}
174impl InvoicesPaymentSettingsPaymentMethodTypes {
175    pub fn as_str(&self) -> &str {
176        use InvoicesPaymentSettingsPaymentMethodTypes::*;
177        match self {
178            AchCreditTransfer => "ach_credit_transfer",
179            AchDebit => "ach_debit",
180            AcssDebit => "acss_debit",
181            Affirm => "affirm",
182            AmazonPay => "amazon_pay",
183            AuBecsDebit => "au_becs_debit",
184            BacsDebit => "bacs_debit",
185            Bancontact => "bancontact",
186            Boleto => "boleto",
187            Card => "card",
188            Cashapp => "cashapp",
189            Crypto => "crypto",
190            Custom => "custom",
191            CustomerBalance => "customer_balance",
192            Eps => "eps",
193            Fpx => "fpx",
194            Giropay => "giropay",
195            Grabpay => "grabpay",
196            Ideal => "ideal",
197            JpCreditTransfer => "jp_credit_transfer",
198            KakaoPay => "kakao_pay",
199            Klarna => "klarna",
200            Konbini => "konbini",
201            KrCard => "kr_card",
202            Link => "link",
203            Multibanco => "multibanco",
204            NaverPay => "naver_pay",
205            NzBankAccount => "nz_bank_account",
206            P24 => "p24",
207            Payco => "payco",
208            Paynow => "paynow",
209            Paypal => "paypal",
210            Payto => "payto",
211            Promptpay => "promptpay",
212            RevolutPay => "revolut_pay",
213            SepaCreditTransfer => "sepa_credit_transfer",
214            SepaDebit => "sepa_debit",
215            Sofort => "sofort",
216            Swish => "swish",
217            UsBankAccount => "us_bank_account",
218            WechatPay => "wechat_pay",
219            Unknown(v) => v,
220        }
221    }
222}
223
224impl std::str::FromStr for InvoicesPaymentSettingsPaymentMethodTypes {
225    type Err = std::convert::Infallible;
226    fn from_str(s: &str) -> Result<Self, Self::Err> {
227        use InvoicesPaymentSettingsPaymentMethodTypes::*;
228        match s {
229            "ach_credit_transfer" => Ok(AchCreditTransfer),
230            "ach_debit" => Ok(AchDebit),
231            "acss_debit" => Ok(AcssDebit),
232            "affirm" => Ok(Affirm),
233            "amazon_pay" => Ok(AmazonPay),
234            "au_becs_debit" => Ok(AuBecsDebit),
235            "bacs_debit" => Ok(BacsDebit),
236            "bancontact" => Ok(Bancontact),
237            "boleto" => Ok(Boleto),
238            "card" => Ok(Card),
239            "cashapp" => Ok(Cashapp),
240            "crypto" => Ok(Crypto),
241            "custom" => Ok(Custom),
242            "customer_balance" => Ok(CustomerBalance),
243            "eps" => Ok(Eps),
244            "fpx" => Ok(Fpx),
245            "giropay" => Ok(Giropay),
246            "grabpay" => Ok(Grabpay),
247            "ideal" => Ok(Ideal),
248            "jp_credit_transfer" => Ok(JpCreditTransfer),
249            "kakao_pay" => Ok(KakaoPay),
250            "klarna" => Ok(Klarna),
251            "konbini" => Ok(Konbini),
252            "kr_card" => Ok(KrCard),
253            "link" => Ok(Link),
254            "multibanco" => Ok(Multibanco),
255            "naver_pay" => Ok(NaverPay),
256            "nz_bank_account" => Ok(NzBankAccount),
257            "p24" => Ok(P24),
258            "payco" => Ok(Payco),
259            "paynow" => Ok(Paynow),
260            "paypal" => Ok(Paypal),
261            "payto" => Ok(Payto),
262            "promptpay" => Ok(Promptpay),
263            "revolut_pay" => Ok(RevolutPay),
264            "sepa_credit_transfer" => Ok(SepaCreditTransfer),
265            "sepa_debit" => Ok(SepaDebit),
266            "sofort" => Ok(Sofort),
267            "swish" => Ok(Swish),
268            "us_bank_account" => Ok(UsBankAccount),
269            "wechat_pay" => Ok(WechatPay),
270            v => {
271                tracing::warn!(
272                    "Unknown value '{}' for enum '{}'",
273                    v,
274                    "InvoicesPaymentSettingsPaymentMethodTypes"
275                );
276                Ok(Unknown(v.to_owned()))
277            }
278        }
279    }
280}
281impl std::fmt::Display for InvoicesPaymentSettingsPaymentMethodTypes {
282    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
283        f.write_str(self.as_str())
284    }
285}
286
287impl std::fmt::Debug for InvoicesPaymentSettingsPaymentMethodTypes {
288    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
289        f.write_str(self.as_str())
290    }
291}
292#[cfg(feature = "serialize")]
293impl serde::Serialize for InvoicesPaymentSettingsPaymentMethodTypes {
294    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
295    where
296        S: serde::Serializer,
297    {
298        serializer.serialize_str(self.as_str())
299    }
300}
301impl miniserde::Deserialize for InvoicesPaymentSettingsPaymentMethodTypes {
302    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
303        crate::Place::new(out)
304    }
305}
306
307impl miniserde::de::Visitor for crate::Place<InvoicesPaymentSettingsPaymentMethodTypes> {
308    fn string(&mut self, s: &str) -> miniserde::Result<()> {
309        use std::str::FromStr;
310        self.out =
311            Some(InvoicesPaymentSettingsPaymentMethodTypes::from_str(s).expect("infallible"));
312        Ok(())
313    }
314}
315
316stripe_types::impl_from_val_with_from_str!(InvoicesPaymentSettingsPaymentMethodTypes);
317#[cfg(feature = "deserialize")]
318impl<'de> serde::Deserialize<'de> for InvoicesPaymentSettingsPaymentMethodTypes {
319    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
320        use std::str::FromStr;
321        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
322        Ok(Self::from_str(&s).expect("infallible"))
323    }
324}