sumup 0.5.12

Rust SDK for the SumUp 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
// The contents of this file are generated; do not modify them.

//! Allow your regular customers to save their information with the Customers model.
//!
//! This will prevent re-entering payment instrument information for recurring payments on your platform.
//!
//! Depending on the needs you can allow, creating, listing or deactivating payment instruments & creating, retrieving and updating customers.
use super::common::*;
/// Profile's personal address information.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct AddressLegacy {
    /// City name from the address.
    ///
    /// Example: `Berlin`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub city: Option<String>,
    /// Two letter country code formatted according to [ISO3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
    ///
    /// Example: `DE`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
    /// First line of the address with details of the street name and number.
    ///
    /// Example: `Sample street`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line_1: Option<String>,
    /// Second line of the address with details of the building, unit, apartment, and floor numbers.
    ///
    /// Example: `ap. 5`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line_2: Option<String>,
    /// Postal code from the address.
    ///
    /// Example: `10115`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub postal_code: Option<String>,
    /// State name or abbreviation from the address.
    ///
    /// Example: `Berlin`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state: Option<String>,
}
/// Saved customer details.
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Customer {
    /// Unique identifier of the customer.
    ///
    /// Example: `831ff8d4cd5958ab5670`
    pub customer_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub personal_details: Option<PersonalDetails>,
}
/// Details of a saved payment instrument.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct PaymentInstrumentResponse {
    /// Unique token identifying the saved payment card for a customer.
    ///
    /// Constraints:
    /// - read-only
    ///
    /// Example: `bcfc8e5f-3b47-4cb9-854b-3b7a4cce7be3`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token: Option<String>,
    /// Indicates whether the payment instrument is active and can be used for payments. To deactivate it, send a `DELETE` request to the resource endpoint.
    ///
    /// Constraints:
    /// - read-only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<bool>,
    /// Type of the payment instrument.
    ///
    /// Example: `card`
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<PaymentInstrumentResponseType>,
    /// Details of the payment card.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card: Option<PaymentInstrumentResponseCard>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mandate: Option<MandateResponse>,
    /// The timestamp of when the payment instrument was created.
    ///
    /// Example: `2021-03-30T10:06:07.000+00:00`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<crate::datetime::DateTime>,
}
/// Personal details for the customer.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct PersonalDetails {
    /// First name of the customer.
    ///
    /// Example: `John`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_name: Option<String>,
    /// Last name of the customer.
    ///
    /// Example: `Doe`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_name: Option<String>,
    /// Email address of the customer.
    ///
    /// Example: `user@example.com`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
    /// Phone number of the customer.
    ///
    /// Example: `+491635559723`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone: Option<String>,
    /// Date of birth of the customer.
    ///
    /// Example: `1993-12-31`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birth_date: Option<crate::datetime::Date>,
    /// Identification number used for tax purposes, such as a CPF in Brazil.
    ///
    /// Constraints:
    /// - max length: 255
    ///
    /// Example: `423.378.593-47`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tax_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address: Option<AddressLegacy>,
}
/// Type of the payment instrument.
///
/// Example: `card`
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum PaymentInstrumentResponseType {
    #[serde(rename = "card")]
    Card,
    #[serde(untagged)]
    Other(String),
}
/// Details of the payment card.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct PaymentInstrumentResponseCard {
    /// Last 4 digits of the payment card number.
    ///
    /// Constraints:
    /// - read-only
    /// - min length: 4
    /// - max length: 4
    ///
    /// Example: `3456`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_4_digits: Option<String>,
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<CardType>,
}
/// Details of the customer.
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreateRequest {
    /// Unique identifier of the customer.
    ///
    /// Example: `831ff8d4cd5958ab5670`
    pub customer_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub personal_details: Option<PersonalDetails>,
}
/// Customer fields to update.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct UpdateRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub personal_details: Option<PersonalDetails>,
}
/// Returns the list of saved payment instruments for the customer.
pub type ListPaymentInstrumentsResponse = Vec<PaymentInstrumentResponse>;
use crate::client::Client;
#[derive(Debug, PartialEq)]
pub enum CreateErrorBody {
    BadRequest(crate::error::UnknownApiBody),
    Unauthorized(Problem),
    Forbidden(ErrorForbidden),
    Conflict(Error),
}
#[derive(Debug, PartialEq)]
pub enum GetErrorBody {
    Unauthorized(Problem),
    Forbidden(ErrorForbidden),
    NotFound(Error),
}
#[derive(Debug, PartialEq)]
pub enum UpdateErrorBody {
    Unauthorized(Problem),
    Forbidden(ErrorForbidden),
    NotFound(Error),
}
#[derive(Debug, PartialEq)]
pub enum ListPaymentInstrumentsErrorBody {
    Unauthorized(Problem),
    Forbidden(ErrorForbidden),
    NotFound(Error),
}
#[derive(Debug, PartialEq)]
pub enum DeactivatePaymentInstrumentErrorBody {
    BadRequest(Error),
    Unauthorized(Problem),
    Forbidden(ErrorForbidden),
    NotFound(Error),
}
/// Client for the Customers API endpoints.
#[derive(Debug)]
pub struct CustomersClient<'a> {
    client: &'a Client,
}
impl<'a> CustomersClient<'a> {
    pub(crate) fn new(client: &'a Client) -> Self {
        Self { client }
    }
    /// Returns a reference to the underlying client.
    pub fn client(&self) -> &Client {
        self.client
    }
    /// Create a customer
    ///
    /// Creates a new saved customer resource which you can later manipulate and save payment instruments to.
    ///
    /// Responses:
    /// - 201: Returns the customer resource.
    /// - 400: The request body is invalid.
    /// - 401: The request is not authorized.
    /// - 403: The request is authenticated but not permitted for this operation.
    /// - 409: A customer with the provided identifier already exists.
    pub async fn create(
        &self,
        body: CreateRequest,
    ) -> crate::error::SdkResult<Customer, CreateErrorBody> {
        let path = "/v0.1/customers";
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .post(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout())
            .json(&body);
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::CREATED => {
                let data: Customer = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::BAD_REQUEST => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::api(CreateErrorBody::BadRequest(
                    body,
                )))
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(CreateErrorBody::Unauthorized(
                    body,
                )))
            }
            reqwest::StatusCode::FORBIDDEN => {
                let body: ErrorForbidden = response.json().await?;
                Err(crate::error::SdkError::api(CreateErrorBody::Forbidden(
                    body,
                )))
            }
            reqwest::StatusCode::CONFLICT => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(CreateErrorBody::Conflict(body)))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
    /// Retrieve a customer
    ///
    /// Retrieves an identified saved customer resource through the unique `customer_id` parameter, generated upon customer creation.
    ///
    /// Responses:
    /// - 200: Returns the customer resource.
    /// - 401: The request is not authorized.
    /// - 403: The request is authenticated but not permitted for this operation.
    /// - 404: The requested resource does not exist.
    pub async fn get(
        &self,
        customer_id: impl Into<String>,
    ) -> crate::error::SdkResult<Customer, GetErrorBody> {
        let path = format!("/v0.1/customers/{}", customer_id.into());
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .get(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout());
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::OK => {
                let data: Customer = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::Unauthorized(
                    body,
                )))
            }
            reqwest::StatusCode::FORBIDDEN => {
                let body: ErrorForbidden = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::Forbidden(body)))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::NotFound(body)))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
    /// Update a customer
    ///
    /// Updates an identified saved customer resource's personal details.
    ///
    /// The request only overwrites the parameters included in the request, all other parameters will remain with their initially assigned values.
    ///
    /// Responses:
    /// - 200: Returns the customer resource.
    /// - 401: The request is not authorized.
    /// - 403: The request is authenticated but not permitted for this operation.
    /// - 404: The requested resource does not exist.
    pub async fn update(
        &self,
        customer_id: impl Into<String>,
        body: UpdateRequest,
    ) -> crate::error::SdkResult<Customer, UpdateErrorBody> {
        let path = format!("/v0.1/customers/{}", customer_id.into());
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .put(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout())
            .json(&body);
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::OK => {
                let data: Customer = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(UpdateErrorBody::Unauthorized(
                    body,
                )))
            }
            reqwest::StatusCode::FORBIDDEN => {
                let body: ErrorForbidden = response.json().await?;
                Err(crate::error::SdkError::api(UpdateErrorBody::Forbidden(
                    body,
                )))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(UpdateErrorBody::NotFound(body)))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
    /// List payment instruments
    ///
    /// Lists all payment instrument resources that are saved for an identified customer.
    ///
    /// Responses:
    /// - 200: Returns the list of saved payment instruments for the customer.
    /// - 401: The request is not authorized.
    /// - 403: The request is authenticated but not permitted for this operation.
    /// - 404: The requested resource does not exist.
    pub async fn list_payment_instruments(
        &self,
        customer_id: impl Into<String>,
    ) -> crate::error::SdkResult<ListPaymentInstrumentsResponse, ListPaymentInstrumentsErrorBody>
    {
        let path = format!("/v0.1/customers/{}/payment-instruments", customer_id.into());
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .get(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout());
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::OK => {
                let data: ListPaymentInstrumentsResponse = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(
                    ListPaymentInstrumentsErrorBody::Unauthorized(body),
                ))
            }
            reqwest::StatusCode::FORBIDDEN => {
                let body: ErrorForbidden = response.json().await?;
                Err(crate::error::SdkError::api(
                    ListPaymentInstrumentsErrorBody::Forbidden(body),
                ))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(
                    ListPaymentInstrumentsErrorBody::NotFound(body),
                ))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
    /// Deactivate a payment instrument
    ///
    /// Deactivates an identified card payment instrument resource for a customer.
    ///
    /// Responses:
    /// - 204: Returns an empty response body when the operation succeeds.
    /// - 400: The request is invalid.
    /// - 401: The request is not authorized.
    /// - 403: The request is authenticated but not permitted for this operation.
    /// - 404: The requested resource does not exist.
    pub async fn deactivate_payment_instrument(
        &self,
        customer_id: impl Into<String>,
        token: impl Into<String>,
    ) -> crate::error::SdkResult<(), DeactivatePaymentInstrumentErrorBody> {
        let path = format!(
            "/v0.1/customers/{}/payment-instruments/{}",
            customer_id.into(),
            token.into()
        );
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .delete(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout());
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::NO_CONTENT => Ok(()),
            reqwest::StatusCode::BAD_REQUEST => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(
                    DeactivatePaymentInstrumentErrorBody::BadRequest(body),
                ))
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(
                    DeactivatePaymentInstrumentErrorBody::Unauthorized(body),
                ))
            }
            reqwest::StatusCode::FORBIDDEN => {
                let body: ErrorForbidden = response.json().await?;
                Err(crate::error::SdkError::api(
                    DeactivatePaymentInstrumentErrorBody::Forbidden(body),
                ))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(
                    DeactivatePaymentInstrumentErrorBody::NotFound(body),
                ))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
}