square_api_client/models/
list_payment_refunds_parameters.rs

1//! Model struct for ListPaymentRefundsParameters (query parameters)
2
3use super::{
4    enums::{PaymentRefundStatus, PaymentSourceType, SortOrder},
5    DateTime,
6};
7
8/// This is a model struct for ListPaymentRefundsParameters (query parameters)
9#[derive(Clone, Debug, Default)]
10pub struct ListPaymentRefundsParameters {
11    /// The timestamp for the beginning of the reporting period. Inclusive.
12    ///
13    /// Default: The current time minus one year.
14    pub begin_time: Option<DateTime>,
15    /// The timestamp for the end of the reporting period.
16    ///
17    /// Default: The current time.
18    pub end_time: Option<DateTime>,
19    /// The order in which results are listed.
20    /// * `ASC` - Oldest to newest.
21    /// * `DESC` - Newest to oldest (default).
22    pub sort_order: Option<SortOrder>,
23    /// A pagination cursor returned by a previous call to this endpoint. Provide this cursor to
24    /// retrieve the next set of results for the original query.
25    ///
26    /// For more information, see
27    /// [Pagination](https://developer.squareup.com/docs/basics/api101/pagination).
28    pub cursor: Option<String>,
29    /// Limit results to the location supplied. By default, results are returned for all locations
30    /// associated with the seller.
31    pub location_id: Option<String>,
32    /// If provided, only refunds with the given status are returned.
33    ///
34    /// Default: If omitted, refunds are returned regardless of their status.
35    pub status: Option<PaymentRefundStatus>,
36    /// If provided, only returns refunds whose payments have the indicated source type. Current
37    /// values include CARD, BANK_ACCOUNT, WALLET, CASH, and EXTERNAL. For information about these
38    /// payment source types,
39    /// see [Take Payments](https://developer.squareup.com/docs/payments-api/take-payments).
40    ///
41    /// Default: If omitted, refunds are returned regardless of the source type.
42    pub source_type: Option<PaymentSourceType>,
43    /// The maximum number of results to be returned in a single page. It is possible to receive
44    /// fewer results than the specified limit on a given page.
45    ///
46    /// The default value of 100 is also the maximum allowed value. If the provided value is greater
47    /// than 100, it is ignored and the default value is used instead.
48    ///
49    /// Default: `100`
50    pub limit: Option<i32>,
51}
52
53impl ListPaymentRefundsParameters {
54    pub fn to_query_string(&self) -> String {
55        self.to_string()
56    }
57}
58
59impl From<ListPaymentRefundsParameters> for String {
60    fn from(list_payment_refunds_parameters: ListPaymentRefundsParameters) -> Self {
61        list_payment_refunds_parameters.to_string()
62    }
63}
64
65impl ToString for ListPaymentRefundsParameters {
66    fn to_string(&self) -> String {
67        let mut params = Vec::new();
68
69        if let Some(begin_time) = &self.begin_time {
70            params.push(format!("begin_time={}", begin_time));
71        }
72
73        if let Some(end_time) = &self.end_time {
74            params.push(format!("end_time={}", end_time));
75        }
76
77        if let Some(sort_order) = &self.sort_order {
78            params.push(format!("sort_order={}", serde_json::to_string(sort_order).unwrap()));
79        }
80
81        if let Some(cursor) = &self.cursor {
82            params.push(format!("cursor={}", cursor));
83        }
84
85        if let Some(location_id) = &self.location_id {
86            params.push(format!("location_id={}", location_id));
87        }
88
89        if let Some(status) = &self.status {
90            params.push(format!("status={}", serde_json::to_string(status).unwrap()));
91        }
92
93        if let Some(source_type) = &self.source_type {
94            params.push(format!("source_type={}", serde_json::to_string(source_type).unwrap()));
95        }
96
97        if let Some(limit) = &self.limit {
98            params.push(format!("limit={}", limit));
99        }
100
101        if params.is_empty() {
102            String::new()
103        } else {
104            format!("?{}", params.join("&"))
105        }
106    }
107}