delopay 0.4.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
//! The `disputes` resource: view disputes and respond to chargebacks with
//! evidence.

use std::sync::Arc;

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

use crate::core::encoding::{encode_segment, to_json_vec};
use crate::core::error::{DelopayError, Result};
use crate::core::models::common::{Currency, DisputeStage, DisputeStatus};
use crate::core::models::dispute::DisputeResponse;
use crate::http::client::Inner;
use crate::http::transport::HttpMethod;
use crate::resources::ValidateRequest;

/// The `disputes` resource, obtained via [`crate::Delopay::disputes`].
#[derive(Debug, Clone)]
pub struct Disputes {
    inner: Arc<Inner>,
}

impl Disputes {
    pub(crate) fn new(inner: Arc<Inner>) -> Self {
        Self { inner }
    }

    /// Retrieve a dispute by ID.
    pub async fn retrieve(&self, dispute_id: &str) -> Result<DisputeResponse> {
        let path = format!("/disputes/{}", encode_segment(dispute_id));
        self.inner
            .request(HttpMethod::Get, &path, None, &[], None)
            .await
    }

    /// List disputes, optionally filtered by status, stage, or date range.
    pub async fn list(&self, params: Option<&DisputeListParams>) -> Result<Vec<DisputeResponse>> {
        let query = params.map(DisputeListParams::to_query).unwrap_or_default();
        self.inner
            .request(HttpMethod::Get, "/disputes/list", None, &query, None)
            .await
    }

    /// Accept a dispute (concede the chargeback).
    pub async fn accept(&self, dispute_id: &str) -> Result<DisputeResponse> {
        let path = format!("/disputes/accept/{}", encode_segment(dispute_id));
        self.inner
            .request(HttpMethod::Post, &path, None, &[], None)
            .await
    }

    /// Submit evidence to challenge a dispute.
    pub async fn submit_evidence(
        &self,
        params: &DisputeEvidenceRequest,
    ) -> Result<DisputeResponse> {
        params.validate()?;
        let body = to_json_vec(params)?;
        self.inner
            .request(
                HttpMethod::Post,
                "/disputes/evidence",
                Some(&body),
                &[],
                None,
            )
            .await
    }

    /// Attach evidence (e.g. uploaded-file references) to a dispute.
    pub async fn attach_evidence(
        &self,
        params: &DisputeEvidenceRequest,
    ) -> Result<DisputeResponse> {
        params.validate()?;
        let body = to_json_vec(params)?;
        self.inner
            .request(
                HttpMethod::Put,
                "/disputes/evidence",
                Some(&body),
                &[],
                None,
            )
            .await
    }

    /// Retrieve previously submitted evidence for a dispute.
    pub async fn retrieve_evidence(&self, dispute_id: &str) -> Result<DisputeEvidenceRequest> {
        let path = format!("/disputes/evidence/{}", encode_segment(dispute_id));
        self.inner
            .request(HttpMethod::Get, &path, None, &[], None)
            .await
    }

    /// Delete submitted evidence for a dispute. The body identifies what to
    /// delete, mirroring the submit shape.
    pub async fn delete_evidence(
        &self,
        params: &DisputeEvidenceRequest,
    ) -> Result<DisputeResponse> {
        params.validate()?;
        let body = to_json_vec(params)?;
        self.inner
            .request(
                HttpMethod::Delete,
                "/disputes/evidence",
                Some(&body),
                &[],
                None,
            )
            .await
    }

    /// List disputes scoped to the profile the API key belongs to.
    pub async fn list_by_profile(
        &self,
        params: Option<&DisputeListParams>,
    ) -> Result<Vec<DisputeResponse>> {
        let query = params.map(DisputeListParams::to_query).unwrap_or_default();
        self.inner
            .request(
                HttpMethod::Get,
                "/disputes/profile/list",
                None,
                &query,
                None,
            )
            .await
    }

    /// Retrieve the filter options available for disputes. Query keys are open
    /// — pass `&[]` for none; see the API reference.
    pub async fn filters(&self, query: &[(&str, String)]) -> Result<Value> {
        self.inner
            .request(HttpMethod::Get, "/disputes/filter", None, query, None)
            .await
    }

