stripe/resources/generated/balance_transaction.rs
1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{BalanceTransactionId, PayoutId, SourceId};
7use crate::params::{Expand, Expandable, List, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::{
9 BalanceTransactionSourceUnion, BalanceTransactionStatus, Currency, FeeType,
10};
11use serde::{Deserialize, Serialize};
12
13/// The resource representing a Stripe "BalanceTransaction".
14///
15/// For more details see <https://stripe.com/docs/api/balance_transactions/object>
16#[derive(Clone, Debug, Default, Deserialize, Serialize)]
17pub struct BalanceTransaction {
18 /// Unique identifier for the object.
19 pub id: BalanceTransactionId,
20
21 /// Gross amount of this transaction (in cents (or local equivalent)).
22 ///
23 /// A positive value represents funds charged to another party, and a negative value represents funds sent to another party.
24 pub amount: i64,
25
26 /// The date that the transaction's net funds become available in the Stripe balance.
27 pub available_on: Timestamp,
28
29 /// Time at which the object was created.
30 ///
31 /// Measured in seconds since the Unix epoch.
32 pub created: Timestamp,
33
34 /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
35 ///
36 /// Must be a [supported currency](https://stripe.com/docs/currencies).
37 pub currency: Currency,
38
39 /// An arbitrary string attached to the object.
40 ///
41 /// Often useful for displaying to users.
42 pub description: Option<String>,
43
44 /// If applicable, this transaction uses an exchange rate.
45 ///
46 /// If money converts from currency A to currency B, then the `amount` in currency A, multipled by the `exchange_rate`, equals the `amount` in currency B.
47 /// For example, if you charge a customer 10.00 EUR, the PaymentIntent's `amount` is `1000` and `currency` is `eur`.
48 /// If this converts to 12.34 USD in your Stripe account, the BalanceTransaction's `amount` is `1234`, its `currency` is `usd`, and the `exchange_rate` is `1.234`.
49 pub exchange_rate: Option<f64>,
50
51 /// Fees (in cents (or local equivalent)) paid for this transaction.
52 ///
53 /// Represented as a positive integer when assessed.
54 pub fee: i64,
55
56 /// Detailed breakdown of fees (in cents (or local equivalent)) paid for this transaction.
57 pub fee_details: Vec<Fee>,
58
59 /// Net impact to a Stripe balance (in cents (or local equivalent)).
60 ///
61 /// A positive value represents incrementing a Stripe balance, and a negative value decrementing a Stripe balance.
62 /// You can calculate the net impact of a transaction on a balance by `amount` - `fee`.
63 pub net: i64,
64
65 /// Learn more about how [reporting categories](https://stripe.com/docs/reports/reporting-categories) can help you understand balance transactions from an accounting perspective.
66 pub reporting_category: String,
67
68 /// This transaction relates to the Stripe object.
69 pub source: Option<Expandable<BalanceTransactionSourceUnion>>,
70
71 /// The transaction's net funds status in the Stripe balance, which are either `available` or `pending`.
72 pub status: BalanceTransactionStatus,
73
74 /// Transaction type: `adjustment`, `advance`, `advance_funding`, `anticipation_repayment`, `application_fee`, `application_fee_refund`, `charge`, `climate_order_purchase`, `climate_order_refund`, `connect_collection_transfer`, `contribution`, `issuing_authorization_hold`, `issuing_authorization_release`, `issuing_dispute`, `issuing_transaction`, `obligation_outbound`, `obligation_reversal_inbound`, `payment`, `payment_failure_refund`, `payment_network_reserve_hold`, `payment_network_reserve_release`, `payment_refund`, `payment_reversal`, `payment_unreconciled`, `payout`, `payout_cancel`, `payout_failure`, `refund`, `refund_failure`, `reserve_transaction`, `reserved_funds`, `stripe_fee`, `stripe_fx_fee`, `tax_fee`, `topup`, `topup_reversal`, `transfer`, `transfer_cancel`, `transfer_failure`, or `transfer_refund`.
75 ///
76 /// Learn more about [balance transaction types and what they represent](https://stripe.com/docs/reports/balance-transaction-types).
77 /// To classify transactions for accounting purposes, consider `reporting_category` instead.
78 #[serde(rename = "type")]
79 pub type_: BalanceTransactionType,
80}
81
82impl BalanceTransaction {
83 /// Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth).
84 ///
85 /// The transactions are returned in sorted order, with the most recent transactions appearing first. Note that this endpoint was previously called “Balance history” and used the path `/v1/balance/history`.
86 pub fn list(
87 client: &Client,
88 params: &ListBalanceTransactions<'_>,
89 ) -> Response<List<BalanceTransaction>> {
90 client.get_query("/balance_transactions", params)
91 }
92
93 /// Retrieves the balance transaction with the given ID.
94 ///
95 /// Note that this endpoint previously used the path `/v1/balance/history/:id`.
96 pub fn retrieve(
97 client: &Client,
98 id: &BalanceTransactionId,
99 expand: &[&str],
100 ) -> Response<BalanceTransaction> {
101 client.get_query(&format!("/balance_transactions/{}", id), Expand { expand })
102 }
103}
104
105impl Object for BalanceTransaction {
106 type Id = BalanceTransactionId;
107 fn id(&self) -> Self::Id {
108 self.id.clone()
109 }
110 fn object(&self) -> &'static str {
111 "balance_transaction"
112 }
113}
114
115#[derive(Clone, Debug, Default, Deserialize, Serialize)]
116pub struct Fee {
117 /// Amount of the fee, in cents.
118 pub amount: i64,
119
120 /// ID of the Connect application that earned the fee.
121 pub application: Option<String>,
122
123 /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
124 ///
125 /// Must be a [supported currency](https://stripe.com/docs/currencies).
126 pub currency: Currency,
127
128 /// An arbitrary string attached to the object.
129 ///
130 /// Often useful for displaying to users.
131 pub description: Option<String>,
132
133 /// Type of the fee, one of: `application_fee`, `stripe_fee` or `tax`.
134 #[serde(rename = "type")]
135 pub type_: FeeType,
136}
137
138/// The parameters for `BalanceTransaction::list`.
139#[derive(Clone, Debug, Serialize, Default)]
140pub struct ListBalanceTransactions<'a> {
141 #[serde(skip_serializing_if = "Option::is_none")]
142 pub created: Option<RangeQuery<Timestamp>>,
143
144 /// Only return transactions in a certain currency.
145 ///
146 /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
147 /// Must be a [supported currency](https://stripe.com/docs/currencies).
148 #[serde(skip_serializing_if = "Option::is_none")]
149 pub currency: Option<Currency>,
150
151 /// A cursor for use in pagination.
152 ///
153 /// `ending_before` is an object ID that defines your place in the list.
154 /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
155 #[serde(skip_serializing_if = "Option::is_none")]
156 pub ending_before: Option<BalanceTransactionId>,
157
158 /// Specifies which fields in the response should be expanded.
159 #[serde(skip_serializing_if = "Expand::is_empty")]
160 pub expand: &'a [&'a str],
161
162 /// A limit on the number of objects to be returned.
163 ///
164 /// Limit can range between 1 and 100, and the default is 10.
165 #[serde(skip_serializing_if = "Option::is_none")]
166 pub limit: Option<u64>,
167
168 /// For automatic Stripe payouts only, only returns transactions that were paid out on the specified payout ID.
169 #[serde(skip_serializing_if = "Option::is_none")]
170 pub payout: Option<PayoutId>,
171
172 /// Only returns the original transaction.
173 #[serde(skip_serializing_if = "Option::is_none")]
174 pub source: Option<SourceId>,
175
176 /// A cursor for use in pagination.
177 ///
178 /// `starting_after` is an object ID that defines your place in the list.
179 /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
180 #[serde(skip_serializing_if = "Option::is_none")]
181 pub starting_after: Option<BalanceTransactionId>,
182
183 /// Only returns transactions of the given type.
184 ///
185 /// One of: `adjustment`, `advance`, `advance_funding`, `anticipation_repayment`, `application_fee`, `application_fee_refund`, `charge`, `climate_order_purchase`, `climate_order_refund`, `connect_collection_transfer`, `contribution`, `issuing_authorization_hold`, `issuing_authorization_release`, `issuing_dispute`, `issuing_transaction`, `obligation_outbound`, `obligation_reversal_inbound`, `payment`, `payment_failure_refund`, `payment_network_reserve_hold`, `payment_network_reserve_release`, `payment_refund`, `payment_reversal`, `payment_unreconciled`, `payout`, `payout_cancel`, `payout_failure`, `refund`, `refund_failure`, `reserve_transaction`, `reserved_funds`, `stripe_fee`, `stripe_fx_fee`, `tax_fee`, `topup`, `topup_reversal`, `transfer`, `transfer_cancel`, `transfer_failure`, or `transfer_refund`.
186 #[serde(rename = "type")]
187 #[serde(skip_serializing_if = "Option::is_none")]
188 pub type_: Option<&'a str>,
189}
190
191impl<'a> ListBalanceTransactions<'a> {
192 pub fn new() -> Self {
193 ListBalanceTransactions {
194 created: Default::default(),
195 currency: Default::default(),
196 ending_before: Default::default(),
197 expand: Default::default(),
198 limit: Default::default(),
199 payout: Default::default(),
200 source: Default::default(),
201 starting_after: Default::default(),
202 type_: Default::default(),
203 }
204 }
205}
206impl Paginable for ListBalanceTransactions<'_> {
207 type O = BalanceTransaction;
208 fn set_last(&mut self, item: Self::O) {
209 self.starting_after = Some(item.id());
210 }
211}
212/// An enum representing the possible values of an `BalanceTransaction`'s `type` field.
213#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
214#[serde(rename_all = "snake_case")]
215pub enum BalanceTransactionType {
216 Adjustment,
217 Advance,
218 AdvanceFunding,
219 AnticipationRepayment,
220 ApplicationFee,
221 ApplicationFeeRefund,
222 Charge,
223 ClimateOrderPurchase,
224 ClimateOrderRefund,
225 ConnectCollectionTransfer,
226 Contribution,
227 IssuingAuthorizationHold,
228 IssuingAuthorizationRelease,
229 IssuingDispute,
230 IssuingTransaction,
231 ObligationOutbound,
232 ObligationReversalInbound,
233 Payment,
234 PaymentFailureRefund,
235 PaymentNetworkReserveHold,
236 PaymentNetworkReserveRelease,
237 PaymentRefund,
238 PaymentReversal,
239 PaymentUnreconciled,
240 Payout,
241 PayoutCancel,
242 PayoutFailure,
243 Refund,
244 RefundFailure,
245 ReserveTransaction,
246 ReservedFunds,
247 StripeFee,
248 StripeFxFee,
249 TaxFee,
250 Topup,
251 TopupReversal,
252 Transfer,
253 TransferCancel,
254 TransferFailure,
255 TransferRefund,
256}
257
258impl BalanceTransactionType {
259 pub fn as_str(self) -> &'static str {
260 match self {
261 BalanceTransactionType::Adjustment => "adjustment",
262 BalanceTransactionType::Advance => "advance",
263 BalanceTransactionType::AdvanceFunding => "advance_funding",
264 BalanceTransactionType::AnticipationRepayment => "anticipation_repayment",
265 BalanceTransactionType::ApplicationFee => "application_fee",
266 BalanceTransactionType::ApplicationFeeRefund => "application_fee_refund",
267 BalanceTransactionType::Charge => "charge",
268 BalanceTransactionType::ClimateOrderPurchase => "climate_order_purchase",
269 BalanceTransactionType::ClimateOrderRefund => "climate_order_refund",
270 BalanceTransactionType::ConnectCollectionTransfer => "connect_collection_transfer",
271 BalanceTransactionType::Contribution => "contribution",
272 BalanceTransactionType::IssuingAuthorizationHold => "issuing_authorization_hold",
273 BalanceTransactionType::IssuingAuthorizationRelease => "issuing_authorization_release",
274 BalanceTransactionType::IssuingDispute => "issuing_dispute",
275 BalanceTransactionType::IssuingTransaction => "issuing_transaction",
276 BalanceTransactionType::ObligationOutbound => "obligation_outbound",
277 BalanceTransactionType::ObligationReversalInbound => "obligation_reversal_inbound",
278 BalanceTransactionType::Payment => "payment",
279 BalanceTransactionType::PaymentFailureRefund => "payment_failure_refund",
280 BalanceTransactionType::PaymentNetworkReserveHold => "payment_network_reserve_hold",
281 BalanceTransactionType::PaymentNetworkReserveRelease => {
282 "payment_network_reserve_release"
283 }
284 BalanceTransactionType::PaymentRefund => "payment_refund",
285 BalanceTransactionType::PaymentReversal => "payment_reversal",
286 BalanceTransactionType::PaymentUnreconciled => "payment_unreconciled",
287 BalanceTransactionType::Payout => "payout",
288 BalanceTransactionType::PayoutCancel => "payout_cancel",
289 BalanceTransactionType::PayoutFailure => "payout_failure",
290 BalanceTransactionType::Refund => "refund",
291 BalanceTransactionType::RefundFailure => "refund_failure",
292 BalanceTransactionType::ReserveTransaction => "reserve_transaction",
293 BalanceTransactionType::ReservedFunds => "reserved_funds",
294 BalanceTransactionType::StripeFee => "stripe_fee",
295 BalanceTransactionType::StripeFxFee => "stripe_fx_fee",
296 BalanceTransactionType::TaxFee => "tax_fee",
297 BalanceTransactionType::Topup => "topup",
298 BalanceTransactionType::TopupReversal => "topup_reversal",
299 BalanceTransactionType::Transfer => "transfer",
300 BalanceTransactionType::TransferCancel => "transfer_cancel",
301 BalanceTransactionType::TransferFailure => "transfer_failure",
302 BalanceTransactionType::TransferRefund => "transfer_refund",
303 }
304 }
305}
306
307impl AsRef<str> for BalanceTransactionType {
308 fn as_ref(&self) -> &str {
309 self.as_str()
310 }
311}
312
313impl std::fmt::Display for BalanceTransactionType {
314 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
315 self.as_str().fmt(f)
316 }
317}
318impl std::default::Default for BalanceTransactionType {
319 fn default() -> Self {
320 Self::Adjustment
321 }
322}