Skip to main content

stripe_shared/
issuing_authorization_request.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 IssuingAuthorizationRequest {
6    /// The `pending_request.amount` at the time of the request, presented in your card's currency and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
7    /// Stripe held this amount from your account to fund the authorization if the request was approved.
8    pub amount: i64,
9    /// Detailed breakdown of amount components.
10    /// These amounts are denominated in `currency` and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
11    pub amount_details: Option<stripe_shared::IssuingAuthorizationAmountDetails>,
12    /// Whether this request was approved.
13    pub approved: bool,
14    /// A code created by Stripe which is shared with the merchant to validate the authorization.
15    /// This field will be populated if the authorization message was approved.
16    /// The code typically starts with the letter "S", followed by a six-digit number.
17    /// For example, "S498162".
18    /// Please note that the code is not guaranteed to be unique across authorizations.
19    pub authorization_code: Option<String>,
20    /// Time at which the object was created. Measured in seconds since the Unix epoch.
21    pub created: stripe_types::Timestamp,
22    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
23    /// Must be a [supported currency](https://stripe.com/docs/currencies).
24    pub currency: stripe_types::Currency,
25    /// The `pending_request.merchant_amount` at the time of the request, presented in the `merchant_currency` and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
26    pub merchant_amount: i64,
27    /// The currency that was collected by the merchant and presented to the cardholder for the authorization.
28    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
29    /// Must be a [supported currency](https://stripe.com/docs/currencies).
30    pub merchant_currency: stripe_types::Currency,
31    /// The card network's estimate of the likelihood that an authorization is fraudulent.
32    /// Takes on values between 1 and 99.
33    pub network_risk_score: Option<i64>,
34    /// When an authorization is approved or declined by you or by Stripe, this field provides additional detail on the reason for the outcome.
35    pub reason: IssuingAuthorizationRequestReason,
36    /// If the `request_history.reason` is `webhook_error` because the direct webhook response is invalid (for example, parsing errors or missing parameters), we surface a more detailed error message via this field.
37    pub reason_message: Option<String>,
38    /// Time when the card network received an authorization request from the acquirer in UTC.
39    /// Referred to by networks as transmission time.
40    pub requested_at: Option<stripe_types::Timestamp>,
41}
42#[cfg(feature = "redact-generated-debug")]
43impl std::fmt::Debug for IssuingAuthorizationRequest {
44    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
45        f.debug_struct("IssuingAuthorizationRequest").finish_non_exhaustive()
46    }
47}
48#[doc(hidden)]
49pub struct IssuingAuthorizationRequestBuilder {
50    amount: Option<i64>,
51    amount_details: Option<Option<stripe_shared::IssuingAuthorizationAmountDetails>>,
52    approved: Option<bool>,
53    authorization_code: Option<Option<String>>,
54    created: Option<stripe_types::Timestamp>,
55    currency: Option<stripe_types::Currency>,
56    merchant_amount: Option<i64>,
57    merchant_currency: Option<stripe_types::Currency>,
58    network_risk_score: Option<Option<i64>>,
59    reason: Option<IssuingAuthorizationRequestReason>,
60    reason_message: Option<Option<String>>,
61    requested_at: Option<Option<stripe_types::Timestamp>>,
62}
63
64#[allow(
65    unused_variables,
66    irrefutable_let_patterns,
67    clippy::let_unit_value,
68    clippy::match_single_binding,
69    clippy::single_match
70)]
71const _: () = {
72    use miniserde::de::{Map, Visitor};
73    use miniserde::json::Value;
74    use miniserde::{Deserialize, Result, make_place};
75    use stripe_types::miniserde_helpers::FromValueOpt;
76    use stripe_types::{MapBuilder, ObjectDeser};
77
78    make_place!(Place);
79
80    impl Deserialize for IssuingAuthorizationRequest {
81        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
82            Place::new(out)
83        }
84    }
85
86    struct Builder<'a> {
87        out: &'a mut Option<IssuingAuthorizationRequest>,
88        builder: IssuingAuthorizationRequestBuilder,
89    }
90
91    impl Visitor for Place<IssuingAuthorizationRequest> {
92        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
93            Ok(Box::new(Builder {
94                out: &mut self.out,
95                builder: IssuingAuthorizationRequestBuilder::deser_default(),
96            }))
97        }
98    }
99
100    impl MapBuilder for IssuingAuthorizationRequestBuilder {
101        type Out = IssuingAuthorizationRequest;
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            Ok(match k {
104                "amount" => Deserialize::begin(&mut self.amount),
105                "amount_details" => Deserialize::begin(&mut self.amount_details),
106                "approved" => Deserialize::begin(&mut self.approved),
107                "authorization_code" => Deserialize::begin(&mut self.authorization_code),
108                "created" => Deserialize::begin(&mut self.created),
109                "currency" => Deserialize::begin(&mut self.currency),
110                "merchant_amount" => Deserialize::begin(&mut self.merchant_amount),
111                "merchant_currency" => Deserialize::begin(&mut self.merchant_currency),
112                "network_risk_score" => Deserialize::begin(&mut self.network_risk_score),
113                "reason" => Deserialize::begin(&mut self.reason),
114                "reason_message" => Deserialize::begin(&mut self.reason_message),
115                "requested_at" => Deserialize::begin(&mut self.requested_at),
116                _ => <dyn Visitor>::ignore(),
117            })
118        }
119
120        fn deser_default() -> Self {
121            Self {
122                amount: None,
123                amount_details: Some(None),
124                approved: None,
125                authorization_code: Some(None),
126                created: None,
127                currency: None,
128                merchant_amount: None,
129                merchant_currency: None,
130                network_risk_score: Some(None),
131                reason: None,
132                reason_message: Some(None),
133                requested_at: Some(None),
134            }
135        }
136
137        fn take_out(&mut self) -> Option<Self::Out> {
138            let (
139                Some(amount),
140                Some(amount_details),
141                Some(approved),
142                Some(authorization_code),
143                Some(created),
144                Some(currency),
145                Some(merchant_amount),
146                Some(merchant_currency),
147                Some(network_risk_score),
148                Some(reason),
149                Some(reason_message),
150                Some(requested_at),
151            ) = (
152                self.amount,
153                self.amount_details,
154                self.approved,
155                self.authorization_code.take(),
156                self.created,
157                self.currency.take(),
158                self.merchant_amount,
159                self.merchant_currency.take(),
160                self.network_risk_score,
161                self.reason.take(),
162                self.reason_message.take(),
163                self.requested_at,
164            )
165            else {
166                return None;
167            };
168            Some(Self::Out {
169                amount,
170                amount_details,
171                approved,
172                authorization_code,
173                created,
174                currency,
175                merchant_amount,
176                merchant_currency,
177                network_risk_score,
178                reason,
179                reason_message,
180                requested_at,
181            })
182        }
183    }
184
185    impl Map for Builder<'_> {
186        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
187            self.builder.key(k)
188        }
189
190        fn finish(&mut self) -> Result<()> {
191            *self.out = self.builder.take_out();
192            Ok(())
193        }
194    }
195
196    impl ObjectDeser for IssuingAuthorizationRequest {
197        type Builder = IssuingAuthorizationRequestBuilder;
198    }
199
200    impl FromValueOpt for IssuingAuthorizationRequest {
201        fn from_value(v: Value) -> Option<Self> {
202            let Value::Object(obj) = v else {
203                return None;
204            };
205            let mut b = IssuingAuthorizationRequestBuilder::deser_default();
206            for (k, v) in obj {
207                match k.as_str() {
208                    "amount" => b.amount = FromValueOpt::from_value(v),
209                    "amount_details" => b.amount_details = FromValueOpt::from_value(v),
210                    "approved" => b.approved = FromValueOpt::from_value(v),
211                    "authorization_code" => b.authorization_code = FromValueOpt::from_value(v),
212                    "created" => b.created = FromValueOpt::from_value(v),
213                    "currency" => b.currency = FromValueOpt::from_value(v),
214                    "merchant_amount" => b.merchant_amount = FromValueOpt::from_value(v),
215                    "merchant_currency" => b.merchant_currency = FromValueOpt::from_value(v),
216                    "network_risk_score" => b.network_risk_score = FromValueOpt::from_value(v),
217                    "reason" => b.reason = FromValueOpt::from_value(v),
218                    "reason_message" => b.reason_message = FromValueOpt::from_value(v),
219                    "requested_at" => b.requested_at = FromValueOpt::from_value(v),
220                    _ => {}
221                }
222            }
223            b.take_out()
224        }
225    }
226};
227/// When an authorization is approved or declined by you or by Stripe, this field provides additional detail on the reason for the outcome.
228#[derive(Clone, Eq, PartialEq)]
229#[non_exhaustive]
230pub enum IssuingAuthorizationRequestReason {
231    AccountDisabled,
232    CardActive,
233    CardCanceled,
234    CardExpired,
235    CardInactive,
236    CardholderBlocked,
237    CardholderInactive,
238    CardholderVerificationRequired,
239    InsecureAuthorizationMethod,
240    InsufficientFunds,
241    NetworkFallback,
242    NotAllowed,
243    PinBlocked,
244    SpendingControls,
245    SuspectedFraud,
246    VerificationFailed,
247    WebhookApproved,
248    WebhookDeclined,
249    WebhookError,
250    WebhookTimeout,
251    /// An unrecognized value from Stripe. Should not be used as a request parameter.
252    Unknown(String),
253}
254impl IssuingAuthorizationRequestReason {
255    pub fn as_str(&self) -> &str {
256        use IssuingAuthorizationRequestReason::*;
257        match self {
258            AccountDisabled => "account_disabled",
259            CardActive => "card_active",
260            CardCanceled => "card_canceled",
261            CardExpired => "card_expired",
262            CardInactive => "card_inactive",
263            CardholderBlocked => "cardholder_blocked",
264            CardholderInactive => "cardholder_inactive",
265            CardholderVerificationRequired => "cardholder_verification_required",
266            InsecureAuthorizationMethod => "insecure_authorization_method",
267            InsufficientFunds => "insufficient_funds",
268            NetworkFallback => "network_fallback",
269            NotAllowed => "not_allowed",
270            PinBlocked => "pin_blocked",
271            SpendingControls => "spending_controls",
272            SuspectedFraud => "suspected_fraud",
273            VerificationFailed => "verification_failed",
274            WebhookApproved => "webhook_approved",
275            WebhookDeclined => "webhook_declined",
276            WebhookError => "webhook_error",
277            WebhookTimeout => "webhook_timeout",
278            Unknown(v) => v,
279        }
280    }
281}
282
283impl std::str::FromStr for IssuingAuthorizationRequestReason {
284    type Err = std::convert::Infallible;
285    fn from_str(s: &str) -> Result<Self, Self::Err> {
286        use IssuingAuthorizationRequestReason::*;
287        match s {
288            "account_disabled" => Ok(AccountDisabled),
289            "card_active" => Ok(CardActive),
290            "card_canceled" => Ok(CardCanceled),
291            "card_expired" => Ok(CardExpired),
292            "card_inactive" => Ok(CardInactive),
293            "cardholder_blocked" => Ok(CardholderBlocked),
294            "cardholder_inactive" => Ok(CardholderInactive),
295            "cardholder_verification_required" => Ok(CardholderVerificationRequired),
296            "insecure_authorization_method" => Ok(InsecureAuthorizationMethod),
297            "insufficient_funds" => Ok(InsufficientFunds),
298            "network_fallback" => Ok(NetworkFallback),
299            "not_allowed" => Ok(NotAllowed),
300            "pin_blocked" => Ok(PinBlocked),
301            "spending_controls" => Ok(SpendingControls),
302            "suspected_fraud" => Ok(SuspectedFraud),
303            "verification_failed" => Ok(VerificationFailed),
304            "webhook_approved" => Ok(WebhookApproved),
305            "webhook_declined" => Ok(WebhookDeclined),
306            "webhook_error" => Ok(WebhookError),
307            "webhook_timeout" => Ok(WebhookTimeout),
308            v => {
309                tracing::warn!(
310                    "Unknown value '{}' for enum '{}'",
311                    v,
312                    "IssuingAuthorizationRequestReason"
313                );
314                Ok(Unknown(v.to_owned()))
315            }
316        }
317    }
318}
319impl std::fmt::Display for IssuingAuthorizationRequestReason {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324
325#[cfg(not(feature = "redact-generated-debug"))]
326impl std::fmt::Debug for IssuingAuthorizationRequestReason {
327    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
328        f.write_str(self.as_str())
329    }
330}
331#[cfg(feature = "redact-generated-debug")]
332impl std::fmt::Debug for IssuingAuthorizationRequestReason {
333    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
334        f.debug_struct(stringify!(IssuingAuthorizationRequestReason)).finish_non_exhaustive()
335    }
336}
337#[cfg(feature = "serialize")]
338impl serde::Serialize for IssuingAuthorizationRequestReason {
339    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
340    where
341        S: serde::Serializer,
342    {
343        serializer.serialize_str(self.as_str())
344    }
345}
346impl miniserde::Deserialize for IssuingAuthorizationRequestReason {
347    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
348        crate::Place::new(out)
349    }
350}
351
352impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationRequestReason> {
353    fn string(&mut self, s: &str) -> miniserde::Result<()> {
354        use std::str::FromStr;
355        self.out = Some(IssuingAuthorizationRequestReason::from_str(s).expect("infallible"));
356        Ok(())
357    }
358}
359
360stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationRequestReason);
361#[cfg(feature = "deserialize")]
362impl<'de> serde::Deserialize<'de> for IssuingAuthorizationRequestReason {
363    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
364        use std::str::FromStr;
365        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
366        Ok(Self::from_str(&s).expect("infallible"))
367    }
368}