1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use super::{enums::SortOrder, DateTime};
#[derive(Clone, Debug, Default)]
pub struct ListPaymentsParameters {
pub begin_time: Option<DateTime>,
pub end_time: Option<DateTime>,
pub sort_order: Option<SortOrder>,
pub cursor: Option<String>,
pub location_id: Option<String>,
pub total: Option<i32>,
pub last_4: Option<String>,
pub card_brand: Option<String>,
pub limit: Option<i32>,
}
impl ListPaymentsParameters {
pub fn to_query_string(&self) -> String {
self.to_string()
}
}
impl From<ListPaymentsParameters> for String {
fn from(list_payments_parameters: ListPaymentsParameters) -> Self {
list_payments_parameters.to_string()
}
}
impl ToString for ListPaymentsParameters {
fn to_string(&self) -> String {
let mut params = Vec::new();
if let Some(begin_time) = &self.begin_time {
params.push(format!("begin_time={}", begin_time));
}
if let Some(end_time) = &self.end_time {
params.push(format!("end_time={}", end_time));
}
if let Some(sort_order) = &self.sort_order {
params.push(format!(
"sort_order={}",
serde_json::to_string(sort_order).unwrap()
));
}
if let Some(cursor) = &self.cursor {
params.push(format!("cursor={}", cursor));
}
if let Some(location_id) = &self.location_id {
params.push(format!("location_id={}", location_id));
}
if let Some(total) = &self.total {
params.push(format!("total={}", total));
}
if let Some(last_4) = &self.last_4 {
params.push(format!("last_4={}", last_4));
}
if let Some(card_brand) = &self.card_brand {
params.push(format!("card_brand={}", card_brand));
}
if let Some(limit) = &self.limit {
params.push(format!("limit={}", limit));
}
if params.is_empty() {
String::new()
} else {
format!("?{}", params.join("&"))
}
}
}