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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//! Export envelopes and the rows they carry.
//!
//! An export is **one read, never a paged walk**, and it is bounded: 25 000
//! rows, 500 for a PDF. Over the bound the request is refused with
//! `DE_07 export_row_limit_exceeded` naming the entity and the limit — a
//! truncated finance file answered with a `200` is the thing these endpoints
//! exist not to produce.
use serde::Deserialize;
use serde_json::Value;
/// A JSON export: the rows, how many there are, and the filters they were
/// produced under.
///
/// [`filters`](Self::filters) echoes what the server actually applied, so a
/// file can be shown beside the question it answers rather than beside the
/// question the caller believes it asked.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ExportEnvelope<T> {
/// The exported rows.
#[serde(default = "Vec::new")]
pub records: Vec<T>,
/// How many rows the file holds.
#[serde(default)]
pub record_count: Option<i64>,
/// The filters the export ran under, as the server resolved them.
#[serde(default)]
pub filters: Option<Value>,
/// Any additional envelope fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a transaction export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct TransactionExportRecord {
/// The payment.
pub payment_id: String,
/// The merchant account it belongs to.
#[serde(default)]
pub merchant_id: Option<String>,
/// The shop it belongs to.
#[serde(default)]
pub shop_id: Option<String>,
/// The payment's status.
#[serde(default)]
pub status: Option<String>,
/// Amount in minor units.
#[serde(default)]
pub amount: Option<i64>,
/// Three-letter ISO 4217 currency code.
#[serde(default)]
pub currency: Option<String>,
/// When the payment was created (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// The payment's environment. `None` when it never recorded one, which
/// is not the same as `false`; a file can span both environments.
#[serde(default)]
pub test_mode: Option<bool>,
/// Where the active attempt's money has got to, as the rail reports it.
/// Present only on the merchant-level export.
#[serde(default)]
pub connector_settlement_status: Option<String>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a transaction line export: one per product line a payment
/// recorded, and one with `row_kind == "no_lines"` for each payment that
/// recorded none, so every payment of the per-payment export is present.
///
/// [`payment_amount`](Self::payment_amount) is set on each payment's **first
/// row only** and `None` on its further rows, so it sums to exactly what the
/// per-payment export's `amount` sums to for the same filters. The line
/// figures are in the line's own [`currency`](Self::currency) and need not
/// add up to the payment amount.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct TransactionLineExportRecord {
/// The payment.
pub payment_id: String,
/// The merchant account it belongs to.
pub merchant_id: String,
/// The shop it belongs to.
#[serde(default)]
pub shop_id: Option<String>,
/// When the payment was created (ISO 8601, UTC).
#[serde(default)]
pub created_at: Option<String>,
/// The payment's status.
pub status: String,
/// The payment's environment. `None` when it never recorded one.
#[serde(default)]
pub test_mode: Option<bool>,
/// The payment amount in minor units, on the payment's first row only.
#[serde(default)]
pub payment_amount: Option<i64>,
/// The payment's currency.
#[serde(default)]
pub payment_currency: Option<String>,
/// `"line"`, or `"no_lines"` for a payment without product lines. New
/// kinds may be added.
pub row_kind: String,
/// The line's ID.
#[serde(default)]
pub line_id: Option<String>,
/// The line's place in the payment, from 0.
#[serde(default)]
pub position: Option<i64>,
/// The line an add-on or component belongs to.
#[serde(default)]
pub parent_line_id: Option<String>,
/// `"product"`, `"addon"`, `"bundle"` or `"component"`.
#[serde(default)]
pub line_role: Option<String>,
/// The catalog product the line resolved to.
#[serde(default)]
pub product_id: Option<String>,
/// The product's name as it read when the payment was made.
#[serde(default)]
pub product_name: Option<String>,
/// The name the caller used, when it was not the product's own.
#[serde(default)]
pub product_alias: Option<String>,
/// Whether the line resolved to a catalog product; `false` on a
/// `no_lines` row.
#[serde(default)]
pub attributed: bool,
/// Units bought.
#[serde(default)]
pub quantity: Option<i64>,
/// Unit price in minor units of `currency`.
#[serde(default)]
pub unit_amount: Option<i64>,
/// `unit_amount × quantity`, in minor units of `currency`.
#[serde(default)]
pub line_total: Option<i64>,
/// The line's own currency.
#[serde(default)]
pub currency: Option<String>,
/// The tax rate as the caller reported it. `None` is not zero.
#[serde(default)]
pub tax_rate: Option<f64>,
/// The tax amount in minor units of `currency`, as the caller reported
/// it. `None` is not zero.
#[serde(default)]
pub tax_amount: Option<i64>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a refund export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundExportRecord {
/// The refund.
pub refund_id: String,
/// The payment it refunds.
#[serde(default)]
pub payment_id: Option<String>,
/// The shop it belongs to.
#[serde(default)]
pub profile_id: Option<String>,
/// The refund's status.
#[serde(default)]
pub status: Option<String>,
/// Amount in minor units.
#[serde(default)]
pub amount: Option<i64>,
/// Three-letter ISO 4217 currency code.
#[serde(default)]
pub currency: Option<String>,
/// The stated reason.
#[serde(default)]
pub reason: Option<String>,
/// The connector that processed it.
#[serde(default)]
pub connector: Option<String>,
/// Connector error code, when it failed.
#[serde(default)]
pub error_code: Option<String>,
/// Connector error message, when it failed.
#[serde(default)]
pub error_message: Option<String>,
/// When it was created (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// When it was last updated (RFC 3339).
#[serde(default)]
pub updated_at: Option<String>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a dispute export.
///
/// [`amount`](Self::amount) is a decimal **string**, as the dispute records it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeExportRecord {
/// The dispute.
pub dispute_id: String,
/// The payment it was raised against.
#[serde(default)]
pub payment_id: Option<String>,
/// The attempt it was raised against.
#[serde(default)]
pub attempt_id: Option<String>,
/// The shop it belongs to.
#[serde(default)]
pub profile_id: Option<String>,
/// The dispute's lifecycle stage.
#[serde(default)]
pub dispute_stage: Option<String>,
/// The dispute's status.
#[serde(default)]
pub dispute_status: Option<String>,
/// Disputed amount, as a decimal string.
#[serde(default)]
pub amount: Option<String>,
/// Three-letter ISO 4217 currency code.
#[serde(default)]
pub currency: Option<String>,
/// The connector that reported it.
#[serde(default)]
pub connector: Option<String>,
/// The connector's own status, verbatim.
#[serde(default)]
pub connector_status: Option<String>,
/// The connector's own dispute id.
#[serde(default)]
pub connector_dispute_id: Option<String>,
/// The connector's stated reason.
#[serde(default)]
pub connector_reason: Option<String>,
/// The connector's code for that reason.
#[serde(default)]
pub connector_reason_code: Option<String>,
/// Deadline to challenge (RFC 3339).
#[serde(default)]
pub challenge_required_by: Option<String>,
/// When it was created (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a payout export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PayoutExportRecord {
/// The payout.
pub payout_id: String,
/// The shop it belongs to.
#[serde(default)]
pub profile_id: Option<String>,
/// The customer paid out to.
#[serde(default)]
pub customer_id: Option<String>,
/// The payout's status.
#[serde(default)]
pub status: Option<String>,
/// Amount in minor units.
#[serde(default)]
pub amount: Option<i64>,
/// Three-letter ISO 4217 currency code.
#[serde(default)]
pub currency: Option<String>,
/// The payout's type.
#[serde(default)]
pub payout_type: Option<String>,
/// The connector that processed it.
#[serde(default)]
pub connector: Option<String>,
/// Connector error code, when it failed.
#[serde(default)]
pub error_code: Option<String>,
/// Connector error message, when it failed.
#[serde(default)]
pub error_message: Option<String>,
/// The merchant's own reference for the order.
#[serde(default)]
pub merchant_order_reference_id: Option<String>,
/// When it was created (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a subscription export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SubscriptionExportRecord {
/// The subscription.
pub id: String,
/// The merchant's own reference for it.
#[serde(default)]
pub merchant_reference_id: Option<String>,
/// The shop it belongs to.
#[serde(default)]
pub profile_id: Option<String>,
/// The customer it bills.
#[serde(default)]
pub customer_id: Option<String>,
/// The subscription's status.
#[serde(default)]
pub status: Option<String>,
/// The plan it runs on.
#[serde(default)]
pub plan_id: Option<String>,
/// The price it runs on.
#[serde(default)]
pub item_price_id: Option<String>,
/// The coupon applied, when one is.
#[serde(default)]
pub coupon_code: Option<String>,
/// Which environment it runs in.
#[serde(default)]
pub test_mode: Option<bool>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One row of a merchant audit-log export.
///
/// The `real_actor_*` and `impersonation_kind` fields are what separate "the
/// user did this" from "somebody acting as that user did this": render the
/// real actor wherever one is present.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogExportRecord {
/// When the change was recorded (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// What kind of actor made it.
#[serde(default)]
pub actor_kind: Option<String>,
/// The acting user's id, as the log recorded it.
#[serde(default)]
pub actor_id: Option<String>,
/// The acting user's name.
#[serde(default)]
pub actor_name: Option<String>,
/// The person behind an impersonated session, when there was one.
#[serde(default)]
pub real_actor_id: Option<String>,
/// That person's name.
#[serde(default)]
pub real_actor_name: Option<String>,
/// What kind of impersonation it was, when it was one.
#[serde(default)]
pub impersonation_kind: Option<String>,
/// The sign-in the change happened in.
#[serde(default)]
pub session_id: Option<String>,
/// The address the change came from.
#[serde(default)]
pub ip_address: Option<String>,
/// The client that made it.
#[serde(default)]
pub user_agent: Option<String>,
/// The shop the change was scoped to.
#[serde(default)]
pub profile_id: Option<String>,
/// What was done.
#[serde(default)]
pub action: Option<String>,
/// What kind of thing it was done to.
#[serde(default)]
pub entity_type: Option<String>,
/// Which one.
#[serde(default)]
pub entity_id: Option<String>,
/// Its name at the time.
#[serde(default)]
pub entity_name: Option<String>,
/// The fields that changed, as the log renders them.
#[serde(default)]
pub changed_fields: Option<String>,
/// Any additional row fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}