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    Promptpay,
163    RevolutPay,
164    SepaCreditTransfer,
165    SepaDebit,
166    Sofort,
167    Swish,
168    UsBankAccount,
169    WechatPay,
170    /// An unrecognized value from Stripe. Should not be used as a request parameter.
171    Unknown(String),
172}
173impl InvoicesPaymentSettingsPaymentMethodTypes {
174    pub fn as_str(&self) -> &str {
175        use InvoicesPaymentSettingsPaymentMethodTypes::*;
176        match self {
177            AchCreditTransfer => "ach_credit_transfer",
178            AchDebit => "ach_debit",
179            AcssDebit => "acss_debit",
180            Affirm => "affirm",
181            AmazonPay => "amazon_pay",
182            AuBecsDebit => "au_becs_debit",
183            BacsDebit => "bacs_debit",
184            Bancontact => "bancontact",
185            Boleto => "boleto",
186            Card => "card",
187            Cashapp => "cashapp",
188            Crypto => "crypto",
189            Custom => "custom",
190            CustomerBalance => "customer_balance",
191            Eps => "eps",
192            Fpx => "fpx",
193            Giropay => "giropay",
194            Grabpay => "grabpay",
195            Ideal => "ideal",
196            JpCreditTransfer => "jp_credit_transfer",
197            KakaoPay => "kakao_pay",
198            Klarna => "klarna",
199            Konbini => "konbini",
200            KrCard => "kr_card",
201            Link => "link",
202            Multibanco => "multibanco",
203            NaverPay => "naver_pay",
204            NzBankAccount => "nz_bank_account",
205            P24 => "p24",
206            Payco => "payco",
207            Paynow => "paynow",
208            Paypal => "paypal",
209            Promptpay => "promptpay",
210            RevolutPay => "revolut_pay",
211            SepaCreditTransfer => "sepa_credit_transfer",
212            SepaDebit => "sepa_debit",
213            Sofort => "sofort",
214            Swish => "swish",
215            UsBankAccount => "us_bank_account",
216            WechatPay => "wechat_pay",
217            Unknown(v) => v,
218        }
219    }
220}
221
222impl std::str::FromStr for InvoicesPaymentSettingsPaymentMethodTypes {
223    type Err = std::convert::Infallible;
224    fn from_str(s: &str) -> Result<Self, Self::Err> {
225        use InvoicesPaymentSettingsPaymentMethodTypes::*;
226        match s {
227            "ach_credit_transfer" => Ok(AchCreditTransfer),
228            "ach_debit" => Ok(AchDebit),
229            "acss_debit" => Ok(AcssDebit),
230            "affirm" => Ok(Affirm),
231            "amazon_pay" => Ok(AmazonPay),
232            "au_becs_debit" => Ok(AuBecsDebit),
233            "bacs_debit" => Ok(BacsDebit),
234            "bancontact" => Ok(Bancontact),
235            "boleto" => Ok(Boleto),
236            "card" => Ok(Card),
237            "cashapp" => Ok(Cashapp),
238            "crypto" => Ok(Crypto),
239            "custom" => Ok(Custom),
240            "customer_balance" => Ok(CustomerBalance),
241            "eps" => Ok(Eps),
242            "fpx" => Ok(Fpx),
243            "giropay" => Ok(Giropay),
244            "grabpay" => Ok(Grabpay),
245            "ideal" => Ok(Ideal),
246            "jp_credit_transfer" => Ok(JpCreditTransfer),
247            "kakao_pay" => Ok(KakaoPay),
248            "klarna" => Ok(Klarna),
249            "konbini" => Ok(Konbini),
250            "kr_card" => Ok(KrCard),
251            "link" => Ok(Link),
252            "multibanco" => Ok(Multibanco),
253            "naver_pay" => Ok(NaverPay),
254            "nz_bank_account" => Ok(NzBankAccount),
255            "p24" => Ok(P24),
256            "payco" => Ok(Payco),
257            "paynow" => Ok(Paynow),
258            "paypal" => Ok(Paypal),
259            "promptpay" => Ok(Promptpay),
260            "revolut_pay" => Ok(RevolutPay),
261            "sepa_credit_transfer" => Ok(SepaCreditTransfer),
262            "sepa_debit" => Ok(SepaDebit),
263            "sofort" => Ok(Sofort),
264            "swish" => Ok(Swish),
265            "us_bank_account" => Ok(UsBankAccount),
266            "wechat_pay" => Ok(WechatPay),
267            v => Ok(Unknown(v.to_owned())),
268        }
269    }
270}
271impl std::fmt::Display for InvoicesPaymentSettingsPaymentMethodTypes {
272    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
273        f.write_str(self.as_str())
274    }
275}
276
277impl std::fmt::Debug for InvoicesPaymentSettingsPaymentMethodTypes {
278    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
279        f.write_str(self.as_str())
280    }
281}
282#[cfg(feature = "serialize")]
283impl serde::Serialize for InvoicesPaymentSettingsPaymentMethodTypes {
284    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
285    where
286        S: serde::Serializer,
287    {
288        serializer.serialize_str(self.as_str())
289    }
290}
291impl miniserde::Deserialize for InvoicesPaymentSettingsPaymentMethodTypes {
292    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
293        crate::Place::new(out)
294    }
295}
296
297impl miniserde::de::Visitor for crate::Place<InvoicesPaymentSettingsPaymentMethodTypes> {
298    fn string(&mut self, s: &str) -> miniserde::Result<()> {
299        use std::str::FromStr;
300        self.out = Some(InvoicesPaymentSettingsPaymentMethodTypes::from_str(s).unwrap());
301        Ok(())
302    }
303}
304
305stripe_types::impl_from_val_with_from_str!(InvoicesPaymentSettingsPaymentMethodTypes);
306#[cfg(feature = "deserialize")]
307impl<'de> serde::Deserialize<'de> for InvoicesPaymentSettingsPaymentMethodTypes {
308    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
309        use std::str::FromStr;
310        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
311        Ok(Self::from_str(&s).unwrap())
312    }
313}