    /// Retrieve the filter options for disputes, scoped to the profile the API
    /// key belongs to. Query keys are open — see the API reference.
    pub async fn filters_by_profile(&self, query: &[(&str, String)]) -> Result<Value> {
        self.inner
            .request(
                HttpMethod::Get,
                "/disputes/profile/filter",
                None,
                query,
                None,
            )
            .await
    }

    /// Retrieve aggregated dispute statistics. Query keys are open — see the
    /// API reference.
    pub async fn aggregate(&self, query: &[(&str, String)]) -> Result<Value> {
        self.inner
            .request(HttpMethod::Get, "/disputes/aggregate", None, query, None)
            .await
    }

    /// Retrieve aggregated dispute statistics, scoped to the profile the API
    /// key belongs to. Query keys are open — see the API reference.
    pub async fn aggregate_by_profile(&self, query: &[(&str, String)]) -> Result<Value> {
        self.inner
            .request(
                HttpMethod::Get,
                "/disputes/profile/aggregate",
                None,
                query,
                None,
            )
            .await
    }

    /// Fetch the latest dispute state from the connector (gateway).
    ///
    /// The path parameter is the **connector's** dispute ID on the gateway,
    /// not the Delopay dispute ID.
    pub async fn fetch_from_connector(
        &self,
        connector_dispute_id: &str,
    ) -> Result<DisputeResponse> {
        let path = format!("/disputes/{}/fetch", encode_segment(connector_dispute_id));
        self.inner
            .request(HttpMethod::Get, &path, None, &[], None)
            .await
    }
}

/// Filter / pagination parameters for [`Disputes::list`] and
/// [`Disputes::list_by_profile`].
#[derive(Debug, Clone, Default)]
pub struct DisputeListParams {
    /// Maximum number of disputes to return.
    pub limit: Option<i64>,
    /// Number of disputes to skip.
    pub offset: Option<i64>,
    /// Only the dispute with this ID.
    pub dispute_id: Option<String>,
    /// Only disputes raised against this payment.
    pub payment_id: Option<String>,
    /// Only disputes in this shop (business profile).
    pub profile_id: Option<String>,
    /// Only disputes in this status.
    pub dispute_status: Option<DisputeStatus>,
    /// Only disputes at this lifecycle stage.
    pub dispute_stage: Option<DisputeStage>,
    /// Only disputes raised for this reason.
    pub reason: Option<String>,
    /// Only disputes reported by this connector.
    pub connector: Option<String>,
    /// Only disputes in this three-letter ISO 4217 currency.
    pub currency: Option<Currency>,
    /// ISO 8601 creation-time range start (required to time-filter).
    pub start_time: Option<String>,
    /// ISO 8601 creation-time range end; defaults to now.
    pub end_time: Option<String>,
    /// Filter by environment: `true` = test only, `false` = live only, `None`
    /// for all.
    pub test_mode: Option<bool>,
}

impl DisputeListParams {
    fn to_query(&self) -> Vec<(&'static str, String)> {
        let mut q = Vec::new();
        if let Some(v) = self.limit {
            q.push(("limit", v.to_string()));
        }
        if let Some(v) = self.offset {
            q.push(("offset", v.to_string()));
        }
        if let Some(v) = &self.dispute_id {
            q.push(("dispute_id", v.clone()));
        }
        if let Some(v) = &self.payment_id {
            q.push(("payment_id", v.clone()));
        }
        if let Some(v) = &self.profile_id {
            q.push(("profile_id", v.clone()));
        }
        if let Some(v) = &self.dispute_status {
            q.push(("dispute_status", v.clone()));
        }
        if let Some(v) = &self.dispute_stage {
            q.push(("dispute_stage", v.clone()));
        }
        if let Some(v) = &self.reason {
            q.push(("reason", v.clone()));
        }
        if let Some(v) = &self.connector {
            q.push(("connector", v.clone()));
        }
        if let Some(v) = &self.currency {
            q.push(("currency", v.clone()));
        }
        if let Some(v) = &self.start_time {
            q.push(("start_time", v.clone()));
        }
        if let Some(v) = &self.end_time {
            q.push(("end_time", v.clone()));
        }
        if let Some(v) = self.test_mode {
            q.push(("test_mode", v.to_string()));
        }
        q
    }
}

