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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct StatisticClient {
pub http_client: HttpClient,
}
impl StatisticClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Retrieves the basic statistics for an organization or a paypoint, for a given time period, grouped by a particular frequency.
///
/// # Arguments
///
/// * `mode` - Mode for the request. Allowed values:
///
/// - `custom` - Allows you to set a custom date range
/// - `ytd` - Year To Date
/// - `mtd` - Month To Date
/// - `wtd` - Week To Date
/// - `today` - All current day
/// - `m12` - Last 12 months
/// - `d30` - Last 30 days
/// - `h24` - Last 24 hours
/// - `lasty` - Last Year
/// - `lastm` - Last Month
/// - `lastw` - Last Week
/// - `yesterday` - Last Day
/// * `freq` - Frequency to group series. Allowed values:
///
/// - `m` - monthly
/// - `w` - weekly
/// - `d` - daily
/// - `h` - hourly
///
/// For example, `w` groups the results by week.
/// * `level` - The entry level for the request:
/// - 0 for Organization
/// - 2 for Paypoint
/// * `entry_id` - Identifier in Payabli for the entity.
/// * `end_date` - Used with `custom` mode. The end date for the range.
/// Valid formats:
/// - YYYY-mm-dd
/// - YYYY/mm/dd
/// - mm-dd-YYYY
/// - mm/dd/YYYY
/// * `parameters` - List of parameters.
/// * `start_date` - Used with `custom` mode. The start date for the range.
/// Valid formats:
/// - YYYY-mm-dd
/// - YYYY/mm/dd
/// - mm-dd-YYYY
/// - mm/dd/YYYY
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn basic_stats(
&self,
mode: &str,
freq: &str,
level: i64,
entry_id: i64,
request: &BasicStatsQueryRequest,
options: Option<RequestOptions>,
) -> Result<Vec<StatBasicExtendedQueryRecord>, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Statistic/basic/{}/{}/{}/{}", mode, freq, level, entry_id),
None,
QueryBuilder::new()
.string("endDate", request.end_date.clone())
.serialize("parameters", request.parameters.clone())
.string("startDate", request.start_date.clone())
.build(),
options,
)
.await
}
/// Retrieves the basic statistics for a customer for a specific time period, grouped by a selected frequency.
///
/// # Arguments
///
/// * `mode` - Mode for request. Allowed values:
///
/// - `ytd` - Year To Date
/// - `mtd` - Month To Date
/// - `wtd` - Week To Date
/// - `today` - All current day
/// - `m12` - Last 12 months
/// - `d30` - Last 30 days
/// - `h24` - Last 24 hours
/// - `lasty` - Last Year
/// - `lastm` - Last Month
/// - `lastw` - Last Week
/// - `yesterday` - Last Day
/// * `freq` - Frequency to group series. Allowed values:
///
/// - `m` - monthly
/// - `w` - weekly
/// - `d` - daily
/// - `h` - hourly
///
/// For example, `w` groups the results by week.
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `parameters` - List of parameters.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn customer_basic_stats(
&self,
mode: &str,
freq: &str,
customer_id: i64,
request: &CustomerBasicStatsQueryRequest,
options: Option<RequestOptions>,
) -> Result<Vec<SubscriptionStatsQueryRecord>, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Statistic/customerbasic/{}/{}/{}", mode, freq, customer_id),
None,
QueryBuilder::new()
.serialize("parameters", request.parameters.clone())
.build(),
options,
)
.await
}
/// Retrieves the subscription statistics for a given interval for a paypoint or organization.
///
/// # Arguments
///
/// * `interval` - Interval to get the data. Allowed values:
///
/// - `all` - all intervals
/// - `30` - 1-30 days
/// - `60` - 31-60 days
/// - `90` - 61-90 days
/// - `plus` - +90 days
/// * `level` - The entry level for the request:
/// - 0 for Organization
/// - 2 for Paypoint
/// * `entry_id` - Identifier in Payabli for the entity.
/// * `parameters` - List of parameters
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn sub_stats(
&self,
interval: &str,
level: i64,
entry_id: i64,
request: &SubStatsQueryRequest,
options: Option<RequestOptions>,
) -> Result<Vec<StatBasicQueryRecord>, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!(
"Statistic/subscriptions/{}/{}/{}",
interval, level, entry_id
),
None,
QueryBuilder::new()
.serialize("parameters", request.parameters.clone())
.build(),
options,
)
.await
}
/// Retrieve the basic statistics about a vendor for a given time period, grouped by frequency.
///
/// # Arguments
///
/// * `mode` - Mode for request. Allowed values:
///
/// - `ytd` - Year To Date
/// - `mtd` - Month To Date
/// - `wtd` - Week To Date
/// - `today` - All current day
/// - `m12` - Last 12 months
/// - `d30` - Last 30 days
/// - `h24` - Last 24 hours
/// - `lasty` - Last Year
/// - `lastm` - Last Month
/// - `lastw` - Last Week
/// - `yesterday` - Last Day
/// * `freq` - Frequency to group series. Allowed values:
///
/// - `m` - monthly
/// - `w` - weekly
/// - `d` - daily
/// - `h` - hourly
///
/// For example, `w` groups the results by week.
/// * `id_vendor` - Vendor ID.
/// * `parameters` - List of parameters
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn vendor_basic_stats(
&self,
mode: &str,
freq: &str,
id_vendor: i64,
request: &VendorBasicStatsQueryRequest,
options: Option<RequestOptions>,
) -> Result<Vec<StatisticsVendorQueryRecord>, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Statistic/vendorbasic/{}/{}/{}", mode, freq, id_vendor),
None,
QueryBuilder::new()
.serialize("parameters", request.parameters.clone())
.build(),
options,
)
.await
}
}