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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
//! The dispute workspace: native disputes and provider-only cases read as one
//! list, the bulk actions over them, and the refunds declared against a
//! dispute.
//!
//! Enumerated values (`dispute_status`, `outcome`, `reason`, …) are kept as
//! strings, so a value a newer API adds still decodes.
use std::collections::BTreeMap;
use std::fmt;
use serde::Deserialize;
use serde_json::Value;
/// One case of the workspace: a native dispute or a case only the provider
/// holds (a PayPal or Whop case, a subscription dispute).
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeWorkspaceRow {
/// The row's id, as the bulk actions name it.
pub id: String,
/// Who opened the case: `payment_provider`, `bank_card_issuer` or
/// `unknown`.
#[serde(default)]
pub origin: Option<String>,
/// `inquiry`, `dispute`, `bank_chargeback`, `pre_chargeback_alert` or
/// `unknown`.
#[serde(default)]
pub category: Option<String>,
/// The native dispute, when the case is one.
#[serde(default)]
pub native_dispute_id: Option<String>,
/// The PayPal case, for a PayPal case.
#[serde(default)]
pub paypal_case_id: Option<String>,
/// The Whop resolution case, for a Whop case.
#[serde(default)]
pub whop_case_id: Option<String>,
/// The subscription dispute, for one.
#[serde(default)]
pub subscription_dispute_id: Option<String>,
/// The disputed payment, when known.
#[serde(default)]
pub payment_id: Option<String>,
/// The disputed payment attempt, when known.
#[serde(default)]
pub attempt_id: Option<String>,
/// The disputed invoice, for a subscription dispute.
#[serde(default)]
pub invoice_id: Option<String>,
/// The subscription, for a subscription dispute.
#[serde(default)]
pub subscription_id: Option<String>,
/// The connector that reported the case.
pub connector: String,
/// The connector's own id for the case.
pub connector_dispute_id: String,
/// The connector account the case belongs to.
#[serde(default)]
pub merchant_connector_id: Option<String>,
/// The shop (business profile) of the case.
#[serde(default)]
pub profile_id: Option<String>,
/// Whether the case is a test case.
#[serde(default)]
pub test_mode: Option<bool>,
/// Three-letter ISO 4217 currency code.
pub currency: String,
/// The disputed amount in minor units, as a decimal string.
#[serde(default)]
pub amount_minor: Option<String>,
/// The disputed amount in major units, as a decimal string.
#[serde(default)]
pub amount_decimal: Option<String>,
/// Normalised dispute status.
#[serde(default)]
pub dispute_status: Option<String>,
/// Normalised dispute stage.
#[serde(default)]
pub dispute_stage: Option<String>,
/// The status as the provider reports it.
#[serde(default)]
pub provider_status: Option<String>,
/// The stage as the provider reports it.
#[serde(default)]
pub provider_stage: Option<String>,
/// The outcome as the provider reports it.
#[serde(default)]
pub provider_outcome: Option<String>,
/// The connector's reason for the case.
#[serde(default)]
pub connector_reason: Option<String>,
/// The card network's reason code.
#[serde(default)]
pub reason_code: Option<String>,
/// When the challenge must be in by, ISO 8601.
#[serde(default)]
pub challenge_required_by: Option<String>,
/// ISO 8601 creation timestamp.
pub created_at: String,
/// ISO 8601 last-update timestamp.
pub updated_at: String,
/// What can be done with the case now.
#[serde(default)]
pub available_actions: Vec<String>,
/// The amount the processor reported, in minor units of its currency,
/// when it reported one in another currency.
#[serde(default)]
pub reported_amount_minor: Option<String>,
/// The currency the processor reported the amount in.
#[serde(default)]
pub reported_currency: Option<String>,
/// The exchange rate the reservation was priced at.
#[serde(default)]
pub exchange_rate: Option<String>,
/// Whether the reported amount has been reconciled.
#[serde(default)]
pub reconciled: Option<bool>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the workspace.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeWorkspaceResponse {
/// The cases on this page.
#[serde(default)]
pub data: Vec<DisputeWorkspaceRow>,
/// Whether more cases follow this page.
pub has_more: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The filter values present in the workspace's scoped case set.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeWorkspaceFilters {
/// Connectors present.
#[serde(default)]
pub connector: Vec<String>,
/// Currencies present.
#[serde(default)]
pub currency: Vec<String>,
/// Dispute statuses present.
#[serde(default)]
pub dispute_status: Vec<String>,
/// Dispute stages present.
#[serde(default)]
pub dispute_stage: Vec<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Counts over the filtered workspace, without pagination.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeWorkspaceAggregate {
/// Every case matching the filters.
pub total_count: i64,
/// Cases per normalised status, including an `unknown` bucket; they add up
/// to `total_count`.
#[serde(default)]
pub status_with_count: BTreeMap<String, i64>,
/// The `unknown` bucket repeated, not an additional count.
pub unknown_count: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The complete filtered workspace, as one export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeWorkspaceExport {
/// Every matching case.
#[serde(default)]
pub data: Vec<DisputeWorkspaceRow>,
/// How many cases the export holds.
pub total_count: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A case a bulk action would act on.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkCase {
/// The workspace row id.
pub id: String,
/// The connector of the case.
pub connector: String,
/// The connector account of the case.
#[serde(default)]
pub merchant_connector_id: Option<String>,
/// The shop of the case.
#[serde(default)]
pub profile_id: Option<String>,
/// The disputed payment.
#[serde(default)]
pub payment_id: Option<String>,
/// The connector's own id for the case.
pub connector_dispute_id: String,
/// Three-letter ISO 4217 currency code.
pub currency: String,
/// The amount in minor units, as a decimal string, when known.
#[serde(default)]
pub amount_minor: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A case a bulk action would leave out, and why.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkSkip {
/// The workspace row id.
pub id: String,
/// The connector of the case.
#[serde(default)]
pub connector: Option<String>,
/// Why, for example `closed`, `not_acceptable_now` or `already_blocked`.
pub reason: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What the eligible cases add up to in one currency.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkTotal {
/// Three-letter ISO 4217 currency code.
pub currency: String,
/// The sum in minor units, as a decimal string.
pub amount_minor: String,
/// Eligible cases in this currency.
pub count: i64,
/// Of those, the cases without a known amount.
pub unpriced_count: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What a bulk action would do. Nothing was changed.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkPreviewResponse {
/// `accept` or `block_buyer`.
pub action: String,
/// How many cases were selected.
pub selected_count: i64,
/// The cases the action would act on.
#[serde(default)]
pub eligible: Vec<DisputeBulkCase>,
/// The cases it would leave out.
#[serde(default)]
pub ineligible: Vec<DisputeBulkSkip>,
/// What the eligible cases add up to, per currency.
#[serde(default)]
pub totals: Vec<DisputeBulkTotal>,
/// Whether more than `max_cases` matched, so only the first were read.
pub truncated: bool,
/// The most cases a preview reads.
pub max_cases: i64,
/// The most cases one bulk call acts on.
pub max_run_cases: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One case's result of a bulk accept.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkAcceptResult {
/// The workspace row id.
pub id: String,
/// The connector of the case.
#[serde(default)]
pub connector: Option<String>,
/// `accepted`, `skipped`, `failed` or `unknown`. An `unknown` result
/// means the processor may have acted: read the case before acting on it
/// again.
pub outcome: String,
/// Why a skipped case was left out.
#[serde(default)]
pub reason: Option<String>,
/// The error code of a failed case.
#[serde(default)]
pub error_code: Option<String>,
/// The error message of a failed case.
#[serde(default)]
pub error_message: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Every case's result of a bulk accept.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkAcceptResponse {
/// One result per listed case.
#[serde(default)]
pub results: Vec<DisputeBulkAcceptResult>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One buyer identifier a bulk block named, and what became of it.
///
/// The identifier's value is personal data: `Debug` prints `<redacted>` in its
/// place.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkBlockedIdentifier {
/// The identifier's kind, for example `email`, `ip` or `device_id`.
pub kind: String,
/// The identifier's value.
pub value: String,
/// The shop the entry blocks in, or `None` for every shop.
#[serde(default)]
pub profile_id: Option<String>,
/// `added`, `already_blocked` or `failed`.
pub state: String,
/// The blocklist entry that holds the identifier.
#[serde(default)]
pub entry_id: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for DisputeBulkBlockedIdentifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DisputeBulkBlockedIdentifier")
.field("kind", &self.kind)
.field("value", &"<redacted>")
.field("profile_id", &self.profile_id)
.field("state", &self.state)
.field("entry_id", &self.entry_id)
.finish_non_exhaustive()
}
}
/// One case's result of a bulk buyer block.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkBlockResult {
/// The workspace row id.
pub id: String,
/// The connector of the case.
#[serde(default)]
pub connector: Option<String>,
/// The case's payment.
#[serde(default)]
pub payment_id: Option<String>,
/// `blocked`, `already_blocked`, `skipped` or `failed`.
pub outcome: String,
/// Why a skipped case was left out.
#[serde(default)]
pub reason: Option<String>,
/// The identifiers the block named.
#[serde(default)]
pub identifiers: Vec<DisputeBulkBlockedIdentifier>,
/// The identifier kinds that could not be tied to the buyer.
#[serde(default)]
pub unattributed: Vec<String>,
/// The error code of a failed case.
#[serde(default)]
pub error_code: Option<String>,
/// The error message of a failed case.
#[serde(default)]
pub error_message: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Every case's result of a bulk buyer block.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeBulkBlockBuyerResponse {
/// One result per listed case.
#[serde(default)]
pub results: Vec<DisputeBulkBlockResult>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A refund declared against a dispute, or one the provider reported.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeRefundAssociation {
/// The merchant the dispute belongs to.
pub merchant_id: String,
/// The dispute.
pub dispute_id: String,
/// The refund, when known.
#[serde(default)]
pub refund_id: Option<String>,
/// The disputed payment.
pub payment_id: String,
/// The connector account of the payment.
pub merchant_connector_id: String,
/// Three-letter ISO 4217 currency code.
pub currency: String,
/// Whether the dispute is a test dispute.
pub test_mode: bool,
/// The amount allocated to the dispute, in minor units.
#[serde(default)]
pub allocated_amount: Option<i64>,
/// Who declared the link.
#[serde(default)]
pub declared_by: Option<String>,
/// The provider's own refund reference.
#[serde(default)]
pub provider_reference: Option<String>,
/// Where the provider reference came from.
#[serde(default)]
pub provider_provenance: Option<String>,
/// ISO 8601 creation timestamp.
pub created_at: String,
/// ISO 8601 last-modification timestamp.
pub modified_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The refunds linked to a dispute. Empty means unknown, not "none".
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeRefundAssociationsResponse {
/// Declared links and provider-reported refund references.
#[serde(default)]
pub associations: Vec<DisputeRefundAssociation>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A refund allocation declared against a dispute.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeRefundDeclaration {
/// The merchant the dispute belongs to.
pub merchant_id: String,
/// The dispute.
pub dispute_id: String,
/// The refund.
pub refund_id: String,
/// The disputed payment.
pub payment_id: String,
/// The connector account of the payment.
pub merchant_connector_id: String,
/// Three-letter ISO 4217 currency code.
pub currency: String,
/// Whether the dispute is a test dispute.
pub test_mode: bool,
/// The amount allocated, in minor units. `None` once cleared.
#[serde(default)]
pub allocated_amount: Option<i64>,
/// Who declared the link.
#[serde(default)]
pub declared_by: Option<String>,
/// The provider's own refund reference.
#[serde(default)]
pub provider_reference: Option<String>,
/// ISO 8601 creation timestamp.
pub created_at: String,
/// ISO 8601 last-modification timestamp.
pub modified_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}