/// Evidence for challenging a dispute, submitted via
/// [`Disputes::submit_evidence`] / [`Disputes::attach_evidence`] and returned
/// by [`Disputes::retrieve_evidence`].
///
/// Every field is optional; file-shaped fields (`receipt`,
/// `shipping_documentation`, …) carry file IDs from the `files` resource.
/// The dispute being contested is identified by a `dispute_id` key — set it
/// through [`extra`](DisputeEvidenceRequest::extra), matching the wire shape.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DisputeEvidenceRequest {
    /// Concede instead of contesting.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cancel_dispute: Option<bool>,
    /// Body of an email exchange with the customer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_email_body: Option<String>,
    /// Customer's email address.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_email_address: Option<String>,
    /// Customer's name.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_name: Option<String>,
    /// File ID of the customer's signature.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_signature: Option<String>,
    /// Description of the product or service sold.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub product_description: Option<String>,
    /// File ID of the receipt.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub receipt: Option<String>,
    /// File ID of the refund policy.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub refund_policy: Option<String>,
    /// How the refund policy was disclosed to the customer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub refund_policy_disclosure: Option<String>,
    /// Why the refund was refused.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub refund_refusal_explanation: Option<String>,
    /// Date the service was provided.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_date: Option<String>,
    /// File ID documenting the service.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_documentation: Option<String>,
    /// Shipping address used.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shipping_address: Option<String>,
    /// Carrier used for shipping.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shipping_carrier: Option<String>,
    /// Date the goods were shipped.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shipping_date: Option<String>,
    /// File ID of the shipping documentation.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shipping_documentation: Option<String>,
    /// Shipment tracking number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shipping_tracking_number: Option<String>,
    /// File ID of any uncategorized evidence.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub uncategorized_file: Option<String>,
    /// Free-text uncategorized evidence.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub uncategorized_text: Option<String>,
    /// Access / activity log evidence.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub access_activity_log: Option<String>,
    /// Billing address used.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub billing_address: Option<String>,
    /// File ID of the cancellation policy.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cancellation_policy: Option<String>,
    /// How the cancellation policy was disclosed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cancellation_policy_disclosure: Option<String>,
    /// Rebuttal to the cancellation claim.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cancellation_rebuttal: Option<String>,
    /// File ID of customer communication.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_communication: Option<String>,
    /// IP address the purchase was made from.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_purchase_ip: Option<String>,
    /// File ID documenting the alleged duplicate charge.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duplicate_charge_documentation: Option<String>,
    /// Explanation of why the charge is not a duplicate.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duplicate_charge_explanation: Option<String>,
    /// Payment ID of the alleged duplicate charge.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duplicate_charge_id: Option<String>,
    /// Any additional fields (e.g. `dispute_id`) are merged in verbatim, and
    /// unknown fields returned by `retrieve_evidence` land here.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Names of `DisputeEvidenceRequest`'s fields as they appear on the wire
/// (`extra` excluded). See `PAYMENT_CREATE_REQUEST_NAMED` in `payments.rs`
/// for why this list lives next to the struct.
const DISPUTE_EVIDENCE_REQUEST_NAMED: &[&str] = &[
    "cancel_dispute",
    "customer_email_body",
    "customer_email_address",
    "customer_name",
    "customer_signature",
    "product_description",
    "receipt",
    "refund_policy",
    "refund_policy_disclosure",
    "refund_refusal_explanation",
    "service_date",
    "service_documentation",
    "shipping_address",
    "shipping_carrier",
    "shipping_date",
    "shipping_documentation",
    "shipping_tracking_number",
    "uncategorized_file",
    "uncategorized_text",
    "access_activity_log",
    "billing_address",
    "cancellation_policy",
    "cancellation_policy_disclosure",
    "cancellation_rebuttal",
    "customer_communication",
    "customer_purchase_ip",
    "duplicate_charge_documentation",
    "duplicate_charge_explanation",
    "duplicate_charge_id",
];

impl ValidateRequest for DisputeEvidenceRequest {
    fn validate(&self) -> Result<()> {
        for key in self.extra.keys() {
            if DISPUTE_EVIDENCE_REQUEST_NAMED.contains(&key.as_str()) {
                return Err(DelopayError::InvalidRequest(format!(
                    "`extra` key `{key}` collides with a named field on DisputeEvidenceRequest"
                )));
            }
        }
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::http::mock::{Step, client_with};
    use serde_json::json;

    const DISPUTE_JSON: &str = r#"{
        "dispute_id": "dp_1", "payment_id": "pay_1", "attempt_id": "att_1",
        "amount": "500", "currency": "EUR", "dispute_stage": "dispute",
        "dispute_status": "dispute_opened", "connector": "stripe",
        "connector_status": "needs_response", "connector_dispute_id": "du_1",
        "is_already_refunded": false
    }"#;

