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
//! PayPal seller case models.
//!
//! A *seller case* is PayPal's own dispute record, which exists for sales this
//! platform never processed — external and subscription sales included — so it
//! is kept apart from [`DisputeResponse`](crate::core::models::dispute::DisputeResponse),
//! the processor-agnostic dispute raised against a DeloPay payment.
//!
//! Money arrives as a decimal **string** in the case's own currency, exactly as
//! PayPal reports it: parsing it into a float here would round a figure a
//! seller is about to argue about.
use serde::Deserialize;
use serde_json::Value;
/// A seller action PayPal offers on a case.
///
/// `"send_message"`, `"make_offer"`, `"accept_claim"`, `"provide_evidence"`,
/// `"appeal"`, `"escalate"`, `"acknowledge_return_item"`,
/// `"provide_supporting_info"` and `"update_communication"`.
///
/// Read the case's [`available_actions`](PaypalDisputeCase::available_actions)
/// rather than assuming: which actions exist depends on the case's stage, and
/// PayPal withdraws them as it moves.
pub type PaypalDisputeAction = String;
/// One PayPal seller case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeCase {
/// PayPal's case id.
pub case_id: String,
/// The dispute id as the connector reports it.
#[serde(default)]
pub connector_dispute_id: Option<String>,
/// The connector account the case was read with.
#[serde(default)]
pub merchant_connector_id: Option<String>,
/// The shop the case maps to, when it maps to one.
#[serde(default)]
pub profile_id: Option<String>,
/// The DeloPay payment the case maps to. `None` for a sale this platform
/// never processed — an external or subscription sale — which is the
/// reason these cases have their own surface.
#[serde(default)]
pub payment_id: Option<String>,
/// The payment attempt the case maps to.
#[serde(default)]
pub attempt_id: Option<String>,
/// PayPal's invoice id for the sale, when it carries one.
#[serde(default)]
pub invoice_id: Option<String>,
/// The PayPal seller account the case belongs to.
#[serde(default)]
pub seller_id: Option<String>,
/// PayPal transaction ids the case covers.
#[serde(default = "Vec::new")]
pub transaction_ids: Vec<String>,
/// Which environment the case was read from.
#[serde(default)]
pub test_mode: Option<bool>,
/// PayPal's own status for the case, verbatim.
#[serde(default)]
pub status: Option<String>,
/// PayPal's own stage for the case, verbatim.
#[serde(default)]
pub stage: Option<String>,
/// The buyer's stated reason.
#[serde(default)]
pub reason: Option<String>,
/// PayPal's code for that reason.
#[serde(default)]
pub reason_code: Option<String>,
/// The disputed amount, as a decimal string in
/// [`currency`](Self::currency).
#[serde(default)]
pub amount: Option<String>,
/// Three-letter ISO 4217 currency of [`amount`](Self::amount).
#[serde(default)]
pub currency: Option<String>,
/// When the seller must answer by (RFC 3339). **The deadline that costs
/// money**: past it PayPal decides without the seller.
#[serde(default)]
pub seller_response_due_date: Option<String>,
/// When the buyer must answer by (RFC 3339).
#[serde(default)]
pub buyer_response_due_date: Option<String>,
/// When PayPal opened the case (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// When this record was last refreshed from PayPal (RFC 3339).
#[serde(default)]
pub updated_at: Option<String>,
/// How the case ended, once it has.
#[serde(default)]
pub outcome: Option<String>,
/// The actions PayPal currently offers on this case. An action absent here
/// is refused, so drive the buttons from this list rather than from the
/// stage.
#[serde(default = "Vec::new")]
pub available_actions: Vec<PaypalDisputeAction>,
/// How many PayPal webhooks have been delivered for the case.
#[serde(default)]
pub webhook_delivery_count: Option<i64>,
/// The provider event this record was last written from.
#[serde(default)]
pub provider_event_id: Option<String>,
/// PayPal's full case document, verbatim.
#[serde(default)]
pub details: Option<Value>,
/// Who opened the case: `"payment_provider"`, `"bank_card_issuer"` or
/// `"unknown"`. `None` on older records.
#[serde(default)]
pub origin: Option<String>,
/// What kind of case it is: `"inquiry"`, `"dispute"`,
/// `"bank_chargeback"`, `"pre_chargeback_alert"` or `"unknown"`. `None`
/// on older records.
#[serde(default)]
pub category: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A page of cases imported from PayPal.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeImportResponse {
/// The cases this page imported.
#[serde(default = "Vec::new")]
pub cases: Vec<PaypalDisputeCase>,
/// The token for the next page. `None` means the import is complete —
/// stop, rather than re-sending the last token.
#[serde(default)]
pub next_page_token: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What a seller action did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeActionResponse {
/// The request id the action was deduplicated on.
#[serde(default)]
pub request_id: Option<String>,
/// What PayPal answered.
///
/// An **unknown** outcome means the action's effect could not be
/// established: reconcile the case — re-read it with a forced sync — rather
/// than sending the action again under a new request id, which is how a
/// case ends up conceded twice.
#[serde(default)]
pub outcome: Option<String>,
/// The case as it stands after the action.
#[serde(default)]
pub case: Option<PaypalDisputeCase>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One action already taken on a case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeActionRecord {
/// The request id the action was sent under.
#[serde(default)]
pub request_id: Option<String>,
/// Which action it was.
#[serde(default)]
pub action: Option<String>,
/// What PayPal answered.
#[serde(default)]
pub outcome: Option<String>,
/// Who sent it, when the record names an actor.
#[serde(default)]
pub actor: Option<String>,
/// When it was sent (RFC 3339).
#[serde(default)]
pub created_at: Option<String>,
/// The request body as it was sent.
#[serde(default)]
pub request: Option<Value>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A document attached to, or downloaded from, a case.
///
/// The bytes travel base64-encoded in [`data_base64`](Self::data_base64), so a
/// caller that wants the file must decode it. Evidence can be large: keep it
/// out of logs.
#[derive(Debug, Clone, Deserialize, serde::Serialize)]
pub struct PaypalDisputeDocument {
/// File name, as PayPal knows it.
pub name: String,
/// The file's media type.
pub content_type: String,
/// The file's bytes, base64-encoded.
pub data_base64: String,
}