stripe_shared/
subscriptions_resource_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 SubscriptionsResourcePaymentSettings {
5    /// Payment-method-specific configuration to provide to invoices created by the subscription.
6    pub payment_method_options: Option<stripe_shared::SubscriptionsResourcePaymentMethodOptions>,
7    /// The list of payment method types to provide to every invoice created by the subscription.
8    /// 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).
9    pub payment_method_types: Option<Vec<SubscriptionsResourcePaymentSettingsPaymentMethodTypes>>,
10    /// Configure whether Stripe updates `subscription.default_payment_method` when payment succeeds.
11    /// Defaults to `off`.
12    pub save_default_payment_method:
13        Option<SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod>,
14}
15#[doc(hidden)]
16pub struct SubscriptionsResourcePaymentSettingsBuilder {
17    payment_method_options:
18        Option<Option<stripe_shared::SubscriptionsResourcePaymentMethodOptions>>,
19    payment_method_types:
20        Option<Option<Vec<SubscriptionsResourcePaymentSettingsPaymentMethodTypes>>>,
21    save_default_payment_method:
22        Option<Option<SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod>>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for SubscriptionsResourcePaymentSettings {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<SubscriptionsResourcePaymentSettings>,
49        builder: SubscriptionsResourcePaymentSettingsBuilder,
50    }
51
52    impl Visitor for Place<SubscriptionsResourcePaymentSettings> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: SubscriptionsResourcePaymentSettingsBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for SubscriptionsResourcePaymentSettingsBuilder {
62        type Out = SubscriptionsResourcePaymentSettings;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
66                "payment_method_types" => Deserialize::begin(&mut self.payment_method_types),
67                "save_default_payment_method" => {
68                    Deserialize::begin(&mut self.save_default_payment_method)
69                }
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                payment_method_options: Deserialize::default(),
77                payment_method_types: Deserialize::default(),
78                save_default_payment_method: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (
84                Some(payment_method_options),
85                Some(payment_method_types),
86                Some(save_default_payment_method),
87            ) = (
88                self.payment_method_options.take(),
89                self.payment_method_types.take(),
90                self.save_default_payment_method.take(),
91            )
92            else {
93                return None;
94            };
95            Some(Self::Out {
96                payment_method_options,
97                payment_method_types,
98                save_default_payment_method,
99            })
100        }
101    }
102
103    impl Map for Builder<'_> {
104        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
105            self.builder.key(k)
106        }
107
108        fn finish(&mut self) -> Result<()> {
109            *self.out = self.builder.take_out();
110            Ok(())
111        }
112    }
113
114    impl ObjectDeser for SubscriptionsResourcePaymentSettings {
115        type Builder = SubscriptionsResourcePaymentSettingsBuilder;
116    }
117
118    impl FromValueOpt for SubscriptionsResourcePaymentSettings {
119        fn from_value(v: Value) -> Option<Self> {
120            let Value::Object(obj) = v else {
121                return None;
122            };
123            let mut b = SubscriptionsResourcePaymentSettingsBuilder::deser_default();
124            for (k, v) in obj {
125                match k.as_str() {
126                    "payment_method_options" => {
127                        b.payment_method_options = FromValueOpt::from_value(v)
128                    }
129                    "payment_method_types" => b.payment_method_types = FromValueOpt::from_value(v),
130                    "save_default_payment_method" => {
131                        b.save_default_payment_method = FromValueOpt::from_value(v)
132                    }
133                    _ => {}
134                }
135            }
136            b.take_out()
137        }
138    }
139};
140/// The list of payment method types to provide to every invoice created by the subscription.
141/// 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).
142#[derive(Clone, Eq, PartialEq)]
143#[non_exhaustive]
144pub enum SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
145    AchCreditTransfer,
146    AchDebit,
147    AcssDebit,
148    Affirm,
149    AmazonPay,
150    AuBecsDebit,
151    BacsDebit,
152    Bancontact,
153    Boleto,
154    Card,
155    Cashapp,
156    Crypto,
157    Custom,
158    CustomerBalance,
159    Eps,
160    Fpx,
161    Giropay,
162    Grabpay,
163    Ideal,
164    JpCreditTransfer,
165    KakaoPay,
166    Klarna,
167    Konbini,
168    KrCard,
169    Link,
170    Multibanco,
171    NaverPay,
172    NzBankAccount,
173    P24,
174    Payco,
175    Paynow,
176    Paypal,
177    Payto,
178    Promptpay,
179    RevolutPay,
180    SepaCreditTransfer,
181    SepaDebit,
182    Sofort,
183    Swish,
184    UsBankAccount,
185    WechatPay,
186    /// An unrecognized value from Stripe. Should not be used as a request parameter.
187    Unknown(String),
188}
189impl SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
190    pub fn as_str(&self) -> &str {
191        use SubscriptionsResourcePaymentSettingsPaymentMethodTypes::*;
192        match self {
193            AchCreditTransfer => "ach_credit_transfer",
194            AchDebit => "ach_debit",
195            AcssDebit => "acss_debit",
196            Affirm => "affirm",
197            AmazonPay => "amazon_pay",
198            AuBecsDebit => "au_becs_debit",
199            BacsDebit => "bacs_debit",
200            Bancontact => "bancontact",
201            Boleto => "boleto",
202            Card => "card",
203            Cashapp => "cashapp",
204            Crypto => "crypto",
205            Custom => "custom",
206            CustomerBalance => "customer_balance",
207            Eps => "eps",
208            Fpx => "fpx",
209            Giropay => "giropay",
210            Grabpay => "grabpay",
211            Ideal => "ideal",
212            JpCreditTransfer => "jp_credit_transfer",
213            KakaoPay => "kakao_pay",
214            Klarna => "klarna",
215            Konbini => "konbini",
216            KrCard => "kr_card",
217            Link => "link",
218            Multibanco => "multibanco",
219            NaverPay => "naver_pay",
220            NzBankAccount => "nz_bank_account",
221            P24 => "p24",
222            Payco => "payco",
223            Paynow => "paynow",
224            Paypal => "paypal",
225            Payto => "payto",
226            Promptpay => "promptpay",
227            RevolutPay => "revolut_pay",
228            SepaCreditTransfer => "sepa_credit_transfer",
229            SepaDebit => "sepa_debit",
230            Sofort => "sofort",
231            Swish => "swish",
232            UsBankAccount => "us_bank_account",
233            WechatPay => "wechat_pay",
234            Unknown(v) => v,
235        }
236    }
237}
238
239impl std::str::FromStr for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
240    type Err = std::convert::Infallible;
241    fn from_str(s: &str) -> Result<Self, Self::Err> {
242        use SubscriptionsResourcePaymentSettingsPaymentMethodTypes::*;
243        match s {
244            "ach_credit_transfer" => Ok(AchCreditTransfer),
245            "ach_debit" => Ok(AchDebit),
246            "acss_debit" => Ok(AcssDebit),
247            "affirm" => Ok(Affirm),
248            "amazon_pay" => Ok(AmazonPay),
249            "au_becs_debit" => Ok(AuBecsDebit),
250            "bacs_debit" => Ok(BacsDebit),
251            "bancontact" => Ok(Bancontact),
252            "boleto" => Ok(Boleto),
253            "card" => Ok(Card),
254            "cashapp" => Ok(Cashapp),
255            "crypto" => Ok(Crypto),
256            "custom" => Ok(Custom),
257            "customer_balance" => Ok(CustomerBalance),
258            "eps" => Ok(Eps),
259            "fpx" => Ok(Fpx),
260            "giropay" => Ok(Giropay),
261            "grabpay" => Ok(Grabpay),
262            "ideal" => Ok(Ideal),
263            "jp_credit_transfer" => Ok(JpCreditTransfer),
264            "kakao_pay" => Ok(KakaoPay),
265            "klarna" => Ok(Klarna),
266            "konbini" => Ok(Konbini),
267            "kr_card" => Ok(KrCard),
268            "link" => Ok(Link),
269            "multibanco" => Ok(Multibanco),
270            "naver_pay" => Ok(NaverPay),
271            "nz_bank_account" => Ok(NzBankAccount),
272            "p24" => Ok(P24),
273            "payco" => Ok(Payco),
274            "paynow" => Ok(Paynow),
275            "paypal" => Ok(Paypal),
276            "payto" => Ok(Payto),
277            "promptpay" => Ok(Promptpay),
278            "revolut_pay" => Ok(RevolutPay),
279            "sepa_credit_transfer" => Ok(SepaCreditTransfer),
280            "sepa_debit" => Ok(SepaDebit),
281            "sofort" => Ok(Sofort),
282            "swish" => Ok(Swish),
283            "us_bank_account" => Ok(UsBankAccount),
284            "wechat_pay" => Ok(WechatPay),
285            v => {
286                tracing::warn!(
287                    "Unknown value '{}' for enum '{}'",
288                    v,
289                    "SubscriptionsResourcePaymentSettingsPaymentMethodTypes"
290                );
291                Ok(Unknown(v.to_owned()))
292            }
293        }
294    }
295}
296impl std::fmt::Display for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
297    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
298        f.write_str(self.as_str())
299    }
300}
301
302impl std::fmt::Debug for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
303    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
304        f.write_str(self.as_str())
305    }
306}
307#[cfg(feature = "serialize")]
308impl serde::Serialize for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
309    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
310    where
311        S: serde::Serializer,
312    {
313        serializer.serialize_str(self.as_str())
314    }
315}
316impl miniserde::Deserialize for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
317    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
318        crate::Place::new(out)
319    }
320}
321
322impl miniserde::de::Visitor
323    for crate::Place<SubscriptionsResourcePaymentSettingsPaymentMethodTypes>
324{
325    fn string(&mut self, s: &str) -> miniserde::Result<()> {
326        use std::str::FromStr;
327        self.out = Some(
328            SubscriptionsResourcePaymentSettingsPaymentMethodTypes::from_str(s)
329                .expect("infallible"),
330        );
331        Ok(())
332    }
333}
334
335stripe_types::impl_from_val_with_from_str!(SubscriptionsResourcePaymentSettingsPaymentMethodTypes);
336#[cfg(feature = "deserialize")]
337impl<'de> serde::Deserialize<'de> for SubscriptionsResourcePaymentSettingsPaymentMethodTypes {
338    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
339        use std::str::FromStr;
340        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
341        Ok(Self::from_str(&s).expect("infallible"))
342    }
343}
344/// Configure whether Stripe updates `subscription.default_payment_method` when payment succeeds.
345/// Defaults to `off`.
346#[derive(Clone, Eq, PartialEq)]
347#[non_exhaustive]
348pub enum SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
349    Off,
350    OnSubscription,
351    /// An unrecognized value from Stripe. Should not be used as a request parameter.
352    Unknown(String),
353}
354impl SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
355    pub fn as_str(&self) -> &str {
356        use SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod::*;
357        match self {
358            Off => "off",
359            OnSubscription => "on_subscription",
360            Unknown(v) => v,
361        }
362    }
363}
364
365impl std::str::FromStr for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
366    type Err = std::convert::Infallible;
367    fn from_str(s: &str) -> Result<Self, Self::Err> {
368        use SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod::*;
369        match s {
370            "off" => Ok(Off),
371            "on_subscription" => Ok(OnSubscription),
372            v => {
373                tracing::warn!(
374                    "Unknown value '{}' for enum '{}'",
375                    v,
376                    "SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod"
377                );
378                Ok(Unknown(v.to_owned()))
379            }
380        }
381    }
382}
383impl std::fmt::Display for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
384    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
385        f.write_str(self.as_str())
386    }
387}
388
389impl std::fmt::Debug for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
390    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
391        f.write_str(self.as_str())
392    }
393}
394#[cfg(feature = "serialize")]
395impl serde::Serialize for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
396    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
397    where
398        S: serde::Serializer,
399    {
400        serializer.serialize_str(self.as_str())
401    }
402}
403impl miniserde::Deserialize for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
404    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
405        crate::Place::new(out)
406    }
407}
408
409impl miniserde::de::Visitor
410    for crate::Place<SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod>
411{
412    fn string(&mut self, s: &str) -> miniserde::Result<()> {
413        use std::str::FromStr;
414        self.out = Some(
415            SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod::from_str(s)
416                .expect("infallible"),
417        );
418        Ok(())
419    }
420}
421
422stripe_types::impl_from_val_with_from_str!(
423    SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod
424);
425#[cfg(feature = "deserialize")]
426impl<'de> serde::Deserialize<'de> for SubscriptionsResourcePaymentSettingsSaveDefaultPaymentMethod {
427    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
428        use std::str::FromStr;
429        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
430        Ok(Self::from_str(&s).expect("infallible"))
431    }
432}