    /// Every optional field populated so serialization emits the full key set.
    fn full_evidence_request() -> DisputeEvidenceRequest {
        let text = |s: &str| Some(s.to_string());
        DisputeEvidenceRequest {
            cancel_dispute: Some(false),
            customer_email_body: text("body"),
            customer_email_address: text("a@example.com"),
            customer_name: text("Ada"),
            customer_signature: text("file_sig"),
            product_description: text("widget"),
            receipt: text("file_receipt"),
            refund_policy: text("file_policy"),
            refund_policy_disclosure: text("shown at checkout"),
            refund_refusal_explanation: text("outside window"),
            service_date: text("2026-01-01"),
            service_documentation: text("file_service"),
            shipping_address: text("Somestr. 1"),
            shipping_carrier: text("DHL"),
            shipping_date: text("2026-01-02"),
            shipping_documentation: text("file_ship"),
            shipping_tracking_number: text("TRACK1"),
            uncategorized_file: text("file_misc"),
            uncategorized_text: text("misc"),
            access_activity_log: text("log"),
            billing_address: text("Somestr. 1"),
            cancellation_policy: text("file_cancel"),
            cancellation_policy_disclosure: text("shown at checkout"),
            cancellation_rebuttal: text("not cancelled"),
            customer_communication: text("file_comm"),
            customer_purchase_ip: text("203.0.113.7"),
            duplicate_charge_documentation: text("file_dup"),
            duplicate_charge_explanation: text("separate orders"),
            duplicate_charge_id: text("pay_2"),
            extra: serde_json::Map::new(),
        }
    }

    /// Drift guard for `DISPUTE_EVIDENCE_REQUEST_NAMED`.
    #[test]
    fn evidence_request_named_fields_are_complete() {
        let value = serde_json::to_value(full_evidence_request()).unwrap();
        let obj = value.as_object().expect("serializes to a JSON object");
        for key in obj.keys() {
            assert!(
                DISPUTE_EVIDENCE_REQUEST_NAMED.contains(&key.as_str()),
                "DISPUTE_EVIDENCE_REQUEST_NAMED is missing wire key `{key}` -- \
                 add it, or the extra-key collision guard silently stops \
                 covering this field"
            );
        }
    }

    #[test]
    fn evidence_validate_rejects_colliding_extra_key() {
        let mut req = DisputeEvidenceRequest::default();
        req.extra.insert("receipt".to_string(), json!("file_x"));
        assert!(matches!(
            req.validate().unwrap_err(),
            DelopayError::InvalidRequest(_)
        ));
    }

    #[test]
    fn evidence_round_trips_with_dispute_id_in_extra() {
        // `retrieve_evidence` deserializes the same struct that submit
        // serializes; the dispute_id travels in `extra` both ways.
        let mut req = DisputeEvidenceRequest {
            receipt: Some("file_receipt".to_string()),
            ..Default::default()
        };
        req.extra.insert("dispute_id".to_string(), json!("dp_1"));

        let wire = serde_json::to_string(&req).unwrap();
        let back: DisputeEvidenceRequest = serde_json::from_str(&wire).unwrap();
        assert_eq!(back.receipt.as_deref(), Some("file_receipt"));
        assert_eq!(back.extra["dispute_id"], "dp_1");
    }

    #[tokio::test]
    async fn submit_uses_post_and_attach_uses_put_on_the_evidence_path() {
        // The submit/attach pair differ ONLY by verb; a mutation collapsing
        // them to the same method must fail here.
        let (client, mock) = client_with(vec![Step::ok(DISPUTE_JSON), Step::ok(DISPUTE_JSON)]);
        let req = DisputeEvidenceRequest {
            receipt: Some("file_receipt".to_string()),
            ..Default::default()
        };
        client.disputes().submit_evidence(&req).await.unwrap();
        client.disputes().attach_evidence(&req).await.unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(
            (seen[0].method, seen[0].url.as_str()),
            ("POST", "https://api.test/disputes/evidence")
        );
        assert_eq!(
            (seen[1].method, seen[1].url.as_str()),
            ("PUT", "https://api.test/disputes/evidence")
        );
        assert_eq!(seen[1].body_json()["receipt"], "file_receipt");
    }

