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::{make_place, Deserialize, Result};
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
148                _ => <dyn Visitor>::ignore(),
149            })
150        }
151
152        fn deser_default() -> Self {
153            Self {
154                amount: Deserialize::default(),
155                amount_details: Deserialize::default(),
156                authorization: Deserialize::default(),
157                balance_transaction: Deserialize::default(),
158                card: Deserialize::default(),
159                cardholder: Deserialize::default(),
160                created: Deserialize::default(),
161                currency: Deserialize::default(),
162                dispute: Deserialize::default(),
163                id: Deserialize::default(),
164                livemode: Deserialize::default(),
165                merchant_amount: Deserialize::default(),
166                merchant_currency: Deserialize::default(),
167                merchant_data: Deserialize::default(),
168                metadata: Deserialize::default(),
169                network_data: Deserialize::default(),
170                purchase_details: Deserialize::default(),
171                token: Deserialize::default(),
172                treasury: Deserialize::default(),
173                type_: Deserialize::default(),
174                wallet: Deserialize::default(),
175            }
176        }
177
178        fn take_out(&mut self) -> Option<Self::Out> {
179            let (
180                Some(amount),
181                Some(amount_details),
182                Some(authorization),
183                Some(balance_transaction),
184                Some(card),
185                Some(cardholder),
186                Some(created),
187                Some(currency),
188                Some(dispute),
189                Some(id),
190                Some(livemode),
191                Some(merchant_amount),
192                Some(merchant_currency),
193                Some(merchant_data),
194                Some(metadata),
195                Some(network_data),
196                Some(purchase_details),
197                Some(token),
198                Some(treasury),
199                Some(type_),
200                Some(wallet),
201            ) = (
202                self.amount,
203                self.amount_details,
204                self.authorization.take(),
205                self.balance_transaction.take(),
206                self.card.take(),
207                self.cardholder.take(),
208                self.created,
209                self.currency,
210                self.dispute.take(),
211                self.id.take(),
212                self.livemode,
213                self.merchant_amount,
214                self.merchant_currency,
215                self.merchant_data.take(),
216                self.metadata.take(),
217                self.network_data.take(),
218                self.purchase_details.take(),
219                self.token.take(),
220                self.treasury.take(),
221                self.type_,
222                self.wallet,
223            )
224            else {
225                return None;
226            };
227            Some(Self::Out {
228                amount,
229                amount_details,
230                authorization,
231                balance_transaction,
232                card,
233                cardholder,
234                created,
235                currency,
236                dispute,
237                id,
238                livemode,
239                merchant_amount,
240                merchant_currency,
241                merchant_data,
242                metadata,
243                network_data,
244                purchase_details,
245                token,
246                treasury,
247                type_,
248                wallet,
249            })
250        }
251    }
252
253    impl<'a> Map for Builder<'a> {
254        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
255            self.builder.key(k)
256        }
257
258        fn finish(&mut self) -> Result<()> {
259            *self.out = self.builder.take_out();
260            Ok(())
261        }
262    }
263
264    impl ObjectDeser for IssuingTransaction {
265        type Builder = IssuingTransactionBuilder;
266    }
267
268    impl FromValueOpt for IssuingTransaction {
269        fn from_value(v: Value) -> Option<Self> {
270            let Value::Object(obj) = v else {
271                return None;
272            };
273            let mut b = IssuingTransactionBuilder::deser_default();
274            for (k, v) in obj {
275                match k.as_str() {
276                    "amount" => b.amount = FromValueOpt::from_value(v),
277                    "amount_details" => b.amount_details = FromValueOpt::from_value(v),
278                    "authorization" => b.authorization = FromValueOpt::from_value(v),
279                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
280                    "card" => b.card = FromValueOpt::from_value(v),
281                    "cardholder" => b.cardholder = FromValueOpt::from_value(v),
282                    "created" => b.created = FromValueOpt::from_value(v),
283                    "currency" => b.currency = FromValueOpt::from_value(v),
284                    "dispute" => b.dispute = FromValueOpt::from_value(v),
285                    "id" => b.id = FromValueOpt::from_value(v),
286                    "livemode" => b.livemode = FromValueOpt::from_value(v),
287                    "merchant_amount" => b.merchant_amount = FromValueOpt::from_value(v),
288                    "merchant_currency" => b.merchant_currency = FromValueOpt::from_value(v),
289                    "merchant_data" => b.merchant_data = FromValueOpt::from_value(v),
290                    "metadata" => b.metadata = FromValueOpt::from_value(v),
291                    "network_data" => b.network_data = FromValueOpt::from_value(v),
292                    "purchase_details" => b.purchase_details = FromValueOpt::from_value(v),
293                    "token" => b.token = FromValueOpt::from_value(v),
294                    "treasury" => b.treasury = FromValueOpt::from_value(v),
295                    "type" => b.type_ = FromValueOpt::from_value(v),
296                    "wallet" => b.wallet = FromValueOpt::from_value(v),
297
298                    _ => {}
299                }
300            }
301            b.take_out()
302        }
303    }
304};
305#[cfg(feature = "serialize")]
306impl serde::Serialize for IssuingTransaction {
307    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
308        use serde::ser::SerializeStruct;
309        let mut s = s.serialize_struct("IssuingTransaction", 22)?;
310        s.serialize_field("amount", &self.amount)?;
311        s.serialize_field("amount_details", &self.amount_details)?;
312        s.serialize_field("authorization", &self.authorization)?;
313        s.serialize_field("balance_transaction", &self.balance_transaction)?;
314        s.serialize_field("card", &self.card)?;
315        s.serialize_field("cardholder", &self.cardholder)?;
316        s.serialize_field("created", &self.created)?;
317        s.serialize_field("currency", &self.currency)?;
318        s.serialize_field("dispute", &self.dispute)?;
319        s.serialize_field("id", &self.id)?;
320        s.serialize_field("livemode", &self.livemode)?;
321        s.serialize_field("merchant_amount", &self.merchant_amount)?;
322        s.serialize_field("merchant_currency", &self.merchant_currency)?;
323        s.serialize_field("merchant_data", &self.merchant_data)?;
324        s.serialize_field("metadata", &self.metadata)?;
325        s.serialize_field("network_data", &self.network_data)?;
326        s.serialize_field("purchase_details", &self.purchase_details)?;
327        s.serialize_field("token", &self.token)?;
328        s.serialize_field("treasury", &self.treasury)?;
329        s.serialize_field("type", &self.type_)?;
330        s.serialize_field("wallet", &self.wallet)?;
331
332        s.serialize_field("object", "issuing.transaction")?;
333        s.end()
334    }
335}
336/// The digital wallet used for this transaction. One of `apple_pay`, `google_pay`, or `samsung_pay`.
337#[derive(Copy, Clone, Eq, PartialEq)]
338pub enum IssuingTransactionWallet {
339    ApplePay,
340    GooglePay,
341    SamsungPay,
342}
343impl IssuingTransactionWallet {
344    pub fn as_str(self) -> &'static str {
345        use IssuingTransactionWallet::*;
346        match self {
347            ApplePay => "apple_pay",
348            GooglePay => "google_pay",
349            SamsungPay => "samsung_pay",
350        }
351    }
352}
353
354impl std::str::FromStr for IssuingTransactionWallet {
355    type Err = stripe_types::StripeParseError;
356    fn from_str(s: &str) -> Result<Self, Self::Err> {
357        use IssuingTransactionWallet::*;
358        match s {
359            "apple_pay" => Ok(ApplePay),
360            "google_pay" => Ok(GooglePay),
361            "samsung_pay" => Ok(SamsungPay),
362            _ => Err(stripe_types::StripeParseError),
363        }
364    }
365}
366impl std::fmt::Display for IssuingTransactionWallet {
367    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
368        f.write_str(self.as_str())
369    }
370}
371
372impl std::fmt::Debug for IssuingTransactionWallet {
373    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
374        f.write_str(self.as_str())
375    }
376}
377#[cfg(feature = "serialize")]
378impl serde::Serialize for IssuingTransactionWallet {
379    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
380    where
381        S: serde::Serializer,
382    {
383        serializer.serialize_str(self.as_str())
384    }
385}
386impl miniserde::Deserialize for IssuingTransactionWallet {
387    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
388        crate::Place::new(out)
389    }
390}
391
392impl miniserde::de::Visitor for crate::Place<IssuingTransactionWallet> {
393    fn string(&mut self, s: &str) -> miniserde::Result<()> {
394        use std::str::FromStr;
395        self.out = Some(IssuingTransactionWallet::from_str(s).map_err(|_| miniserde::Error)?);
396        Ok(())
397    }
398}
399
400stripe_types::impl_from_val_with_from_str!(IssuingTransactionWallet);
401#[cfg(feature = "deserialize")]
402impl<'de> serde::Deserialize<'de> for IssuingTransactionWallet {
403    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
404        use std::str::FromStr;
405        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
406        Self::from_str(&s)
407            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingTransactionWallet"))
408    }
409}
410impl stripe_types::Object for IssuingTransaction {
411    type Id = stripe_shared::IssuingTransactionId;
412    fn id(&self) -> &Self::Id {
413        &self.id
414    }
415
416    fn into_id(self) -> Self::Id {
417        self.id
418    }
419}
420stripe_types::def_id!(IssuingTransactionId);
421#[derive(Copy, Clone, Eq, PartialEq)]
422pub enum IssuingTransactionType {
423    Capture,
424    Refund,
425}
426impl IssuingTransactionType {
427    pub fn as_str(self) -> &'static str {
428        use IssuingTransactionType::*;
429        match self {
430            Capture => "capture",
431            Refund => "refund",
432        }
433    }
434}
435
436impl std::str::FromStr for IssuingTransactionType {
437    type Err = stripe_types::StripeParseError;
438    fn from_str(s: &str) -> Result<Self, Self::Err> {
439        use IssuingTransactionType::*;
440        match s {
441            "capture" => Ok(Capture),
442            "refund" => Ok(Refund),
443            _ => Err(stripe_types::StripeParseError),
444        }
445    }
446}
447impl std::fmt::Display for IssuingTransactionType {
448    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
449        f.write_str(self.as_str())
450    }
451}
452
453impl std::fmt::Debug for IssuingTransactionType {
454    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
455        f.write_str(self.as_str())
456    }
457}
458impl serde::Serialize for IssuingTransactionType {
459    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
460    where
461        S: serde::Serializer,
462    {
463        serializer.serialize_str(self.as_str())
464    }
465}
466impl miniserde::Deserialize for IssuingTransactionType {
467    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
468        crate::Place::new(out)
469    }
470}
471
472impl miniserde::de::Visitor for crate::Place<IssuingTransactionType> {
473    fn string(&mut self, s: &str) -> miniserde::Result<()> {
474        use std::str::FromStr;
475        self.out = Some(IssuingTransactionType::from_str(s).map_err(|_| miniserde::Error)?);
476        Ok(())
477    }
478}
479
480stripe_types::impl_from_val_with_from_str!(IssuingTransactionType);
481#[cfg(feature = "deserialize")]
482impl<'de> serde::Deserialize<'de> for IssuingTransactionType {
483    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
484        use std::str::FromStr;
485        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
486        Self::from_str(&s)
487            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingTransactionType"))
488    }
489}