stripe/resources/generated/
dispute.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{ChargeId, DisputeId, PaymentIntentId};
7use crate::params::{Expand, Expandable, List, Metadata, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::{BalanceTransaction, Charge, Currency, File, PaymentIntent};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "Dispute".
12///
13/// For more details see <https://stripe.com/docs/api/disputes/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Dispute {
16    /// Unique identifier for the object.
17    pub id: DisputeId,
18
19    /// Disputed amount.
20    ///
21    /// Usually the amount of the charge, but it can differ (usually because of currency fluctuation or because only part of the order is disputed).
22    pub amount: i64,
23
24    /// List of zero, one, or two balance transactions that show funds withdrawn and reinstated to your Stripe account as a result of this dispute.
25    pub balance_transactions: Vec<BalanceTransaction>,
26
27    /// ID of the charge that's disputed.
28    pub charge: Expandable<Charge>,
29
30    /// Time at which the object was created.
31    ///
32    /// Measured in seconds since the Unix epoch.
33    pub created: Timestamp,
34
35    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
36    ///
37    /// Must be a [supported currency](https://stripe.com/docs/currencies).
38    pub currency: Currency,
39
40    pub evidence: DisputeEvidence,
41
42    pub evidence_details: DisputeEvidenceDetails,
43
44    /// If true, it's still possible to refund the disputed payment.
45    ///
46    /// After the payment has been fully refunded, no further funds are withdrawn from your Stripe account as a result of this dispute.
47    pub is_charge_refundable: bool,
48
49    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
50    pub livemode: bool,
51
52    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
53    ///
54    /// This can be useful for storing additional information about the object in a structured format.
55    pub metadata: Metadata,
56
57    /// Network-dependent reason code for the dispute.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub network_reason_code: Option<String>,
60
61    /// ID of the PaymentIntent that's disputed.
62    pub payment_intent: Option<Expandable<PaymentIntent>>,
63
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub payment_method_details: Option<DisputePaymentMethodDetails>,
66
67    /// Reason given by cardholder for dispute.
68    ///
69    /// Possible values are `bank_cannot_process`, `check_returned`, `credit_not_processed`, `customer_initiated`, `debit_not_authorized`, `duplicate`, `fraudulent`, `general`, `incorrect_account_details`, `insufficient_funds`, `product_not_received`, `product_unacceptable`, `subscription_canceled`, or `unrecognized`.
70    /// Learn more about [dispute reasons](https://stripe.com/docs/disputes/categories).
71    pub reason: String,
72
73    /// Current status of dispute.
74    ///
75    /// Possible values are `warning_needs_response`, `warning_under_review`, `warning_closed`, `needs_response`, `under_review`, `won`, or `lost`.
76    pub status: DisputeStatus,
77}
78
79impl Dispute {
80    /// Returns a list of your disputes.
81    pub fn list(client: &Client, params: &ListDisputes<'_>) -> Response<List<Dispute>> {
82        client.get_query("/disputes", params)
83    }
84
85    /// Retrieves the dispute with the given ID.
86    pub fn retrieve(client: &Client, id: &DisputeId, expand: &[&str]) -> Response<Dispute> {
87        client.get_query(&format!("/disputes/{}", id), Expand { expand })
88    }
89}
90
91impl Object for Dispute {
92    type Id = DisputeId;
93    fn id(&self) -> Self::Id {
94        self.id.clone()
95    }
96    fn object(&self) -> &'static str {
97        "dispute"
98    }
99}
100
101#[derive(Clone, Debug, Default, Deserialize, Serialize)]
102pub struct DisputeEvidence {
103    /// Any server or activity logs showing proof that the customer accessed or downloaded the purchased digital product.
104    ///
105    /// This information should include IP addresses, corresponding timestamps, and any detailed recorded activity.
106    pub access_activity_log: Option<String>,
107
108    /// The billing address provided by the customer.
109    pub billing_address: Option<String>,
110
111    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Your subscription cancellation policy, as shown to the customer.
112    pub cancellation_policy: Option<Expandable<File>>,
113
114    /// An explanation of how and when the customer was shown your refund policy prior to purchase.
115    pub cancellation_policy_disclosure: Option<String>,
116
117    /// A justification for why the customer's subscription was not canceled.
118    pub cancellation_rebuttal: Option<String>,
119
120    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Any communication with the customer that you feel is relevant to your case.
121    ///
122    /// Examples include emails proving that the customer received the product or service, or demonstrating their use of or satisfaction with the product or service.
123    pub customer_communication: Option<Expandable<File>>,
124
125    /// The email address of the customer.
126    pub customer_email_address: Option<String>,
127
128    /// The name of the customer.
129    pub customer_name: Option<String>,
130
131    /// The IP address that the customer used when making the purchase.
132    pub customer_purchase_ip: Option<String>,
133
134    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) A relevant document or contract showing the customer's signature.
135    pub customer_signature: Option<Expandable<File>>,
136
137    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Documentation for the prior charge that can uniquely identify the charge, such as a receipt, shipping label, work order, etc.
138    ///
139    /// This document should be paired with a similar document from the disputed payment that proves the two payments are separate.
140    pub duplicate_charge_documentation: Option<Expandable<File>>,
141
142    /// An explanation of the difference between the disputed charge versus the prior charge that appears to be a duplicate.
143    pub duplicate_charge_explanation: Option<String>,
144
145    /// The Stripe ID for the prior charge which appears to be a duplicate of the disputed charge.
146    pub duplicate_charge_id: Option<String>,
147
148    /// A description of the product or service that was sold.
149    pub product_description: Option<String>,
150
151    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Any receipt or message sent to the customer notifying them of the charge.
152    pub receipt: Option<Expandable<File>>,
153
154    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Your refund policy, as shown to the customer.
155    pub refund_policy: Option<Expandable<File>>,
156
157    /// Documentation demonstrating that the customer was shown your refund policy prior to purchase.
158    pub refund_policy_disclosure: Option<String>,
159
160    /// A justification for why the customer is not entitled to a refund.
161    pub refund_refusal_explanation: Option<String>,
162
163    /// The date on which the customer received or began receiving the purchased service, in a clear human-readable format.
164    pub service_date: Option<String>,
165
166    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Documentation showing proof that a service was provided to the customer.
167    ///
168    /// This could include a copy of a signed contract, work order, or other form of written agreement.
169    pub service_documentation: Option<Expandable<File>>,
170
171    /// The address to which a physical product was shipped.
172    ///
173    /// You should try to include as complete address information as possible.
174    pub shipping_address: Option<String>,
175
176    /// The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc.
177    ///
178    /// If multiple carriers were used for this purchase, please separate them with commas.
179    pub shipping_carrier: Option<String>,
180
181    /// The date on which a physical product began its route to the shipping address, in a clear human-readable format.
182    pub shipping_date: Option<String>,
183
184    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Documentation showing proof that a product was shipped to the customer at the same address the customer provided to you.
185    ///
186    /// This could include a copy of the shipment receipt, shipping label, etc.
187    /// It should show the customer's full shipping address, if possible.
188    pub shipping_documentation: Option<Expandable<File>>,
189
190    /// The tracking number for a physical product, obtained from the delivery service.
191    ///
192    /// If multiple tracking numbers were generated for this purchase, please separate them with commas.
193    pub shipping_tracking_number: Option<String>,
194
195    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Any additional evidence or statements.
196    pub uncategorized_file: Option<Expandable<File>>,
197
198    /// Any additional evidence or statements.
199    pub uncategorized_text: Option<String>,
200}
201
202#[derive(Clone, Debug, Default, Deserialize, Serialize)]
203pub struct DisputeEvidenceDetails {
204    /// Date by which evidence must be submitted in order to successfully challenge dispute.
205    ///
206    /// Will be 0 if the customer's bank or credit card company doesn't allow a response for this particular dispute.
207    pub due_by: Option<Timestamp>,
208
209    /// Whether evidence has been staged for this dispute.
210    pub has_evidence: bool,
211
212    /// Whether the last evidence submission was submitted past the due date.
213    ///
214    /// Defaults to `false` if no evidence submissions have occurred.
215    /// If `true`, then delivery of the latest evidence is *not* guaranteed.
216    pub past_due: bool,
217
218    /// The number of times evidence has been submitted.
219    ///
220    /// Typically, you may only submit evidence once.
221    pub submission_count: u64,
222}
223
224#[derive(Clone, Debug, Default, Deserialize, Serialize)]
225pub struct DisputePaymentMethodDetails {
226    /// Card specific dispute details.
227    pub card: Option<DisputePaymentMethodDetailsCard>,
228
229    /// Payment method type.
230    #[serde(rename = "type")]
231    pub type_: DisputePaymentMethodDetailsType,
232}
233
234#[derive(Clone, Debug, Default, Deserialize, Serialize)]
235pub struct DisputePaymentMethodDetailsCard {
236    /// Card brand.
237    ///
238    /// Can be `amex`, `diners`, `discover`, `eftpos_au`, `jcb`, `mastercard`, `unionpay`, `visa`, or `unknown`.
239    pub brand: String,
240
241    /// The card network's specific dispute reason code, which maps to one of Stripe's primary dispute categories to simplify response guidance.
242    ///
243    /// The [Network code map](https://stripe.com/docs/disputes/categories#network-code-map) lists all available dispute reason codes by network.
244    pub network_reason_code: Option<String>,
245}
246
247/// The parameters for `Dispute::list`.
248#[derive(Clone, Debug, Serialize, Default)]
249pub struct ListDisputes<'a> {
250    /// Only return disputes associated to the charge specified by this charge ID.
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub charge: Option<ChargeId>,
253
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub created: Option<RangeQuery<Timestamp>>,
256
257    /// A cursor for use in pagination.
258    ///
259    /// `ending_before` is an object ID that defines your place in the list.
260    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
261    #[serde(skip_serializing_if = "Option::is_none")]
262    pub ending_before: Option<DisputeId>,
263
264    /// Specifies which fields in the response should be expanded.
265    #[serde(skip_serializing_if = "Expand::is_empty")]
266    pub expand: &'a [&'a str],
267
268    /// A limit on the number of objects to be returned.
269    ///
270    /// Limit can range between 1 and 100, and the default is 10.
271    #[serde(skip_serializing_if = "Option::is_none")]
272    pub limit: Option<u64>,
273
274    /// Only return disputes associated to the PaymentIntent specified by this PaymentIntent ID.
275    #[serde(skip_serializing_if = "Option::is_none")]
276    pub payment_intent: Option<PaymentIntentId>,
277
278    /// A cursor for use in pagination.
279    ///
280    /// `starting_after` is an object ID that defines your place in the list.
281    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
282    #[serde(skip_serializing_if = "Option::is_none")]
283    pub starting_after: Option<DisputeId>,
284}
285
286impl<'a> ListDisputes<'a> {
287    pub fn new() -> Self {
288        ListDisputes {
289            charge: Default::default(),
290            created: Default::default(),
291            ending_before: Default::default(),
292            expand: Default::default(),
293            limit: Default::default(),
294            payment_intent: Default::default(),
295            starting_after: Default::default(),
296        }
297    }
298}
299impl Paginable for ListDisputes<'_> {
300    type O = Dispute;
301    fn set_last(&mut self, item: Self::O) {
302        self.starting_after = Some(item.id());
303    }
304}
305/// An enum representing the possible values of an `DisputePaymentMethodDetails`'s `type` field.
306#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
307#[serde(rename_all = "snake_case")]
308pub enum DisputePaymentMethodDetailsType {
309    Card,
310}
311
312impl DisputePaymentMethodDetailsType {
313    pub fn as_str(self) -> &'static str {
314        match self {
315            DisputePaymentMethodDetailsType::Card => "card",
316        }
317    }
318}
319
320impl AsRef<str> for DisputePaymentMethodDetailsType {
321    fn as_ref(&self) -> &str {
322        self.as_str()
323    }
324}
325
326impl std::fmt::Display for DisputePaymentMethodDetailsType {
327    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
328        self.as_str().fmt(f)
329    }
330}
331impl std::default::Default for DisputePaymentMethodDetailsType {
332    fn default() -> Self {
333        Self::Card
334    }
335}
336
337/// An enum representing the possible values of an `Dispute`'s `status` field.
338#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
339#[serde(rename_all = "snake_case")]
340pub enum DisputeStatus {
341    Lost,
342    NeedsResponse,
343    UnderReview,
344    WarningClosed,
345    WarningNeedsResponse,
346    WarningUnderReview,
347    Won,
348}
349
350impl DisputeStatus {
351    pub fn as_str(self) -> &'static str {
352        match self {
353            DisputeStatus::Lost => "lost",
354            DisputeStatus::NeedsResponse => "needs_response",
355            DisputeStatus::UnderReview => "under_review",
356            DisputeStatus::WarningClosed => "warning_closed",
357            DisputeStatus::WarningNeedsResponse => "warning_needs_response",
358            DisputeStatus::WarningUnderReview => "warning_under_review",
359            DisputeStatus::Won => "won",
360        }
361    }
362}
363
364impl AsRef<str> for DisputeStatus {
365    fn as_ref(&self) -> &str {
366        self.as_str()
367    }
368}
369
370impl std::fmt::Display for DisputeStatus {
371    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
372        self.as_str().fmt(f)
373    }
374}
375impl std::default::Default for DisputeStatus {
376    fn default() -> Self {
377        Self::Lost
378    }
379}