    #[tokio::test]
    async fn delete_evidence_sends_a_delete_with_a_body() {
        let (client, mock) = client_with(vec![Step::ok(DISPUTE_JSON)]);
        let mut req = DisputeEvidenceRequest::default();
        req.extra.insert("dispute_id".to_string(), json!("dp_1"));
        client.disputes().delete_evidence(&req).await.unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(seen[0].method, "DELETE");
        assert_eq!(seen[0].url, "https://api.test/disputes/evidence");
        assert_eq!(
            seen[0].body_json()["dispute_id"],
            "dp_1",
            "DELETE must still carry the identifying body"
        );
    }

    #[tokio::test]
    async fn list_and_list_by_profile_serialize_the_same_filters() {
        // The two calls differ ONLY by path; a mutation pointing one at the
        // other's URL must fail here.
        let (client, mock) = client_with(vec![Step::ok("[]"), Step::ok("[]")]);
        let params = DisputeListParams {
            limit: Some(10),
            dispute_status: Some("dispute_opened".to_string()),
            test_mode: Some(true),
            ..Default::default()
        };
        client.disputes().list(Some(&params)).await.unwrap();
        client
            .disputes()
            .list_by_profile(Some(&params))
            .await
            .unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(
            (seen[0].method, seen[0].url.as_str()),
            (
                "GET",
                "https://api.test/disputes/list?limit=10&dispute_status=dispute_opened&test_mode=true"
            )
        );
        assert_eq!(
            (seen[1].method, seen[1].url.as_str()),
            (
                "GET",
                "https://api.test/disputes/profile/list?limit=10&dispute_status=dispute_opened&test_mode=true"
            )
        );
    }

    #[tokio::test]
    async fn list_without_params_sends_no_query() {
        let (client, mock) = client_with(vec![Step::ok("[]")]);
        client.disputes().list(None).await.unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(seen[0].url, "https://api.test/disputes/list");
    }

    #[tokio::test]
    async fn filter_and_aggregate_paths_are_distinct() {
        let (client, mock) = client_with(vec![
            Step::ok("{}"),
            Step::ok("{}"),
            Step::ok("{}"),
            Step::ok("{}"),
        ]);
        let query = [("start_time", "2026-01-01T00:00:00Z".to_string())];
        client.disputes().filters(&[]).await.unwrap();
        client.disputes().filters_by_profile(&[]).await.unwrap();
        client.disputes().aggregate(&query).await.unwrap();
        client
            .disputes()
            .aggregate_by_profile(&query)
            .await
            .unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(
            (seen[0].method, seen[0].url.as_str()),
            ("GET", "https://api.test/disputes/filter")
        );
        assert_eq!(
            (seen[1].method, seen[1].url.as_str()),
            ("GET", "https://api.test/disputes/profile/filter")
        );
        assert_eq!(
            (seen[2].method, seen[2].url.as_str()),
            (
                "GET",
                "https://api.test/disputes/aggregate?start_time=2026-01-01T00:00:00Z"
            )
        );
        assert_eq!(
            (seen[3].method, seen[3].url.as_str()),
            (
                "GET",
                "https://api.test/disputes/profile/aggregate?start_time=2026-01-01T00:00:00Z"
            )
        );
    }

    #[tokio::test]
    async fn retrieve_evidence_and_connector_fetch_hit_their_paths() {
        let (client, mock) = client_with(vec![
            Step::ok(r#"{"receipt":"file_receipt","dispute_id":"dp_1"}"#),
            Step::ok(DISPUTE_JSON),
        ]);
        let evidence = client.disputes().retrieve_evidence("dp_1").await.unwrap();
        assert_eq!(evidence.receipt.as_deref(), Some("file_receipt"));
        client
            .disputes()
            .fetch_from_connector("du_1")
            .await
            .unwrap();

        let seen = mock.seen.lock().unwrap();
        assert_eq!(
            (seen[0].method, seen[0].url.as_str()),
            ("GET", "https://api.test/disputes/evidence/dp_1")
        );
        assert_eq!(
            (seen[1].method, seen[1].url.as_str()),
            ("GET", "https://api.test/disputes/du_1/fetch")
        );
    }
}