stripe_shared/
charge_outcome.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ChargeOutcome {
5    /// An enumerated value providing a more detailed explanation on [how to proceed with an error](https://stripe.com/docs/declines#retrying-issuer-declines).
6    pub advice_code: Option<ChargeOutcomeAdviceCode>,
7    /// For charges declined by the network, a 2 digit code which indicates the advice returned by the network on how to proceed with an error.
8    pub network_advice_code: Option<String>,
9    /// For charges declined by the network, a brand specific 2, 3, or 4 digit code which indicates the reason the authorization failed.
10    pub network_decline_code: Option<String>,
11    /// Possible values are `approved_by_network`, `declined_by_network`, `not_sent_to_network`, and `reversed_after_approval`.
12    /// The value `reversed_after_approval` indicates the payment was [blocked by Stripe](https://stripe.com/docs/declines#blocked-payments) after bank authorization, and may temporarily appear as "pending" on a cardholder's statement.
13    pub network_status: Option<String>,
14    /// An enumerated value providing a more detailed explanation of the outcome's `type`.
15    /// Charges blocked by Radar's default block rule have the value `highest_risk_level`.
16    /// Charges placed in review by Radar's default review rule have the value `elevated_risk_level`.
17    /// Charges authorized, blocked, or placed in review by custom rules have the value `rule`.
18    /// See [understanding declines](https://stripe.com/docs/declines) for more details.
19    pub reason: Option<String>,
20    /// Stripe Radar's evaluation of the riskiness of the payment.
21    /// Possible values for evaluated payments are `normal`, `elevated`, `highest`.
22    /// For non-card payments, and card-based payments predating the public assignment of risk levels, this field will have the value `not_assessed`.
23    /// In the event of an error in the evaluation, this field will have the value `unknown`.
24    /// This field is only available with Radar.
25    pub risk_level: Option<String>,
26    /// Stripe Radar's evaluation of the riskiness of the payment.
27    /// Possible values for evaluated payments are between 0 and 100.
28    /// For non-card payments, card-based payments predating the public assignment of risk scores, or in the event of an error during evaluation, this field will not be present.
29    /// This field is only available with Radar for Fraud Teams.
30    pub risk_score: Option<i64>,
31    /// The ID of the Radar rule that matched the payment, if applicable.
32    pub rule: Option<stripe_types::Expandable<stripe_shared::Rule>>,
33    /// A human-readable description of the outcome type and reason, designed for you (the recipient of the payment), not your customer.
34    pub seller_message: Option<String>,
35    /// Possible values are `authorized`, `manual_review`, `issuer_declined`, `blocked`, and `invalid`.
36    /// See [understanding declines](https://stripe.com/docs/declines) and [Radar reviews](https://stripe.com/docs/radar/reviews) for details.
37    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
38    pub type_: String,
39}
40#[doc(hidden)]
41pub struct ChargeOutcomeBuilder {
42    advice_code: Option<Option<ChargeOutcomeAdviceCode>>,
43    network_advice_code: Option<Option<String>>,
44    network_decline_code: Option<Option<String>>,
45    network_status: Option<Option<String>>,
46    reason: Option<Option<String>>,
47    risk_level: Option<Option<String>>,
48    risk_score: Option<Option<i64>>,
49    rule: Option<Option<stripe_types::Expandable<stripe_shared::Rule>>>,
50    seller_message: Option<Option<String>>,
51    type_: Option<String>,
52}
53
54#[allow(
55    unused_variables,
56    irrefutable_let_patterns,
57    clippy::let_unit_value,
58    clippy::match_single_binding,
59    clippy::single_match
60)]
61const _: () = {
62    use miniserde::de::{Map, Visitor};
63    use miniserde::json::Value;
64    use miniserde::{make_place, Deserialize, Result};
65    use stripe_types::miniserde_helpers::FromValueOpt;
66    use stripe_types::{MapBuilder, ObjectDeser};
67
68    make_place!(Place);
69
70    impl Deserialize for ChargeOutcome {
71        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
72            Place::new(out)
73        }
74    }
75
76    struct Builder<'a> {
77        out: &'a mut Option<ChargeOutcome>,
78        builder: ChargeOutcomeBuilder,
79    }
80
81    impl Visitor for Place<ChargeOutcome> {
82        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
83            Ok(Box::new(Builder {
84                out: &mut self.out,
85                builder: ChargeOutcomeBuilder::deser_default(),
86            }))
87        }
88    }
89
90    impl MapBuilder for ChargeOutcomeBuilder {
91        type Out = ChargeOutcome;
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            Ok(match k {
94                "advice_code" => Deserialize::begin(&mut self.advice_code),
95                "network_advice_code" => Deserialize::begin(&mut self.network_advice_code),
96                "network_decline_code" => Deserialize::begin(&mut self.network_decline_code),
97                "network_status" => Deserialize::begin(&mut self.network_status),
98                "reason" => Deserialize::begin(&mut self.reason),
99                "risk_level" => Deserialize::begin(&mut self.risk_level),
100                "risk_score" => Deserialize::begin(&mut self.risk_score),
101                "rule" => Deserialize::begin(&mut self.rule),
102                "seller_message" => Deserialize::begin(&mut self.seller_message),
103                "type" => Deserialize::begin(&mut self.type_),
104
105                _ => <dyn Visitor>::ignore(),
106            })
107        }
108
109        fn deser_default() -> Self {
110            Self {
111                advice_code: Deserialize::default(),
112                network_advice_code: Deserialize::default(),
113                network_decline_code: Deserialize::default(),
114                network_status: Deserialize::default(),
115                reason: Deserialize::default(),
116                risk_level: Deserialize::default(),
117                risk_score: Deserialize::default(),
118                rule: Deserialize::default(),
119                seller_message: Deserialize::default(),
120                type_: Deserialize::default(),
121            }
122        }
123
124        fn take_out(&mut self) -> Option<Self::Out> {
125            let (
126                Some(advice_code),
127                Some(network_advice_code),
128                Some(network_decline_code),
129                Some(network_status),
130                Some(reason),
131                Some(risk_level),
132                Some(risk_score),
133                Some(rule),
134                Some(seller_message),
135                Some(type_),
136            ) = (
137                self.advice_code,
138                self.network_advice_code.take(),
139                self.network_decline_code.take(),
140                self.network_status.take(),
141                self.reason.take(),
142                self.risk_level.take(),
143                self.risk_score,
144                self.rule.take(),
145                self.seller_message.take(),
146                self.type_.take(),
147            )
148            else {
149                return None;
150            };
151            Some(Self::Out {
152                advice_code,
153                network_advice_code,
154                network_decline_code,
155                network_status,
156                reason,
157                risk_level,
158                risk_score,
159                rule,
160                seller_message,
161                type_,
162            })
163        }
164    }
165
166    impl<'a> Map for Builder<'a> {
167        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
168            self.builder.key(k)
169        }
170
171        fn finish(&mut self) -> Result<()> {
172            *self.out = self.builder.take_out();
173            Ok(())
174        }
175    }
176
177    impl ObjectDeser for ChargeOutcome {
178        type Builder = ChargeOutcomeBuilder;
179    }
180
181    impl FromValueOpt for ChargeOutcome {
182        fn from_value(v: Value) -> Option<Self> {
183            let Value::Object(obj) = v else {
184                return None;
185            };
186            let mut b = ChargeOutcomeBuilder::deser_default();
187            for (k, v) in obj {
188                match k.as_str() {
189                    "advice_code" => b.advice_code = FromValueOpt::from_value(v),
190                    "network_advice_code" => b.network_advice_code = FromValueOpt::from_value(v),
191                    "network_decline_code" => b.network_decline_code = FromValueOpt::from_value(v),
192                    "network_status" => b.network_status = FromValueOpt::from_value(v),
193                    "reason" => b.reason = FromValueOpt::from_value(v),
194                    "risk_level" => b.risk_level = FromValueOpt::from_value(v),
195                    "risk_score" => b.risk_score = FromValueOpt::from_value(v),
196                    "rule" => b.rule = FromValueOpt::from_value(v),
197                    "seller_message" => b.seller_message = FromValueOpt::from_value(v),
198                    "type" => b.type_ = FromValueOpt::from_value(v),
199
200                    _ => {}
201                }
202            }
203            b.take_out()
204        }
205    }
206};
207/// An enumerated value providing a more detailed explanation on [how to proceed with an error](https://stripe.com/docs/declines#retrying-issuer-declines).
208#[derive(Copy, Clone, Eq, PartialEq)]
209pub enum ChargeOutcomeAdviceCode {
210    ConfirmCardData,
211    DoNotTryAgain,
212    TryAgainLater,
213}
214impl ChargeOutcomeAdviceCode {
215    pub fn as_str(self) -> &'static str {
216        use ChargeOutcomeAdviceCode::*;
217        match self {
218            ConfirmCardData => "confirm_card_data",
219            DoNotTryAgain => "do_not_try_again",
220            TryAgainLater => "try_again_later",
221        }
222    }
223}
224
225impl std::str::FromStr for ChargeOutcomeAdviceCode {
226    type Err = stripe_types::StripeParseError;
227    fn from_str(s: &str) -> Result<Self, Self::Err> {
228        use ChargeOutcomeAdviceCode::*;
229        match s {
230            "confirm_card_data" => Ok(ConfirmCardData),
231            "do_not_try_again" => Ok(DoNotTryAgain),
232            "try_again_later" => Ok(TryAgainLater),
233            _ => Err(stripe_types::StripeParseError),
234        }
235    }
236}
237impl std::fmt::Display for ChargeOutcomeAdviceCode {
238    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
239        f.write_str(self.as_str())
240    }
241}
242
243impl std::fmt::Debug for ChargeOutcomeAdviceCode {
244    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
245        f.write_str(self.as_str())
246    }
247}
248#[cfg(feature = "serialize")]
249impl serde::Serialize for ChargeOutcomeAdviceCode {
250    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
251    where
252        S: serde::Serializer,
253    {
254        serializer.serialize_str(self.as_str())
255    }
256}
257impl miniserde::Deserialize for ChargeOutcomeAdviceCode {
258    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
259        crate::Place::new(out)
260    }
261}
262
263impl miniserde::de::Visitor for crate::Place<ChargeOutcomeAdviceCode> {
264    fn string(&mut self, s: &str) -> miniserde::Result<()> {
265        use std::str::FromStr;
266        self.out = Some(ChargeOutcomeAdviceCode::from_str(s).map_err(|_| miniserde::Error)?);
267        Ok(())
268    }
269}
270
271stripe_types::impl_from_val_with_from_str!(ChargeOutcomeAdviceCode);
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for ChargeOutcomeAdviceCode {
274    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275        use std::str::FromStr;
276        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277        Self::from_str(&s)
278            .map_err(|_| serde::de::Error::custom("Unknown value for ChargeOutcomeAdviceCode"))
279    }
280}