square_api_client/models/
list_payments_parameters.rs

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