stripe_shared/
issuing_transaction.rs

1/// Any use of an [issued card](https://stripe.com/docs/issuing) that results in funds entering or leaving.
2/// your Stripe account, such as a completed purchase or refund, is represented by an Issuing
3/// `Transaction` object.
4///
5/// Related guide: [Issued card transactions](https://stripe.com/docs/issuing/purchases/transactions)
6///
7/// For more details see <<https://stripe.com/docs/api/issuing/transactions/object>>.
8#[derive(Clone, Debug)]
9#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
10pub struct IssuingTransaction {
11    /// The transaction amount, which will be reflected in your balance.
12    /// This amount is in your currency and in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
13    pub amount: i64,
14    /// Detailed breakdown of amount components.
15    /// These amounts are denominated in `currency` and in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
16    pub amount_details: Option<stripe_shared::IssuingTransactionAmountDetails>,
17    /// The `Authorization` object that led to this transaction.
18    pub authorization: Option<stripe_types::Expandable<stripe_shared::IssuingAuthorization>>,
19    /// ID of the [balance transaction](https://stripe.com/docs/api/balance_transactions) associated with this transaction.
20    pub balance_transaction: Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
21    /// The card used to make this transaction.
22    pub card: stripe_types::Expandable<stripe_shared::IssuingCard>,
23    /// The cardholder to whom this transaction belongs.
24    pub cardholder: Option<stripe_types::Expandable<stripe_shared::IssuingCardholder>>,
25    /// Time at which the object was created. Measured in seconds since the Unix epoch.
26    pub created: stripe_types::Timestamp,
27    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
28    /// Must be a [supported currency](https://stripe.com/docs/currencies).
29    pub currency: stripe_types::Currency,
30    /// If you've disputed the transaction, the ID of the dispute.
31    pub dispute: Option<stripe_types::Expandable<stripe_shared::IssuingDispute>>,
32    /// Unique identifier for the object.
33    pub id: stripe_shared::IssuingTransactionId,
34    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
35    pub livemode: bool,
36    /// The amount that the merchant will receive, denominated in `merchant_currency` and in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
37    /// It will be different from `amount` if the merchant is taking payment in a different currency.
38    pub merchant_amount: i64,
39    /// The currency with which the merchant is taking payment.
40    pub merchant_currency: stripe_types::Currency,
41    pub merchant_data: stripe_shared::IssuingAuthorizationMerchantData,
42    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
43    /// This can be useful for storing additional information about the object in a structured format.
44    pub metadata: std::collections::HashMap<String, String>,
45    /// Details about the transaction, such as processing dates, set by the card network.
46    pub network_data: Option<stripe_shared::IssuingTransactionNetworkData>,
47    /// Additional purchase information that is optionally provided by the merchant.
48    pub purchase_details: Option<stripe_shared::IssuingTransactionPurchaseDetails>,
49    /// [Token](https://stripe.com/docs/api/issuing/tokens/object) object used for this transaction.
50    /// If a network token was not used for this transaction, this field will be null.
51    pub token: Option<stripe_types::Expandable<stripe_shared::IssuingToken>>,
52    /// [Treasury](https://stripe.com/docs/api/treasury) details related to this transaction if it was created on a [FinancialAccount](/docs/api/treasury/financial_accounts.
53    pub treasury: Option<stripe_shared::IssuingTransactionTreasury>,
54    /// The nature of the transaction.
55    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
56    pub type_: stripe_shared::IssuingTransactionType,
57    /// The digital wallet used for this transaction. One of `apple_pay`, `google_pay`, or `samsung_pay`.
58    pub wallet: Option<IssuingTransactionWallet>,
59}
60#[doc(hidden)]
61pub struct IssuingTransactionBuilder {
62    amount: Option<i64>,
63    amount_details: Option<Option<stripe_shared::IssuingTransactionAmountDetails>>,
64    authorization: Option<Option<stripe_types::Expandable<stripe_shared::IssuingAuthorization>>>,
65    balance_transaction:
66        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
67    card: Option<stripe_types::Expandable<stripe_shared::IssuingCard>>,
68    cardholder: Option<Option<stripe_types::Expandable<stripe_shared::IssuingCardholder>>>,
69    created: Option<stripe_types::Timestamp>,
70    currency: Option<stripe_types::Currency>,
71    dispute: Option<Option<stripe_types::Expandable<stripe_shared::IssuingDispute>>>,
72    id: Option<stripe_shared::IssuingTransactionId>,
73    livemode: Option<bool>,
74    merchant_amount: Option<i64>,
75    merchant_currency: Option<stripe_types::Currency>,
76    merchant_data: Option<stripe_shared::IssuingAuthorizationMerchantData>,
77    metadata: Option<std::collections::HashMap<String, String>>,
78    network_data: Option<Option<stripe_shared::IssuingTransactionNetworkData>>,
79    purchase_details: Option<Option<stripe_shared::IssuingTransactionPurchaseDetails>>,
80    token: Option<Option<stripe_types::Expandable<stripe_shared::IssuingToken>>>,
81    treasury: Option<Option<stripe_shared::IssuingTransactionTreasury>>,
82    type_: Option<stripe_shared::IssuingTransactionType>,
83    wallet: Option<Option<IssuingTransactionWallet>>,
84}
85
86#[allow(
87    unused_variables,
88    irrefutable_let_patterns,
89    clippy::let_unit_value,
90    clippy::match_single_binding,
91    clippy::single_match
92)]
93const _: () = {
94    use miniserde::de::{Map, Visitor};
95    use miniserde::json::Value;
96    use miniserde::{Deserialize, Result, make_place};
97    use stripe_types::miniserde_helpers::FromValueOpt;
98    use stripe_types::{MapBuilder, ObjectDeser};
99
100    make_place!(Place);
101
102    impl Deserialize for IssuingTransaction {
103        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
104            Place::new(out)
105        }
106    }
107
108    struct Builder<'a> {
109        out: &'a mut Option<IssuingTransaction>,
110        builder: IssuingTransactionBuilder,
111    }
112
113    impl Visitor for Place<IssuingTransaction> {
114        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
115            Ok(Box::new(Builder {
116                out: &mut self.out,
117                builder: IssuingTransactionBuilder::deser_default(),
118            }))
119        }
120    }
121
122    impl MapBuilder for IssuingTransactionBuilder {
123        type Out = IssuingTransaction;
124        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
125            Ok(match k {
126                "amount" => Deserialize::begin(&mut self.amount),
127                "amount_details" => Deserialize::begin(&mut self.amount_details),
128                "authorization" => Deserialize::begin(&mut self.authorization),
129                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
130                "card" => Deserialize::begin(&mut self.card),
131                "cardholder" => Deserialize::begin(&mut self.cardholder),
132                "created" => Deserialize::begin(&mut self.created),
133                "currency" => Deserialize::begin(&mut self.currency),
134                "dispute" => Deserialize::begin(&mut self.dispute),
135                "id" => Deserialize::begin(&mut self.id),
136                "livemode" => Deserialize::begin(&mut self.livemode),
137                "merchant_amount" => Deserialize::begin(&mut self.merchant_amount),
138                "merchant_currency" => Deserialize::begin(&mut self.merchant_currency),
139                "merchant_data" => Deserialize::begin(&mut self.merchant_data),
140                "metadata" => Deserialize::begin(&mut self.metadata),
141                "network_data" => Deserialize::begin(&mut self.network_data),
142                "purchase_details" => Deserialize::begin(&mut self.purchase_details),
143                "token" => Deserialize::begin(&mut self.token),
144                "treasury" => Deserialize::begin(&mut self.treasury),
145                "type" => Deserialize::begin(&mut self.type_),
146                "wallet" => Deserialize::begin(&mut self.wallet),
147                _ => <dyn Visitor>::ignore(),
148            })
149        }
150
151        fn deser_default() -> Self {
152            Self {
153                amount: Deserialize::default(),
154                amount_details: Deserialize::default(),
155                authorization: Deserialize::default(),
156                balance_transaction: Deserialize::default(),
157                card: Deserialize::default(),
158                cardholder: Deserialize::default(),
159                created: Deserialize::default(),
160                currency: Deserialize::default(),
161                dispute: Deserialize::default(),
162                id: Deserialize::default(),
163                livemode: Deserialize::default(),
164                merchant_amount: Deserialize::default(),
165                merchant_currency: Deserialize::default(),
166                merchant_data: Deserialize::default(),
167                metadata: Deserialize::default(),
168                network_data: Deserialize::default(),
169                purchase_details: Deserialize::default(),
170                token: Deserialize::default(),
171                treasury: Deserialize::default(),
172                type_: Deserialize::default(),
173                wallet: Deserialize::default(),
174            }
175        }
176
177        fn take_out(&mut self) -> Option<Self::Out> {
178            let (
179                Some(amount),
180                Some(amount_details),
181                Some(authorization),
182                Some(balance_transaction),
183                Some(card),
184                Some(cardholder),
185                Some(created),
186                Some(currency),
187                Some(dispute),
188                Some(id),
189                Some(livemode),
190                Some(merchant_amount),
191                Some(merchant_currency),
192                Some(merchant_data),
193                Some(metadata),
194                Some(network_data),
195                Some(purchase_details),
196                Some(token),
197                Some(treasury),
198                Some(type_),
199                Some(wallet),
200            ) = (
201                self.amount,
202                self.amount_details,
203                self.authorization.take(),
204                self.balance_transaction.take(),
205                self.card.take(),
206                self.cardholder.take(),
207                self.created,
208                self.currency.take(),
209                self.dispute.take(),
210                self.id.take(),
211                self.livemode,
212                self.merchant_amount,
213                self.merchant_currency.take(),
214                self.merchant_data.take(),
215                self.metadata.take(),
216                self.network_data.take(),
217                self.purchase_details.take(),
218                self.token.take(),
219                self.treasury.take(),
220                self.type_,
221                self.wallet,
222            )
223            else {
224                return None;
225            };
226            Some(Self::Out {
227                amount,
228                amount_details,
229                authorization,
230                balance_transaction,
231                card,
232                cardholder,
233                created,
234                currency,
235                dispute,
236                id,
237                livemode,
238                merchant_amount,
239                merchant_currency,
240                merchant_data,
241                metadata,
242                network_data,
243                purchase_details,
244                token,
245                treasury,
246                type_,
247                wallet,
248            })
249        }
250    }
251
252    impl Map for Builder<'_> {
253        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
254            self.builder.key(k)
255        }
256
257        fn finish(&mut self) -> Result<()> {
258            *self.out = self.builder.take_out();
259            Ok(())
260        }
261    }
262
263    impl ObjectDeser for IssuingTransaction {
264        type Builder = IssuingTransactionBuilder;
265    }
266
267    impl FromValueOpt for IssuingTransaction {
268        fn from_value(v: Value) -> Option<Self> {
269            let Value::Object(obj) = v else {
270                return None;
271            };
272            let mut b = IssuingTransactionBuilder::deser_default();
273            for (k, v) in obj {
274                match k.as_str() {
275                    "amount" => b.amount = FromValueOpt::from_value(v),
276                    "amount_details" => b.amount_details = FromValueOpt::from_value(v),
277                    "authorization" => b.authorization = FromValueOpt::from_value(v),
278                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
279                    "card" => b.card = FromValueOpt::from_value(v),
280                    "cardholder" => b.cardholder = FromValueOpt::from_value(v),
281                    "created" => b.created = FromValueOpt::from_value(v),
282                    "currency" => b.currency = FromValueOpt::from_value(v),
283                    "dispute" => b.dispute = FromValueOpt::from_value(v),
284                    "id" => b.id = FromValueOpt::from_value(v),
285                    "livemode" => b.livemode = FromValueOpt::from_value(v),
286                    "merchant_amount" => b.merchant_amount = FromValueOpt::from_value(v),
287                    "merchant_currency" => b.merchant_currency = FromValueOpt::from_value(v),
288                    "merchant_data" => b.merchant_data = FromValueOpt::from_value(v),
289                    "metadata" => b.metadata = FromValueOpt::from_value(v),
290                    "network_data" => b.network_data = FromValueOpt::from_value(v),
291                    "purchase_details" => b.purchase_details = FromValueOpt::from_value(v),
292                    "token" => b.token = FromValueOpt::from_value(v),
293                    "treasury" => b.treasury = FromValueOpt::from_value(v),
294                    "type" => b.type_ = FromValueOpt::from_value(v),
295                    "wallet" => b.wallet = FromValueOpt::from_value(v),
296                    _ => {}
297                }
298            }
299            b.take_out()
300        }
301    }
302};
303#[cfg(feature = "serialize")]
304impl serde::Serialize for IssuingTransaction {
305    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
306        use serde::ser::SerializeStruct;
307        let mut s = s.serialize_struct("IssuingTransaction", 22)?;
308        s.serialize_field("amount", &self.amount)?;
309        s.serialize_field("amount_details", &self.amount_details)?;
310        s.serialize_field("authorization", &self.authorization)?;
311        s.serialize_field("balance_transaction", &self.balance_transaction)?;
312        s.serialize_field("card", &self.card)?;
313        s.serialize_field("cardholder", &self.cardholder)?;
314        s.serialize_field("created", &self.created)?;
315        s.serialize_field("currency", &self.currency)?;
316        s.serialize_field("dispute", &self.dispute)?;
317        s.serialize_field("id", &self.id)?;
318        s.serialize_field("livemode", &self.livemode)?;
319        s.serialize_field("merchant_amount", &self.merchant_amount)?;
320        s.serialize_field("merchant_currency", &self.merchant_currency)?;
321        s.serialize_field("merchant_data", &self.merchant_data)?;
322        s.serialize_field("metadata", &self.metadata)?;
323        s.serialize_field("network_data", &self.network_data)?;
324        s.serialize_field("purchase_details", &self.purchase_details)?;
325        s.serialize_field("token", &self.token)?;
326        s.serialize_field("treasury", &self.treasury)?;
327        s.serialize_field("type", &self.type_)?;
328        s.serialize_field("wallet", &self.wallet)?;
329
330        s.serialize_field("object", "issuing.transaction")?;
331        s.end()
332    }
333}
334/// The digital wallet used for this transaction. One of `apple_pay`, `google_pay`, or `samsung_pay`.
335#[derive(Copy, Clone, Eq, PartialEq)]
336pub enum IssuingTransactionWallet {
337    ApplePay,
338    GooglePay,
339    SamsungPay,
340}
341impl IssuingTransactionWallet {
342    pub fn as_str(self) -> &'static str {
343        use IssuingTransactionWallet::*;
344        match self {
345            ApplePay => "apple_pay",
346            GooglePay => "google_pay",
347            SamsungPay => "samsung_pay",
348        }
349    }
350}
351
352impl std::str::FromStr for IssuingTransactionWallet {
353    type Err = stripe_types::StripeParseError;
354    fn from_str(s: &str) -> Result<Self, Self::Err> {
355        use IssuingTransactionWallet::*;
356        match s {
357            "apple_pay" => Ok(ApplePay),
358            "google_pay" => Ok(GooglePay),
359            "samsung_pay" => Ok(SamsungPay),
360            _ => Err(stripe_types::StripeParseError),
361        }
362    }
363}
364impl std::fmt::Display for IssuingTransactionWallet {
365    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
366        f.write_str(self.as_str())
367    }
368}
369
370impl std::fmt::Debug for IssuingTransactionWallet {
371    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
372        f.write_str(self.as_str())
373    }
374}
375#[cfg(feature = "serialize")]
376impl serde::Serialize for IssuingTransactionWallet {
377    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
378    where
379        S: serde::Serializer,
380    {
381        serializer.serialize_str(self.as_str())
382    }
383}
384impl miniserde::Deserialize for IssuingTransactionWallet {
385    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
386        crate::Place::new(out)
387    }
388}
389
390impl miniserde::de::Visitor for crate::Place<IssuingTransactionWallet> {
391    fn string(&mut self, s: &str) -> miniserde::Result<()> {
392        use std::str::FromStr;
393        self.out = Some(IssuingTransactionWallet::from_str(s).map_err(|_| miniserde::Error)?);
394        Ok(())
395    }
396}
397
398stripe_types::impl_from_val_with_from_str!(IssuingTransactionWallet);
399#[cfg(feature = "deserialize")]
400impl<'de> serde::Deserialize<'de> for IssuingTransactionWallet {
401    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
402        use std::str::FromStr;
403        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
404        Self::from_str(&s)
405            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingTransactionWallet"))
406    }
407}
408impl stripe_types::Object for IssuingTransaction {
409    type Id = stripe_shared::IssuingTransactionId;
410    fn id(&self) -> &Self::Id {
411        &self.id
412    }
413
414    fn into_id(self) -> Self::Id {
415        self.id
416    }
417}
418stripe_types::def_id!(IssuingTransactionId);
419#[derive(Copy, Clone, Eq, PartialEq)]
420pub enum IssuingTransactionType {
421    Capture,
422    Refund,
423}
424impl IssuingTransactionType {
425    pub fn as_str(self) -> &'static str {
426        use IssuingTransactionType::*;
427        match self {
428            Capture => "capture",
429            Refund => "refund",
430        }
431    }
432}
433
434impl std::str::FromStr for IssuingTransactionType {
435    type Err = stripe_types::StripeParseError;
436    fn from_str(s: &str) -> Result<Self, Self::Err> {
437        use IssuingTransactionType::*;
438        match s {
439            "capture" => Ok(Capture),
440            "refund" => Ok(Refund),
441            _ => Err(stripe_types::StripeParseError),
442        }
443    }
444}
445impl std::fmt::Display for IssuingTransactionType {
446    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
447        f.write_str(self.as_str())
448    }
449}
450
451impl std::fmt::Debug for IssuingTransactionType {
452    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
453        f.write_str(self.as_str())
454    }
455}
456impl serde::Serialize for IssuingTransactionType {
457    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
458    where
459        S: serde::Serializer,
460    {
461        serializer.serialize_str(self.as_str())
462    }
463}
464impl miniserde::Deserialize for IssuingTransactionType {
465    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
466        crate::Place::new(out)
467    }
468}
469
470impl miniserde::de::Visitor for crate::Place<IssuingTransactionType> {
471    fn string(&mut self, s: &str) -> miniserde::Result<()> {
472        use std::str::FromStr;
473        self.out = Some(IssuingTransactionType::from_str(s).map_err(|_| miniserde::Error)?);
474        Ok(())
475    }
476}
477
478stripe_types::impl_from_val_with_from_str!(IssuingTransactionType);
479#[cfg(feature = "deserialize")]
480impl<'de> serde::Deserialize<'de> for IssuingTransactionType {
481    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
482        use std::str::FromStr;
483        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
484        Self::from_str(&s)
485            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingTransactionType"))
486    }
487}