Skip to main content

stripe_shared/
payment_method_options_card_present.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 PaymentMethodOptionsCardPresent {
6    /// Controls when the funds will be captured from the customer's account.
7    pub capture_method: Option<PaymentMethodOptionsCardPresentCaptureMethod>,
8    /// Request ability to capture this payment beyond the standard [authorization validity window](https://docs.stripe.com/terminal/features/extended-authorizations#authorization-validity).
9    pub request_extended_authorization: Option<bool>,
10    /// Request ability to [increment](https://docs.stripe.com/terminal/features/incremental-authorizations) this PaymentIntent if the combination of MCC and card brand is eligible.
11    /// Check [incremental_authorization_supported](https://docs.stripe.com/api/charges/object#charge_object-payment_method_details-card_present-incremental_authorization_supported) in the [Confirm](https://docs.stripe.com/api/payment_intents/confirm) response to verify support.
12    pub request_incremental_authorization_support: Option<bool>,
13    pub routing: Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>,
14}
15#[cfg(feature = "redact-generated-debug")]
16impl std::fmt::Debug for PaymentMethodOptionsCardPresent {
17    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18        f.debug_struct("PaymentMethodOptionsCardPresent").finish_non_exhaustive()
19    }
20}
21#[doc(hidden)]
22pub struct PaymentMethodOptionsCardPresentBuilder {
23    capture_method: Option<Option<PaymentMethodOptionsCardPresentCaptureMethod>>,
24    request_extended_authorization: Option<Option<bool>>,
25    request_incremental_authorization_support: Option<Option<bool>>,
26    routing: Option<Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>>,
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 PaymentMethodOptionsCardPresent {
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<PaymentMethodOptionsCardPresent>,
53        builder: PaymentMethodOptionsCardPresentBuilder,
54    }
55
56    impl Visitor for Place<PaymentMethodOptionsCardPresent> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: PaymentMethodOptionsCardPresentBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for PaymentMethodOptionsCardPresentBuilder {
66        type Out = PaymentMethodOptionsCardPresent;
67        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68            Ok(match k {
69                "capture_method" => Deserialize::begin(&mut self.capture_method),
70                "request_extended_authorization" => {
71                    Deserialize::begin(&mut self.request_extended_authorization)
72                }
73                "request_incremental_authorization_support" => {
74                    Deserialize::begin(&mut self.request_incremental_authorization_support)
75                }
76                "routing" => Deserialize::begin(&mut self.routing),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                capture_method: Deserialize::default(),
84                request_extended_authorization: Deserialize::default(),
85                request_incremental_authorization_support: Deserialize::default(),
86                routing: Deserialize::default(),
87            }
88        }
89
90        fn take_out(&mut self) -> Option<Self::Out> {
91            let (
92                Some(capture_method),
93                Some(request_extended_authorization),
94                Some(request_incremental_authorization_support),
95                Some(routing),
96            ) = (
97                self.capture_method.take(),
98                self.request_extended_authorization,
99                self.request_incremental_authorization_support,
100                self.routing.take(),
101            )
102            else {
103                return None;
104            };
105            Some(Self::Out {
106                capture_method,
107                request_extended_authorization,
108                request_incremental_authorization_support,
109                routing,
110            })
111        }
112    }
113
114    impl Map for Builder<'_> {
115        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
116            self.builder.key(k)
117        }
118
119        fn finish(&mut self) -> Result<()> {
120            *self.out = self.builder.take_out();
121            Ok(())
122        }
123    }
124
125    impl ObjectDeser for PaymentMethodOptionsCardPresent {
126        type Builder = PaymentMethodOptionsCardPresentBuilder;
127    }
128
129    impl FromValueOpt for PaymentMethodOptionsCardPresent {
130        fn from_value(v: Value) -> Option<Self> {
131            let Value::Object(obj) = v else {
132                return None;
133            };
134            let mut b = PaymentMethodOptionsCardPresentBuilder::deser_default();
135            for (k, v) in obj {
136                match k.as_str() {
137                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
138                    "request_extended_authorization" => {
139                        b.request_extended_authorization = FromValueOpt::from_value(v)
140                    }
141                    "request_incremental_authorization_support" => {
142                        b.request_incremental_authorization_support = FromValueOpt::from_value(v)
143                    }
144                    "routing" => b.routing = FromValueOpt::from_value(v),
145                    _ => {}
146                }
147            }
148            b.take_out()
149        }
150    }
151};
152/// Controls when the funds will be captured from the customer's account.
153#[derive(Clone, Eq, PartialEq)]
154#[non_exhaustive]
155pub enum PaymentMethodOptionsCardPresentCaptureMethod {
156    Manual,
157    ManualPreferred,
158    /// An unrecognized value from Stripe. Should not be used as a request parameter.
159    Unknown(String),
160}
161impl PaymentMethodOptionsCardPresentCaptureMethod {
162    pub fn as_str(&self) -> &str {
163        use PaymentMethodOptionsCardPresentCaptureMethod::*;
164        match self {
165            Manual => "manual",
166            ManualPreferred => "manual_preferred",
167            Unknown(v) => v,
168        }
169    }
170}
171
172impl std::str::FromStr for PaymentMethodOptionsCardPresentCaptureMethod {
173    type Err = std::convert::Infallible;
174    fn from_str(s: &str) -> Result<Self, Self::Err> {
175        use PaymentMethodOptionsCardPresentCaptureMethod::*;
176        match s {
177            "manual" => Ok(Manual),
178            "manual_preferred" => Ok(ManualPreferred),
179            v => {
180                tracing::warn!(
181                    "Unknown value '{}' for enum '{}'",
182                    v,
183                    "PaymentMethodOptionsCardPresentCaptureMethod"
184                );
185                Ok(Unknown(v.to_owned()))
186            }
187        }
188    }
189}
190impl std::fmt::Display for PaymentMethodOptionsCardPresentCaptureMethod {
191    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
192        f.write_str(self.as_str())
193    }
194}
195
196#[cfg(not(feature = "redact-generated-debug"))]
197impl std::fmt::Debug for PaymentMethodOptionsCardPresentCaptureMethod {
198    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
199        f.write_str(self.as_str())
200    }
201}
202#[cfg(feature = "redact-generated-debug")]
203impl std::fmt::Debug for PaymentMethodOptionsCardPresentCaptureMethod {
204    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
205        f.debug_struct(stringify!(PaymentMethodOptionsCardPresentCaptureMethod))
206            .finish_non_exhaustive()
207    }
208}
209#[cfg(feature = "serialize")]
210impl serde::Serialize for PaymentMethodOptionsCardPresentCaptureMethod {
211    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
212    where
213        S: serde::Serializer,
214    {
215        serializer.serialize_str(self.as_str())
216    }
217}
218impl miniserde::Deserialize for PaymentMethodOptionsCardPresentCaptureMethod {
219    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
220        crate::Place::new(out)
221    }
222}
223
224impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardPresentCaptureMethod> {
225    fn string(&mut self, s: &str) -> miniserde::Result<()> {
226        use std::str::FromStr;
227        self.out =
228            Some(PaymentMethodOptionsCardPresentCaptureMethod::from_str(s).expect("infallible"));
229        Ok(())
230    }
231}
232
233stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardPresentCaptureMethod);
234#[cfg(feature = "deserialize")]
235impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardPresentCaptureMethod {
236    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
237        use std::str::FromStr;
238        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
239        Ok(Self::from_str(&s).expect("infallible"))
240    }
241}