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
//! Project models: the project itself and the merchant-level aggregates
//! returned by the project stats and overview endpoints.
use serde::Deserialize;
use serde_json::Value;
use crate::core::models::shop::{CurrencyRevenue, ShopStats};
/// A project — an optional grouping layer that contains one or more shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectResponse {
/// Unique project ID (the API field is `id`, not `project_id`).
pub id: String,
/// Merchant account that owns this project.
pub merchant_id: String,
/// Display name of the project.
pub project_name: String,
/// Whether the project is active.
pub is_active: bool,
/// ISO 8601 creation timestamp.
pub created_at: String,
/// ISO 8601 last-modification timestamp.
pub modified_at: String,
/// Free-form description.
#[serde(default)]
pub description: Option<String>,
/// The parent project; `None` for a top-level project.
#[serde(default)]
pub parent_id: Option<String>,
/// The project's level, a top-level project being 1. `0` from an older
/// API.
#[serde(default)]
pub level: i32,
/// The projects from the top level down to this one.
#[serde(default)]
pub path: Vec<ProjectPathEntry>,
/// How many projects sit directly under this one.
#[serde(default)]
pub child_project_count: i32,
/// How many shops sit directly in this project.
#[serde(default)]
pub direct_shop_count: i32,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Order and revenue figures for one project, plus its shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectStats {
/// The project these figures belong to.
pub project_id: String,
/// Display name of the project.
pub project_name: String,
/// Number of successful orders in the window.
pub orders: i64,
/// Raw cross-currency minor-unit sum — do not display. Use
/// [`revenue_usd`](Self::revenue_usd) or
/// [`revenue_by_currency`](Self::revenue_by_currency).
pub revenue: i64,
/// FX-converted revenue in USD major units.
pub revenue_usd: f64,
/// Revenue split by the currency it was taken in.
#[serde(default)]
pub revenue_by_currency: Vec<CurrencyRevenue>,
/// Orders left out of `revenue_usd` for want of a fresh USD rate.
pub unconverted_orders: i64,
/// Per-shop breakdown for the shops grouped under this project.
#[serde(default)]
pub shops: Vec<ShopStats>,
/// The parent project; `None` for a top-level project.
#[serde(default)]
pub parent_id: Option<String>,
/// The project's level, a top-level project being 1.
#[serde(default)]
pub level: i32,
/// What the totals cover: `"subtree"`, the project and every project
/// under it.
#[serde(default)]
pub scope: Option<String>,
/// The figures of the project's own shops only.
#[serde(default)]
pub direct: Option<ProjectDirectStats>,
/// Every shop the subtree totals cover.
#[serde(default)]
pub descendant_shop_ids: Vec<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Aggregate payment statistics across all of a merchant's projects, as
/// returned by the `projects.stats` endpoint.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectStatsResponse {
/// Per-project breakdown.
#[serde(default)]
pub projects: Vec<ProjectStats>,
/// Every shop of the merchant, including shops that belong to no project —
/// those never appear under `projects[].shops`, since projects are an
/// optional grouping layer. Look a single shop up here rather than walking
/// the project tree.
#[serde(default)]
pub shops: Vec<ShopStats>,
/// Total number of successful orders in the window.
pub total_orders: i64,
/// Raw cross-currency minor-unit sum — do not display. Use
/// [`total_revenue_usd`](Self::total_revenue_usd).
pub total_revenue: i64,
/// FX-converted total revenue in USD major units.
pub total_revenue_usd: f64,
/// Total revenue split by the currency it was taken in.
#[serde(default)]
pub total_revenue_by_currency: Vec<CurrencyRevenue>,
/// Orders left out of `total_revenue_usd` for want of a fresh USD rate.
pub unconverted_orders: i64,
/// Window the figures cover, in days. `None` when an all-time total was
/// asked for.
#[serde(default)]
pub period_days: Option<i64>,
/// Whether payments marked as integration tests are left out of these
/// figures. `false` from an older API.
#[serde(default)]
pub analytics_exclusions_active: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One project on the way from the top level to a project.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectPathEntry {
/// The project's ID.
pub id: String,
/// The project's name.
pub project_name: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The figures of a project's own shops, without its sub-projects.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectDirectStats {
/// Orders.
pub orders: i64,
/// Raw cross-currency sum of minor units; prefer `revenue_usd` or
/// `revenue_by_currency`.
pub revenue: i64,
/// Revenue converted to USD.
pub revenue_usd: f64,
/// Revenue per currency.
#[serde(default)]
pub revenue_by_currency: Vec<CurrencyRevenue>,
/// Orders left out of `revenue_usd` for want of a USD rate.
pub unconverted_orders: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One headline figure on the merchant overview, with its period-over-period
/// change.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantOverviewStat {
/// Human-readable label for the figure.
pub label: String,
/// The figure itself.
pub value: f64,
/// Change against the previous window, in percent.
pub change_percent: f64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// High-level merchant overview, as returned by the `projects.overview`
/// endpoint.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantOverviewResponse {
/// Total number of shops.
pub total_shops: MerchantOverviewStat,
/// Number of active shops.
pub active_shops: MerchantOverviewStat,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Where a merchant's project depth limit comes from: `"default"`,
/// `"platform"` or `"merchant_override"`.
pub type ProjectDepthSource = String;
/// How deep a merchant may nest projects, and how deep it does.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectLimitsResponse {
/// The most project levels the merchant may have, a root project being
/// level 1.
pub max_depth: u32,
/// Where that limit comes from.
pub source: ProjectDepthSource,
/// The level of the merchant's deepest project; 0 without projects.
pub deepest_level: u32,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}