Skip to main content

stripe_shared/
issuing_transaction.rs

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