Skip to main content

stripe_shared/
checkout_upi_payment_method_options.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 CheckoutUpiPaymentMethodOptions {
6    pub mandate_options: Option<stripe_shared::MandateOptionsUpi>,
7    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
8    ///
9    /// 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.
10    /// 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.
11    ///
12    /// 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.
13    ///
14    /// 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).
15    pub setup_future_usage: Option<CheckoutUpiPaymentMethodOptionsSetupFutureUsage>,
16}
17#[cfg(feature = "redact-generated-debug")]
18impl std::fmt::Debug for CheckoutUpiPaymentMethodOptions {
19    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
20        f.debug_struct("CheckoutUpiPaymentMethodOptions").finish_non_exhaustive()
21    }
22}
23#[doc(hidden)]
24pub struct CheckoutUpiPaymentMethodOptionsBuilder {
25    mandate_options: Option<Option<stripe_shared::MandateOptionsUpi>>,
26    setup_future_usage: Option<Option<CheckoutUpiPaymentMethodOptionsSetupFutureUsage>>,
27}
28
29#[allow(
30    unused_variables,
31    irrefutable_let_patterns,
32    clippy::let_unit_value,
33    clippy::match_single_binding,
34    clippy::single_match
35)]
36const _: () = {
37    use miniserde::de::{Map, Visitor};
38    use miniserde::json::Value;
39    use miniserde::{Deserialize, Result, make_place};
40    use stripe_types::miniserde_helpers::FromValueOpt;
41    use stripe_types::{MapBuilder, ObjectDeser};
42
43    make_place!(Place);
44
45    impl Deserialize for CheckoutUpiPaymentMethodOptions {
46        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
47            Place::new(out)
48        }
49    }
50
51    struct Builder<'a> {
52        out: &'a mut Option<CheckoutUpiPaymentMethodOptions>,
53        builder: CheckoutUpiPaymentMethodOptionsBuilder,
54    }
55
56    impl Visitor for Place<CheckoutUpiPaymentMethodOptions> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: CheckoutUpiPaymentMethodOptionsBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for CheckoutUpiPaymentMethodOptionsBuilder {
66        type Out = CheckoutUpiPaymentMethodOptions;
67        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68            Ok(match k {
69                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
70                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self { mandate_options: Some(None), setup_future_usage: Some(None) }
77        }
78
79        fn take_out(&mut self) -> Option<Self::Out> {
80            let (Some(mandate_options), Some(setup_future_usage)) =
81                (self.mandate_options.take(), self.setup_future_usage.take())
82            else {
83                return None;
84            };
85            Some(Self::Out { mandate_options, setup_future_usage })
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 CheckoutUpiPaymentMethodOptions {
101        type Builder = CheckoutUpiPaymentMethodOptionsBuilder;
102    }
103
104    impl FromValueOpt for CheckoutUpiPaymentMethodOptions {
105        fn from_value(v: Value) -> Option<Self> {
106            let Value::Object(obj) = v else {
107                return None;
108            };
109            let mut b = CheckoutUpiPaymentMethodOptionsBuilder::deser_default();
110            for (k, v) in obj {
111                match k.as_str() {
112                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
113                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
122///
123/// 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.
124/// 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.
125///
126/// 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.
127///
128/// 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).
129#[derive(Clone, Eq, PartialEq)]
130#[non_exhaustive]
131pub enum CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
132    None,
133    OffSession,
134    OnSession,
135    /// An unrecognized value from Stripe. Should not be used as a request parameter.
136    Unknown(String),
137}
138impl CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
139    pub fn as_str(&self) -> &str {
140        use CheckoutUpiPaymentMethodOptionsSetupFutureUsage::*;
141        match self {
142            None => "none",
143            OffSession => "off_session",
144            OnSession => "on_session",
145            Unknown(v) => v,
146        }
147    }
148}
149
150impl std::str::FromStr for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
151    type Err = std::convert::Infallible;
152    fn from_str(s: &str) -> Result<Self, Self::Err> {
153        use CheckoutUpiPaymentMethodOptionsSetupFutureUsage::*;
154        match s {
155            "none" => Ok(None),
156            "off_session" => Ok(OffSession),
157            "on_session" => Ok(OnSession),
158            v => {
159                tracing::warn!(
160                    "Unknown value '{}' for enum '{}'",
161                    v,
162                    "CheckoutUpiPaymentMethodOptionsSetupFutureUsage"
163                );
164                Ok(Unknown(v.to_owned()))
165            }
166        }
167    }
168}
169impl std::fmt::Display for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.write_str(self.as_str())
172    }
173}
174
175#[cfg(not(feature = "redact-generated-debug"))]
176impl std::fmt::Debug for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.write_str(self.as_str())
179    }
180}
181#[cfg(feature = "redact-generated-debug")]
182impl std::fmt::Debug for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
183    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
184        f.debug_struct(stringify!(CheckoutUpiPaymentMethodOptionsSetupFutureUsage))
185            .finish_non_exhaustive()
186    }
187}
188#[cfg(feature = "serialize")]
189impl serde::Serialize for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
190    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
191    where
192        S: serde::Serializer,
193    {
194        serializer.serialize_str(self.as_str())
195    }
196}
197impl miniserde::Deserialize for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
198    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
199        crate::Place::new(out)
200    }
201}
202
203impl miniserde::de::Visitor for crate::Place<CheckoutUpiPaymentMethodOptionsSetupFutureUsage> {
204    fn string(&mut self, s: &str) -> miniserde::Result<()> {
205        use std::str::FromStr;
206        self.out =
207            Some(CheckoutUpiPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"));
208        Ok(())
209    }
210}
211
212stripe_types::impl_from_val_with_from_str!(CheckoutUpiPaymentMethodOptionsSetupFutureUsage);
213#[cfg(feature = "deserialize")]
214impl<'de> serde::Deserialize<'de> for CheckoutUpiPaymentMethodOptionsSetupFutureUsage {
215    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
216        use std::str::FromStr;
217        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
218        Ok(Self::from_str(&s).expect("infallible"))
219    }
220}