Skip to main content

stripe_shared/
issuing_transaction_network_data.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 IssuingTransactionNetworkData {
6    /// A code created by Stripe which is shared with the merchant to validate the authorization.
7    /// This field will be populated if the authorization message was approved.
8    /// The code typically starts with the letter "S", followed by a six-digit number.
9    /// For example, "S498162".
10    /// Please note that the code is not guaranteed to be unique across authorizations.
11    pub authorization_code: Option<String>,
12    /// The date the transaction was processed by the card network.
13    /// This can be different from the date the seller recorded the transaction depending on when the acquirer submits the transaction to the network.
14    pub processing_date: Option<String>,
15    /// Unique identifier for the authorization assigned by the card network used to match subsequent messages, disputes, and transactions.
16    pub transaction_id: Option<String>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for IssuingTransactionNetworkData {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        f.debug_struct("IssuingTransactionNetworkData").finish_non_exhaustive()
22    }
23}
24#[doc(hidden)]
25pub struct IssuingTransactionNetworkDataBuilder {
26    authorization_code: Option<Option<String>>,
27    processing_date: Option<Option<String>>,
28    transaction_id: Option<Option<String>>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for IssuingTransactionNetworkData {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<IssuingTransactionNetworkData>,
55        builder: IssuingTransactionNetworkDataBuilder,
56    }
57
58    impl Visitor for Place<IssuingTransactionNetworkData> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: IssuingTransactionNetworkDataBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for IssuingTransactionNetworkDataBuilder {
68        type Out = IssuingTransactionNetworkData;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "authorization_code" => Deserialize::begin(&mut self.authorization_code),
72                "processing_date" => Deserialize::begin(&mut self.processing_date),
73                "transaction_id" => Deserialize::begin(&mut self.transaction_id),
74                _ => <dyn Visitor>::ignore(),
75            })
76        }
77
78        fn deser_default() -> Self {
79            Self {
80                authorization_code: Some(None),
81                processing_date: Some(None),
82                transaction_id: Some(None),
83            }
84        }
85
86        fn take_out(&mut self) -> Option<Self::Out> {
87            let (Some(authorization_code), Some(processing_date), Some(transaction_id)) = (
88                self.authorization_code.take(),
89                self.processing_date.take(),
90                self.transaction_id.take(),
91            ) else {
92                return None;
93            };
94            Some(Self::Out { authorization_code, processing_date, transaction_id })
95        }
96    }
97
98    impl Map for Builder<'_> {
99        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
100            self.builder.key(k)
101        }
102
103        fn finish(&mut self) -> Result<()> {
104            *self.out = self.builder.take_out();
105            Ok(())
106        }
107    }
108
109    impl ObjectDeser for IssuingTransactionNetworkData {
110        type Builder = IssuingTransactionNetworkDataBuilder;
111    }
112
113    impl FromValueOpt for IssuingTransactionNetworkData {
114        fn from_value(v: Value) -> Option<Self> {
115            let Value::Object(obj) = v else {
116                return None;
117            };
118            let mut b = IssuingTransactionNetworkDataBuilder::deser_default();
119            for (k, v) in obj {
120                match k.as_str() {
121                    "authorization_code" => b.authorization_code = FromValueOpt::from_value(v),
122                    "processing_date" => b.processing_date = FromValueOpt::from_value(v),
123                    "transaction_id" => b.transaction_id = FromValueOpt::from_value(v),
124                    _ => {}
125                }
126            }
127            b.take_out()
128        }
129    }
130};