stripe_core/balance_transaction/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListBalanceTransactionBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    created: Option<stripe_types::RangeQueryTs>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    currency: Option<stripe_types::Currency>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    ending_before: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    expand: Option<Vec<String>>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    limit: Option<i64>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    payout: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    source: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    starting_after: Option<String>,
23    #[serde(rename = "type")]
24    #[serde(skip_serializing_if = "Option::is_none")]
25    type_: Option<String>,
26}
27impl ListBalanceTransactionBuilder {
28    fn new() -> Self {
29        Self {
30            created: None,
31            currency: None,
32            ending_before: None,
33            expand: None,
34            limit: None,
35            payout: None,
36            source: None,
37            starting_after: None,
38            type_: None,
39        }
40    }
41}
42/// Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth).
43/// The transactions are returned in sorted order, with the most recent transactions appearing first.
44///
45/// Note that this endpoint was previously called “Balance history” and used the path `/v1/balance/history`.
46#[derive(Clone, Debug, serde::Serialize)]
47pub struct ListBalanceTransaction {
48    inner: ListBalanceTransactionBuilder,
49}
50impl ListBalanceTransaction {
51    /// Construct a new `ListBalanceTransaction`.
52    pub fn new() -> Self {
53        Self { inner: ListBalanceTransactionBuilder::new() }
54    }
55    /// Only return transactions that were created during the given date interval.
56    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
57        self.inner.created = Some(created.into());
58        self
59    }
60    /// Only return transactions in a certain currency.
61    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
62    /// Must be a [supported currency](https://stripe.com/docs/currencies).
63    pub fn currency(mut self, currency: impl Into<stripe_types::Currency>) -> Self {
64        self.inner.currency = Some(currency.into());
65        self
66    }
67    /// A cursor for use in pagination.
68    /// `ending_before` is an object ID that defines your place in the list.
69    /// 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.
70    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
71        self.inner.ending_before = Some(ending_before.into());
72        self
73    }
74    /// Specifies which fields in the response should be expanded.
75    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
76        self.inner.expand = Some(expand.into());
77        self
78    }
79    /// A limit on the number of objects to be returned.
80    /// Limit can range between 1 and 100, and the default is 10.
81    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
82        self.inner.limit = Some(limit.into());
83        self
84    }
85    /// For automatic Stripe payouts only, only returns transactions that were paid out on the specified payout ID.
86    pub fn payout(mut self, payout: impl Into<String>) -> Self {
87        self.inner.payout = Some(payout.into());
88        self
89    }
90    /// Only returns the original transaction.
91    pub fn source(mut self, source: impl Into<String>) -> Self {
92        self.inner.source = Some(source.into());
93        self
94    }
95    /// A cursor for use in pagination.
96    /// `starting_after` is an object ID that defines your place in the list.
97    /// 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.
98    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
99        self.inner.starting_after = Some(starting_after.into());
100        self
101    }
102    /// Only returns transactions of the given type.
103    /// 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`, `payout_minimum_balance_hold`, `payout_minimum_balance_release`, `refund`, `refund_failure`, `reserve_transaction`, `reserved_funds`, `stripe_fee`, `stripe_fx_fee`, `stripe_balance_payment_debit`, `stripe_balance_payment_debit_reversal`, `tax_fee`, `topup`, `topup_reversal`, `transfer`, `transfer_cancel`, `transfer_failure`, or `transfer_refund`.
104    pub fn type_(mut self, type_: impl Into<String>) -> Self {
105        self.inner.type_ = Some(type_.into());
106        self
107    }
108}
109impl Default for ListBalanceTransaction {
110    fn default() -> Self {
111        Self::new()
112    }
113}
114impl ListBalanceTransaction {
115    /// Send the request and return the deserialized response.
116    pub async fn send<C: StripeClient>(
117        &self,
118        client: &C,
119    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
120        self.customize().send(client).await
121    }
122
123    /// Send the request and return the deserialized response, blocking until completion.
124    pub fn send_blocking<C: StripeBlockingClient>(
125        &self,
126        client: &C,
127    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
128        self.customize().send_blocking(client)
129    }
130
131    pub fn paginate(
132        &self,
133    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::BalanceTransaction>>
134    {
135        stripe_client_core::ListPaginator::new_list("/balance_transactions", &self.inner)
136    }
137}
138
139impl StripeRequest for ListBalanceTransaction {
140    type Output = stripe_types::List<stripe_shared::BalanceTransaction>;
141
142    fn build(&self) -> RequestBuilder {
143        RequestBuilder::new(StripeMethod::Get, "/balance_transactions").query(&self.inner)
144    }
145}
146#[derive(Clone, Debug, serde::Serialize)]
147struct RetrieveBalanceTransactionBuilder {
148    #[serde(skip_serializing_if = "Option::is_none")]
149    expand: Option<Vec<String>>,
150}
151impl RetrieveBalanceTransactionBuilder {
152    fn new() -> Self {
153        Self { expand: None }
154    }
155}
156/// Retrieves the balance transaction with the given ID.
157///
158/// Note that this endpoint previously used the path `/v1/balance/history/:id`.
159#[derive(Clone, Debug, serde::Serialize)]
160pub struct RetrieveBalanceTransaction {
161    inner: RetrieveBalanceTransactionBuilder,
162    id: stripe_shared::BalanceTransactionId,
163}
164impl RetrieveBalanceTransaction {
165    /// Construct a new `RetrieveBalanceTransaction`.
166    pub fn new(id: impl Into<stripe_shared::BalanceTransactionId>) -> Self {
167        Self { id: id.into(), inner: RetrieveBalanceTransactionBuilder::new() }
168    }
169    /// Specifies which fields in the response should be expanded.
170    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
171        self.inner.expand = Some(expand.into());
172        self
173    }
174}
175impl RetrieveBalanceTransaction {
176    /// Send the request and return the deserialized response.
177    pub async fn send<C: StripeClient>(
178        &self,
179        client: &C,
180    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
181        self.customize().send(client).await
182    }
183
184    /// Send the request and return the deserialized response, blocking until completion.
185    pub fn send_blocking<C: StripeBlockingClient>(
186        &self,
187        client: &C,
188    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
189        self.customize().send_blocking(client)
190    }
191}
192
193impl StripeRequest for RetrieveBalanceTransaction {
194    type Output = stripe_shared::BalanceTransaction;
195
196    fn build(&self) -> RequestBuilder {
197        let id = &self.id;
198        RequestBuilder::new(StripeMethod::Get, format!("/balance_transactions/{id}"))
199            .query(&self.inner)
200    }
201}