delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
//! Chargeback prevention: alerts from a prevention provider account the
//! merchant connected with its own key.
//!
//! Each case carries the provider's status verbatim, DeloPay's reading of it
//! and an `outcome` taken from DeloPay's own refunds and disputes first. An
//! alert alone is never an outcome.

use serde::{Deserialize, Serialize};
use serde_json::Value;

/// One business account the provider holds under a connection.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionAccount {
    /// The provider's id of the business account.
    pub provider_account_id: String,
    /// Its name at the provider.
    #[serde(default)]
    pub name: Option<String>,
    /// Its website at the provider.
    #[serde(default)]
    pub url: Option<String>,
    /// The shops it sells through. Empty: unassigned.
    #[serde(default)]
    pub profile_ids: Vec<String>,
    /// The processor accounts it is limited to. Empty: any of those shops.
    #[serde(default)]
    pub merchant_connector_ids: Vec<String>,
    /// `false` once the provider no longer lists it.
    pub present: bool,
    /// When the shops were last set, ISO 8601.
    #[serde(default)]
    pub mapped_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// How current a connection's cases are.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionSyncHealth {
    /// `ok`, `rate_limited`, `auth_failed`, `failed` or `unknown`.
    #[serde(default)]
    pub status: Option<String>,
    /// What went wrong last.
    #[serde(default)]
    pub error: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub last_started_at: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub last_completed_at: Option<String>,
    /// When the provider's request limit lets the next read start, ISO 8601.
    #[serde(default)]
    pub retry_at: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub last_webhook_at: Option<String>,
    /// The last read failed, or none completed for too long.
    pub stale: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A connected provider account. Carries no key.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionConnection {
    /// The connection's id.
    pub id: String,
    /// The merchant.
    pub merchant_id: String,
    /// `chargebackio` or `chargebackhit`.
    pub provider: String,
    /// Whether its alerts belong to test payments.
    pub test_mode: bool,
    /// `active`, `auth_failed`, `disconnected` or `unknown`.
    pub status: String,
    /// How current its cases are.
    pub sync: PreventionSyncHealth,
    /// Its business accounts.
    #[serde(default)]
    pub accounts: Vec<PreventionAccount>,
    /// ISO 8601.
    pub created_at: String,
    /// Who connected it.
    #[serde(default)]
    pub created_by: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub disconnected_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The merchant's connections.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionConnectionList {
    /// Every connection, disconnected ones included.
    pub connections: Vec<PreventionConnection>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A connection's state beside a case list.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionConnectionSummary {
    /// The connection's id.
    pub id: String,
    /// `chargebackio` or `chargebackhit`.
    pub provider: String,
    /// Whether its alerts belong to test payments.
    pub test_mode: bool,
    /// `active`, `auth_failed`, `disconnected` or `unknown`.
    pub status: String,
    /// How current its cases are.
    pub sync: PreventionSyncHealth,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One alert and what DeloPay knows of its payment.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionCase {
    /// The case's id.
    pub id: String,
    /// The merchant.
    pub merchant_id: String,
    /// The connection that reported it.
    pub connection_id: String,
    /// `chargebackio` or `chargebackhit`.
    pub provider: String,
    /// Whether it belongs to test payments.
    pub test_mode: bool,
    /// The provider's business account.
    pub provider_account_id: String,
    /// Its name at the provider.
    #[serde(default)]
    pub provider_account_name: Option<String>,
    /// The provider's reference for the alert.
    pub provider_case_id: String,
    /// The network's reference for the alert.
    #[serde(default)]
    pub provider_alert_id: Option<String>,
    /// The network or program that raised it, e.g. `ethoca`, `cdrn`, `rdr`.
    #[serde(default)]
    pub source: Option<String>,
    /// The provider's alert type.
    #[serde(default)]
    pub alert_type: Option<String>,
    /// The provider's status, verbatim.
    pub provider_status: String,
    /// DeloPay's reading of it: `attention`, `refunded`,
    /// `previously_refunded`, `declined`, `not_found`, `failed_transaction`,
    /// `already_chargeback`, `answered` (answered without a refund),
    /// `answer_failed` (the provider recorded the answer as invalid or
    /// failed), `deflected` (the provider reports the network prevented the
    /// dispute), `issuer_report` (an issuer's fraud report, nothing to answer)
    /// or `unknown`.
    pub status: String,
    /// What happened to the payment: `open`, `refund_confirmed` (DeloPay
    /// holds a successful refund), `refund_reported` (only the provider says
    /// so), `chargeback`, `dispute_won`, `declined`, `not_found`,
    /// `failed_transaction`, `withdrawn` (the provider withdrew the alert,
    /// nothing was resolved), `deflected` (the provider's word that the
    /// network prevented the dispute, not an outcome DeloPay confirms),
    /// `answered` (the inquiry was answered; the cardholder may still
    /// dispute), `informational` (a notice that needs no answer) or
    /// `unknown`.
    pub outcome: String,
    /// The provider's reason.
    #[serde(default)]
    pub reason: Option<String>,
    /// Decimal in major units, as the provider reports it.
    #[serde(default)]
    pub amount: Option<String>,
    /// ISO 4217.
    #[serde(default)]
    pub currency: Option<String>,
    /// What the provider charged for the alert, in minor units of
    /// `cost_currency`.
    #[serde(default)]
    pub cost_minor: Option<i64>,
    /// ISO 4217.
    #[serde(default)]
    pub cost_currency: Option<String>,
    /// The card's last four digits.
    #[serde(default)]
    pub card_last4: Option<String>,
    /// The card's brand.
    #[serde(default)]
    pub card_brand: Option<String>,
    /// Processor names the provider attributed it to.
    #[serde(default)]
    pub processors: Vec<String>,
    /// The provider's message to the merchant.
    #[serde(default)]
    pub provider_message: Option<String>,
    /// The provider's deadline to act, ISO 8601.
    #[serde(default)]
    pub respond_by: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub transaction_at: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub alerted_at: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub provider_updated_at: Option<String>,
    /// `matched`, `unmatched`, `ambiguous`, `unassigned` or `unknown`.
    pub match_status: String,
    /// The shop of the matched payment.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The processor account of the matched payment.
    #[serde(default)]
    pub merchant_connector_id: Option<String>,
    /// The matched payment.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The matched attempt.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// A successful DeloPay refund of the payment exists.
    pub refund_confirmed: bool,
    /// The latest DeloPay dispute on the payment.
    #[serde(default)]
    pub dispute_id: Option<String>,
    /// Its status.
    #[serde(default)]
    pub dispute_status: Option<String>,
    /// What DeloPay answered the provider's delivery of the alert, for a
    /// provider whose alert notifications are answered (Chargebackhit).
    #[serde(default)]
    pub answer: Option<PreventionAnswer>,
    /// When the provider withdrew the alert, ISO 8601. The case is kept.
    #[serde(default)]
    pub withdrawn_at: Option<String>,
    /// What the merchant's refund rule did about the payment, whichever of
    /// the payment's alerts it acted on. `None` when it did nothing.
    #[serde(default)]
    pub refund_action: Option<PreventionRefundActionSummary>,
    /// ISO 8601.
    pub created_at: String,
    /// ISO 8601.
    pub modified_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What DeloPay answered the provider's latest delivery of an alert.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionAnswer {
    /// The outcome sent, in the provider's vocabulary: `acknowledged`,
    /// `not-found`, `pending`, `previously-reversed` or `decline`. `None`
    /// when DeloPay could not answer.
    #[serde(default)]
    pub outcome: Option<String>,
    /// Why, as a key: `matched`, `no_payment`, `several_payments`,
    /// `no_shop`, `merchant_details_missing`, `order_details_incomplete`,
    /// `refunded_before_alert`, `payment_failed`, `awaiting_merchant`,
    /// `notice`, `withdrawn`, `too_slow` or `failed`.
    #[serde(default)]
    pub reason: Option<String>,
    /// How long the answer took, in milliseconds.
    #[serde(default)]
    pub elapsed_ms: Option<i64>,
    /// ISO 8601.
    #[serde(default)]
    pub answered_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One state of a case DeloPay observed, in the provider's order.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionCaseEvent {
    /// The provider's status, verbatim.
    pub provider_status: String,
    /// DeloPay's reading of it.
    pub status: String,
    /// The provider's message.
    #[serde(default)]
    pub provider_message: Option<String>,
    /// ISO 8601.
    pub provider_updated_at: String,
    /// ISO 8601.
    pub observed_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A case with its references and history.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionCaseDetail {
    /// The case.
    #[serde(flatten)]
    pub case: PreventionCase,
    /// The merchant descriptor the alert names.
    #[serde(default)]
    pub merchant_descriptor: Option<String>,
    /// Acquirer reference number.
    #[serde(default)]
    pub arn: Option<String>,
    /// The authorization code.
    #[serde(default)]
    pub auth_code: Option<String>,
    /// Processor transaction ids the provider named.
    #[serde(default)]
    pub transaction_ids: Vec<String>,
    /// Its observed history.
    #[serde(default)]
    pub events: Vec<PreventionCaseEvent>,
}

/// A page of cases.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionCaseList {
    /// The page.
    pub data: Vec<PreventionCase>,
    /// Cases matching the filters.
    pub total: i64,
    /// The state of every connection in scope.
    #[serde(default)]
    pub connections: Vec<PreventionConnectionSummary>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The most a refund rule refunds for one alert in one currency.
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct PreventionRefundLimit {
    /// ISO 4217.
    pub currency: String,
    /// In the currency's minor units.
    pub max_amount: i64,
}

/// A merchant's opt-in refund rule for one prevention connector account and
/// environment. Off unless the merchant turns it on in the dashboard.
///
/// While it is on, DeloPay refunds the payment a matched alert in Attention
/// names, once, through the payment's own processor, and reports the refund
/// to the provider. A payment DeloPay already holds refunded is reconciled,
/// never refunded again. A Chargebackhit rule refunds refund requests only.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundRule {
    /// The merchant.
    pub merchant_id: String,
    /// The prevention connector account the rule belongs to.
    pub merchant_connector_id: String,
    /// The connection reading that account's slot, when one is connected.
    #[serde(default)]
    pub connection_id: Option<String>,
    /// `chargebackio` or `chargebackhit`.
    pub provider: String,
    /// Test or live.
    pub test_mode: bool,
    /// Whether the rule acts.
    pub enabled: bool,
    /// Alert sources refunded: `cdrn`, `ethoca`, `paypal`.
    #[serde(default)]
    pub alert_sources: Vec<String>,
    /// One limit per currency refunded. An alert in any other currency is
    /// not refunded.
    #[serde(default)]
    pub amount_limits: Vec<PreventionRefundLimit>,
    /// Most refunds started in any 24 hours.
    pub daily_limit: i32,
    /// An alert raised longer ago than this is not refunded.
    pub max_alert_age_hours: i32,
    /// `0` for a rule never saved.
    pub version: i32,
    /// Who saved this version.
    #[serde(default)]
    pub updated_by: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub updated_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Every connected account's refund rule.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundRuleList {
    /// One per connected account and environment.
    pub rules: Vec<PreventionRefundRule>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a rule would do with one open alert.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundPreviewItem {
    /// The case.
    pub case_id: String,
    /// The network's reference for the alert.
    #[serde(default)]
    pub provider_alert_id: Option<String>,
    /// The matched payment.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// Its shop.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The network or program.
    #[serde(default)]
    pub source: Option<String>,
    /// Decimal in major units, as the provider reports it.
    #[serde(default)]
    pub amount: Option<String>,
    /// ISO 4217.
    #[serde(default)]
    pub currency: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub respond_by: Option<String>,
    /// `refund`, `reconcile` (already refunded: reported, not refunded
    /// again) or `skip`.
    pub decision: String,
    /// Why it is skipped, e.g. `source_not_selected`, `over_limit`,
    /// `partially_refunded`, `disputed`, `other_charge`.
    #[serde(default)]
    pub reason: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a rule would do with the account's open alerts now.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundPreview {
    /// The rule applied.
    pub rule: PreventionRefundRule,
    /// Open matched alerts without an action yet. The daily limit is not
    /// applied here.
    #[serde(default)]
    pub items: Vec<PreventionRefundPreviewItem>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The refund rule's action on a case's payment, as the case shows it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundActionSummary {
    /// The action.
    pub id: String,
    /// The alert it acted on.
    pub case_id: String,
    /// The refund DeloPay made; its id is the action's.
    pub refund_id: String,
    /// In the payment currency's minor units.
    pub amount: i64,
    /// ISO 4217.
    pub currency: String,
    /// `refunding`, `pending`, `succeeded`, `failed`, `reconciled` or
    /// `unknown`.
    pub state: String,
    /// `none`, `due`, `reported`, `refused` or `unknown`.
    pub report_state: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a refund rule did about one alert: a refund it made, or a payment it
/// found already refunded. One per payment.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundAction {
    /// The action.
    pub id: String,
    /// The merchant.
    pub merchant_id: String,
    /// The alert it acted on.
    pub case_id: String,
    /// The prevention connector account.
    pub merchant_connector_id: String,
    /// Test or live.
    pub test_mode: bool,
    /// The refunded payment.
    pub payment_id: String,
    /// Its shop.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The refund DeloPay made; its id is the action's.
    pub refund_id: String,
    /// In the payment currency's minor units.
    pub amount: i64,
    /// ISO 4217.
    pub currency: String,
    /// `refunding`, `pending`, `succeeded`, `failed`, `reconciled` or
    /// `unknown`. Only `succeeded` is a refund the processor confirmed.
    pub state: String,
    /// Why it failed.
    #[serde(default)]
    pub reason: Option<String>,
    /// The rule version it was decided under.
    pub rule_version: i32,
    /// The rule as it stood then.
    #[serde(default)]
    pub rule: Value,
    /// The status reported to the provider.
    #[serde(default)]
    pub report_status: Option<String>,
    /// `none`, `due`, `reported`, `refused` or `unknown`.
    pub report_state: String,
    /// Why the provider refused the report.
    #[serde(default)]
    pub report_error: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub reported_at: Option<String>,
    /// ISO 8601.
    #[serde(default)]
    pub settled_at: Option<String>,
    /// ISO 8601.
    pub created_at: String,
    /// ISO 8601.
    pub modified_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A page of refund rule actions.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PreventionRefundActionList {
    /// The page, newest first.
    pub data: Vec<PreventionRefundAction>,
    /// Actions matching the filters.
    pub total: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}