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
//! The buyer account: a buyer signs in with their email address and sees
//! their purchases across shops.
//!
//! Enumerated values arrive as strings, so a value added later does not break
//! decoding. `Debug` on a session prints neither its token nor the address it
//! was opened for, and `Debug` on an opened portal prints no URL, which
//! carries the portal grant.
use std::fmt;
use serde::Deserialize;
use serde_json::Value;
use crate::core::models::buyer_portal::BuyerPortalPurchaseLine;
/// Whether buyers can sign in on this platform, and how.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountAvailability {
/// Whether sign-in is offered.
pub enabled: bool,
/// The methods offered: `code`, `magic_link`, `password`, `oauth`.
#[serde(default)]
pub methods: Vec<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What a started sign-in mailed.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountSignInResponse {
/// What the message carries: `code`, `magic_link` or both.
#[serde(default)]
pub methods: Vec<String>,
/// How long the code or link stays valid, in seconds.
pub expires_in_seconds: i32,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A signed-in buyer. Send `token` as the `api-key` header of buyer account
/// requests: build a separate client with it as the key.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountSession {
/// The session token.
pub token: String,
/// When the session stops working, in Unix seconds.
pub expires_at: i64,
/// The address signed in with, masked, such as `j***@example.com`.
pub email: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerAccountSession {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BuyerAccountSession")
.field("token", &"<redacted>")
.field("expires_at", &self.expires_at)
.field("email", &"<redacted>")
.finish_non_exhaustive()
}
}
/// The current session.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountSessionInfo {
/// The address signed in with, masked.
pub email: String,
/// When the session expires, in Unix seconds.
pub expires_at: i64,
/// Whether the buyer has set a password.
#[serde(default)]
pub has_password: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerAccountSessionInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BuyerAccountSessionInfo")
.field("email", &"<redacted>")
.field("expires_at", &self.expires_at)
.field("has_password", &self.has_password)
.finish_non_exhaustive()
}
}
/// What the buyer is mailed about, at every shop.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerNoticeSettings {
/// A reply from a shop's team the buyer has not read.
pub replies: bool,
/// News in the buyer's refund requests and disputes.
pub case_updates: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One purchase, as a receipt.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountPurchase {
/// Purchase id.
pub id: String,
/// The record it belongs to.
pub record: String,
/// The kind of purchase.
pub kind: String,
/// Its status.
pub status: String,
/// Amount, in minor units.
pub amount: i64,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// When it was made.
pub created_at: String,
/// The shop.
pub shop: String,
/// The shop's name.
pub shop_name: String,
/// The lines.
#[serde(default)]
pub lines: Vec<BuyerPortalPurchaseLine>,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// Whether the buyer has confirmed its record.
pub confirmed: bool,
/// Whether the buyer can confirm its record.
#[serde(default)]
pub confirmable: bool,
/// Refunded so far, in minor units.
#[serde(default)]
pub refunded_amount: Option<i64>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the buyer's purchases, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountPurchasePage {
/// The purchases.
#[serde(default)]
pub data: Vec<BuyerAccountPurchase>,
/// Pass as `cursor` for the next page.
#[serde(default)]
pub next_cursor: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A shop the buyer has purchases at.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountShop {
/// The shop, as `shop` filters name it.
pub shop: String,
/// The shop's name.
pub name: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The shops the buyer has purchases at.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountShopList {
/// The shops.
#[serde(default)]
pub data: Vec<BuyerAccountShop>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One of the buyer's subscriptions.
///
/// A record the buyer has not confirmed shows what a receipt carries, without
/// its period or cancellation.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountSubscription {
/// Subscription id.
pub id: String,
/// The record it belongs to.
pub record: String,
/// The shop.
pub shop: String,
/// The shop's name.
pub shop_name: String,
/// Its status.
pub status: String,
/// The plan's name.
#[serde(default)]
pub name: Option<String>,
/// Amount per cycle, in minor units.
#[serde(default)]
pub amount: Option<i64>,
/// ISO 4217 currency of `amount`.
#[serde(default)]
pub currency: Option<String>,
/// Billing interval, e.g. `month`.
#[serde(default)]
pub billing_interval: Option<String>,
/// Intervals per billing cycle.
#[serde(default)]
pub billing_interval_count: Option<i32>,
/// When it started.
pub created_at: String,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// Whether the buyer has confirmed its record.
pub confirmed: bool,
/// When the current period ends. Confirmed records only.
#[serde(default)]
pub current_period_end: Option<String>,
/// Whether it ends with the current period. Confirmed records only.
#[serde(default)]
pub cancel_at_period_end: Option<bool>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the buyer's subscriptions, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountSubscriptionList {
/// The subscriptions.
#[serde(default)]
pub data: Vec<BuyerAccountSubscription>,
/// Whether more follow.
#[serde(default)]
pub has_more: bool,
/// Pass as `cursor` for the next page, with the same shop and mode.
#[serde(default)]
pub next_cursor: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// An issued invoice of a confirmed record.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountInvoice {
/// Invoice id.
pub id: String,
/// The record it belongs to.
pub record: String,
/// The shop.
pub shop: String,
/// The shop's name.
pub shop_name: String,
/// The printed number.
#[serde(default)]
pub document_number: Option<String>,
/// `invoice` or `credit_note`.
pub kind: String,
/// `draft`, `issued` or `voided`.
pub status: String,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// Gross total, in minor units.
pub gross_amount: i64,
/// Paid so far, in minor units.
#[serde(default)]
pub paid_amount: Option<i64>,
/// Date of supply.
pub supply_date: String,
/// When payment is due.
#[serde(default)]
pub due_date: Option<String>,
/// Start of the billed period.
#[serde(default)]
pub period_start: Option<String>,
/// End of the billed period.
#[serde(default)]
pub period_end: Option<String>,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the confirmed records' invoices, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountInvoiceList {
/// The invoices.
#[serde(default)]
pub data: Vec<BuyerAccountInvoice>,
/// Whether more follow.
#[serde(default)]
pub has_more: bool,
/// Pass as `cursor` for the next page, with the same shop and mode.
#[serde(default)]
pub next_cursor: Option<String>,
/// Whether records the buyer has not confirmed were left out.
#[serde(default)]
pub unconfirmed_records: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A refund request of a confirmed record, with the shop's decision.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountRefundRequest {
/// Request id.
pub id: String,
/// The record it belongs to.
pub record: String,
/// The shop.
pub shop: String,
/// The shop's name.
pub shop_name: String,
/// The purchase it is about.
pub purchase: String,
/// The kind of that purchase.
pub purchase_kind: String,
/// `not_received`, `not_as_described`, `duplicate`, `cancelled_order` or
/// `other`.
pub reason: String,
/// What went wrong, in the buyer's words.
pub message: String,
/// The amount asked for, in minor units.
pub amount: i64,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// `requested`, `approved` or `declined`.
pub status: String,
/// The amount the shop approved, in minor units.
#[serde(default)]
pub approved_amount: Option<i64>,
/// The shop's reply.
#[serde(default)]
pub merchant_reply: Option<String>,
/// When it was sent.
pub created_at: String,
/// When the shop decided.
#[serde(default)]
pub decided_at: Option<String>,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the confirmed records' refund requests, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountRefundRequestList {
/// The requests.
#[serde(default)]
pub data: Vec<BuyerAccountRefundRequest>,
/// Whether more follow.
#[serde(default)]
pub has_more: bool,
/// Pass as `cursor` for the next page, with the same shop and mode.
#[serde(default)]
pub next_cursor: Option<String>,
/// Whether records the buyer has not confirmed were left out.
#[serde(default)]
pub unconfirmed_records: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A record confirmed for the signed-in buyer.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountConfirmation {
/// The record, as its purchases carry it.
pub record: String,
/// When it was confirmed, in Unix seconds.
pub confirmed_at: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The shop's customer portal, opened for a confirmed record.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerAccountPortal {
/// Opens the shop's portal signed in, so treat it as a credential.
/// Opening another one for the same record ends this one.
pub url: String,
/// When the portal session stops working, in Unix seconds.
pub expires_at: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerAccountPortal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BuyerAccountPortal")
.field("url", &"<redacted>")
.field("expires_at", &self.expires_at)
.finish_non_exhaustive()
}
}