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
//! Checkout-method models: a shop's payment-method layout for the hosted
//! checkout, what a buyer is offered from it, and what DeloPay confirms
//! beneath each item.

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

/// A shop's checkout layout and every item it may place, for one environment.
///
/// `layout` is kept as raw JSON so it round-trips unchanged into
/// `CheckoutMethodsUpdateRequest`: read it, change it, send it back.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodsResponse {
    /// The shop (business profile).
    pub profile_id: String,
    /// `stored` when the shop saved a layout, `derived` when the layout is
    /// derived from the shop's connector accounts.
    pub source: String,
    /// The layout: the `express` rows, the `normal` list, the `alternative`
    /// ("other payment methods") list and each item's overrides.
    pub layout: Value,
    /// Every item this shop may place, placed or not, including what only its
    /// switched-off accounts offer (`account_enabled: false`).
    #[serde(default)]
    pub available: Vec<AvailableCheckoutMethod>,
    /// Every method this shop may place as a `general` item.
    #[serde(default)]
    pub general: Vec<Value>,
    /// ISO 8601 time of the last save; absent on a derived layout.
    #[serde(default)]
    pub modified_at: Option<String>,
    /// Whether this is the shop's Test checkout (used by payments created
    /// with `test_mode: true`) rather than its Live one.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Test only: the shop has no Test layout of its own yet, so this is
    /// Live's. The first Test save gives Test its own copy.
    #[serde(default)]
    pub follows_live: Option<bool>,
    /// The connector accounts hidden from this environment's checkout.
    #[serde(default)]
    pub hidden_accounts: Vec<String>,
    /// Present when the caller may change only some payment methods: their
    /// method keys. A change to another item is refused with 403 `IR_22`.
    #[serde(default)]
    pub editable_methods: Option<Vec<String>>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One item a shop may place in its checkout layout.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AvailableCheckoutMethod {
    /// What the item is, e.g. `card`, `method`, `general`.
    pub kind: String,
    /// The connector offering it, for a `method` item.
    #[serde(default)]
    pub connector: Option<String>,
    /// The connector's display name.
    #[serde(default)]
    pub connector_display_name: Option<String>,
    /// The connector's catalogue key for the method.
    #[serde(default)]
    pub method: Option<String>,
    /// The label shown when the layout sets none.
    #[serde(default)]
    pub default_label: Option<String>,
    /// The section the item goes in when the layout sets none.
    pub default_category: String,
    /// Whether the item draws its own button (required in the express strip).
    pub supports_native_element: bool,
    /// Whether the item can open in a new tab or a pop-up.
    pub supports_open_target: bool,
    /// `false` when only switched-off or hidden accounts offer it.
    #[serde(default)]
    pub account_enabled: Option<bool>,
    /// Any additional response fields not modeled above (accounts, coverage,
    /// provider limits, presets and the rest).
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Answer of a checkout-methods reset: the stored layout of one environment
/// was deleted.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodsResetResponse {
    /// The shop (business profile).
    pub profile_id: String,
    /// Whether a stored layout was deleted.
    pub deleted: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Where a connector account is hidden after a visibility change.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutAccountVisibilityResponse {
    /// The connector account.
    pub merchant_connector_id: String,
    /// Hidden from the Live checkout.
    pub hidden_live: bool,
    /// Hidden from the Test checkout.
    pub hidden_test: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// For one buyer (country, amount, currency): which placeable items they are
/// offered and every reason they are not.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodsAvailabilityResponse {
    /// The shop (business profile).
    pub profile_id: String,
    /// The buyer's country, ISO 3166-1 alpha-2.
    pub country: String,
    /// The order value, in minor units of `currency`.
    pub amount: i64,
    /// ISO 4217 currency code.
    pub currency: String,
    /// Whether DeloPay's country defaults apply on this deployment. When
    /// `false`, no item is hidden by `country_default`.
    pub country_defaults_enabled: bool,
    /// One entry per item an enabled account of the shop offers.
    #[serde(default)]
    pub items: Vec<CheckoutMethodAvailability>,
    /// How each smart block of the layout evaluates for this buyer, in
    /// layout order.
    #[serde(default)]
    pub smart_blocks: Vec<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Whether one placeable item reaches the buyer asked about.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodAvailability {
    /// What the item is, e.g. `card`, `method`, `general`.
    pub kind: String,
    /// The connector offering it, for a `method` item.
    #[serde(default)]
    pub connector: Option<String>,
    /// The connector's catalogue key for the method.
    #[serde(default)]
    pub method: Option<String>,
    /// Every reason the item is not offered, in the order the checkout
    /// applies them. Empty when the buyer is offered it.
    #[serde(default)]
    pub hidden_by: Vec<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What DeloPay confirms beneath each item the shop can place: card networks,
/// and the methods or coins a provider's page offers.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodsChildrenResponse {
    /// The shop (business profile).
    pub profile_id: String,
    /// Whether these are the Test checkout's answers.
    pub test_mode: bool,
    /// The buyer country the answers are for, when one was given.
    #[serde(default)]
    pub country: Option<String>,
    /// The order currency the answers are for, when one was given.
    #[serde(default)]
    pub currency: Option<String>,
    /// The order value the answers are for, in minor units of `currency`.
    #[serde(default)]
    pub amount: Option<i64>,
    /// One entry per placeable item (per account, for a `method` item).
    #[serde(default)]
    pub items: Vec<CheckoutMethodChildrenItem>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What DeloPay confirms beneath one placeable item.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodChildrenItem {
    /// What the item is, e.g. `card`, `method`, `general`.
    pub kind: String,
    /// `method` items: the connector.
    #[serde(default)]
    pub connector: Option<String>,
    /// `method` items: the connector's catalogue key.
    #[serde(default)]
    pub method: Option<String>,
    /// `general` items: the capability.
    #[serde(default)]
    pub capability: Option<String>,
    /// `method` items: the account this row is for.
    #[serde(default)]
    pub merchant_connector_id: Option<String>,
    /// Whether the children are known, e.g. `confirmed`, `unknown`,
    /// `context_required`.
    pub status: String,
    /// Where the answer came from.
    #[serde(default)]
    pub source: Option<String>,
    /// ISO 8601 time the answer was checked.
    #[serde(default)]
    pub checked_at: Option<String>,
    /// Whether the answer is older than DeloPay would like.
    pub stale: bool,
    /// `false` when the provider named something DeloPay has no id for.
    pub complete: bool,
    /// What DeloPay confirms, in badge order.
    #[serde(default)]
    pub children: Vec<CheckoutMethodChildRef>,
    /// While `status` is `unknown`: ids the merchant may state.
    #[serde(default)]
    pub declarable: Vec<CheckoutMethodChildRef>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One child of a placeable item, e.g. `card_network:visa`, `method:ideal`.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutMethodChildRef {
    /// The child's id, e.g. `crypto:usdt:tron`.
    pub id: String,
    /// The kind of child.
    pub kind: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A shop's checkout entries for one environment: separate ways into the
/// hosted checkout of one payment (`?entry=<key>`), each in its own named
/// look.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutEntriesResponse {
    /// The shop.
    pub profile_id: String,
    /// Whether these are the Test checkout's entries, used by payments
    /// created with `test_mode: true`, rather than Live's.
    pub test_mode: bool,
    /// The entries.
    #[serde(default)]
    pub entries: Vec<CheckoutEntry>,
    /// When the entries last changed (ISO 8601).
    #[serde(default)]
    pub modified_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One checkout entry. Read back from the API and sent again, unchanged or
/// edited, in `CheckoutEntriesUpdateRequest`.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CheckoutEntry {
    /// The value of `?entry=` that opens it: 1 to 32 characters of `a-z`,
    /// `0-9`, `_` and `-`, unique among the shop's entries in this
    /// environment.
    pub key: String,
    /// The merchant's name for the entry, 1 to 64 characters. Shown in the
    /// dashboard only.
    pub label: String,
    /// What the entry opens: `card` or `methods`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kind: Option<String>,
    /// `kind: methods` only, 1 to 32: what the entry offers.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub methods: Vec<CheckoutEntryMethod>,
    /// The named appearance variant the entry is drawn in.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub theme: Option<String>,
    /// `kind: card` only: the key of the `methods` entry its "Other payment
    /// methods" action opens.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub other_entry: Option<String>,
    /// Any additional fields not modeled above, kept on read and sent back
    /// verbatim.
    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
    pub extra: serde_json::Map<String, Value>,
}

impl CheckoutEntry {
    /// An entry opened by `?entry=key`, named `label` in the dashboard.
    pub fn new(key: impl Into<String>, label: impl Into<String>) -> Self {
        Self {
            key: key.into(),
            label: label.into(),
            ..Default::default()
        }
    }

    /// Open the card form (`card`) or a list of methods (`methods`).
    #[must_use]
    pub fn kind(mut self, kind: impl Into<String>) -> Self {
        self.kind = Some(kind.into());
        self
    }

    /// Add one method to a `methods` entry.
    #[must_use]
    pub fn method(mut self, method: CheckoutEntryMethod) -> Self {
        self.methods.push(method);
        self
    }

    /// Draw the entry in this named appearance variant.
    #[must_use]
    pub fn theme(mut self, theme: impl Into<String>) -> Self {
        self.theme = Some(theme.into());
        self
    }

    /// For a `card` entry: the `methods` entry its "Other payment methods"
    /// action opens.
    #[must_use]
    pub fn other_entry(mut self, other_entry: impl Into<String>) -> Self {
        self.other_entry = Some(other_entry.into());
        self
    }
}

/// One thing a `methods` entry offers: a layout group, one provider's
/// method, or a general method by capability.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CheckoutEntryMethod {
    /// `group`, `method` or `general`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kind: Option<String>,
    /// `kind: group` only: the group's `group_id` in the layout.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub group_id: Option<String>,
    /// `kind: method` only: the provider, e.g. `stripe`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub connector: Option<String>,
    /// `kind: method` only: the catalogue key, e.g. `apple_pay`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub method: Option<String>,
    /// `kind: general` only: the method's capability, e.g. `wallet.paypal`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub capability: Option<String>,
    /// Any additional fields not modeled above, kept on read and sent back
    /// verbatim.
    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
    pub extra: serde_json::Map<String, Value>,
}

impl CheckoutEntryMethod {
    /// A layout group, by its `group_id`.
    pub fn group(group_id: impl Into<String>) -> Self {
        Self {
            kind: Some("group".to_string()),
            group_id: Some(group_id.into()),
            ..Default::default()
        }
    }

    /// One provider's method, by catalogue key.
    pub fn provider_method(connector: impl Into<String>, method: impl Into<String>) -> Self {
        Self {
            kind: Some("method".to_string()),
            connector: Some(connector.into()),
            method: Some(method.into()),
            ..Default::default()
        }
    }

    /// A general method, by capability.
    pub fn general(capability: impl Into<String>) -> Self {
        Self {
            kind: Some("general".to_string()),
            capability: Some(capability.into()),
            ..Default::default()
        }
    }
}

/// The methods a payment of the shop can be limited to through
/// `allowed_payment_method_types`, in the order its checkout places them.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutPaymentMethodOptionsResponse {
    /// The shop.
    pub profile_id: String,
    /// Whether these are the Test checkout's methods rather than Live's.
    pub test_mode: bool,
    /// Methods only: no processor or account is named.
    #[serde(default)]
    pub options: Vec<CheckoutPaymentMethodOption>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One method a payment can be limited to.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutPaymentMethodOption {
    /// The kind of method: `card` for the card form.
    pub payment_method: String,
    /// What a payment limited to this method sends in
    /// `allowed_payment_method_types`.
    #[serde(default)]
    pub payment_method_types: Vec<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What the tested redirect rules decide for the described buyer, and how
/// each rule fared. Nothing is stored.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CheckoutRedirectRulesTestResponse {
    /// What the rules decided; `None` when none did and the saved behaviour
    /// applies.
    #[serde(default)]
    pub decision: Option<Value>,
    /// One trace per rule, in order.
    #[serde(default)]
    pub rules: Vec<Value>,
    /// What the buyer would be offered: the shop's layout after its
    /// availability rules and the cap states.
    #[serde(default)]
    pub offered: Vec<Value>,
    /// The live cap and health state of every account the rules name, and of
    /// the shop's accounts.
    #[serde(default)]
    pub accounts: Vec<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}