sumup 0.5.14

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

//! Endpoints to manage custom roles. Custom roles allow you to tailor roles from individual permissions to match your needs. Once created, you can assign your custom roles to your merchant account members using the memberships.
use super::common::*;
/// Marker type for this event notification.
#[derive(Debug, Clone)]
pub enum RoleCreated {}
impl crate::event::private::Sealed for RoleCreated {}
impl crate::events::EventSpec for RoleCreated {
    const EVENT_TYPE: &'static str = "roles.created";
    type FetchedObject = Role;
}
/// Event notification for this event type.
pub type RoleCreatedEvent = crate::events::Event<RoleCreated>;
/// Marker type for this event notification.
#[derive(Debug, Clone)]
pub enum RoleDeleted {}
impl crate::event::private::Sealed for RoleDeleted {}
impl crate::events::EventSpec for RoleDeleted {
    const EVENT_TYPE: &'static str = "roles.deleted";
    type FetchedObject = Role;
}
/// Event notification for this event type.
pub type RoleDeletedEvent = crate::events::Event<RoleDeleted>;
/// Marker type for this event notification.
#[derive(Debug, Clone)]
pub enum RoleUpdated {}
impl crate::event::private::Sealed for RoleUpdated {}
impl crate::events::EventSpec for RoleUpdated {
    const EVENT_TYPE: &'static str = "roles.updated";
    type FetchedObject = Role;
}
/// Event notification for this event type.
pub type RoleUpdatedEvent = crate::events::Event<RoleUpdated>;
/// A custom role that can be used to assign set of permissions to members.
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Role {
    /// The timestamp of when the role was created.
    ///
    /// Example: `2023-01-20T15:16:17Z`
    pub created_at: crate::datetime::DateTime,
    /// User-defined description of the role.
    ///
    /// Example: `Manges the shop and the employees.`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Unique identifier of the role.
    ///
    /// Example: `role_WZsm7QTPhVrompscmPhoGTXXcrd58fr9MOhP`
    pub id: String,
    /// True if the role is provided by SumUp.
    ///
    /// Example: `true`
    pub is_predefined: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Metadata>,
    /// User-defined name of the role.
    ///
    /// Example: `Senior Shop Manager II`
    pub name: String,
    /// List of permission granted by this role.
    ///
    /// Constraints:
    /// - max items: 100
    pub permissions: Vec<String>,
    /// The timestamp of when the role was last updated.
    ///
    /// Example: `2023-01-20T15:16:17Z`
    pub updated_at: crate::datetime::DateTime,
}
/// Returns a list of Role objects.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ListResponse {
    pub items: Vec<Role>,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreateRequest {
    /// User-defined description of the role.
    ///
    /// Example: `Manges the shop and the employees.`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Metadata>,
    /// User-defined name of the role.
    ///
    /// Example: `Senior Shop Manager II`
    pub name: String,
    /// User's permissions.
    ///
    /// Constraints:
    /// - min items: 1
    /// - max items: 100
    pub permissions: Vec<String>,
}
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct UpdateRequest {
    /// User-defined description of the role.
    ///
    /// Example: `Manges the shop and the employees.`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// User-defined name of the role.
    ///
    /// Example: `Senior Shop Manager II`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// User's permissions.
    ///
    /// Constraints:
    /// - min items: 1
    /// - max items: 100
    #[serde(skip_serializing_if = "Option::is_none")]
    pub permissions: Option<Vec<String>>,
}
use crate::client::Client;
#[derive(Debug, PartialEq)]
pub enum ListErrorBody {
    NotFound(Problem),
}
#[derive(Debug, PartialEq)]
pub enum CreateErrorBody {
    BadRequest(Problem),
    NotFound(Problem),
}
#[derive(Debug, PartialEq)]
pub enum DeleteErrorBody {
    BadRequest(Problem),
    NotFound(Problem),
}
#[derive(Debug, PartialEq)]
pub enum GetErrorBody {
    NotFound(Problem),
}
#[derive(Debug, PartialEq)]
pub enum UpdateErrorBody {
    BadRequest(Problem),
    NotFound(Problem),
}
/// Client for the Roles API endpoints.
#[derive(Debug)]
pub struct RolesClient<'a> {
    client: &'a Client,
}
impl<'a> RolesClient<'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
    }
    /// List roles
    ///
    /// List merchant's custom roles.
    ///
    /// Responses:
    /// - 200: Returns a list of Role objects.
    /// - 404: Merchant not found.
    pub async fn list(
        &self,
        merchant_code: impl Into<String>,
    ) -> crate::error::SdkResult<ListResponse, ListErrorBody> {
        let path = format!("/v0.1/merchants/{}/roles", merchant_code.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: ListResponse = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(ListErrorBody::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))
            }
        }
    }
    /// Create a role
    ///
    /// Create a custom role for the merchant. Roles are defined by the set of permissions that they grant to the members that they are assigned to.
    ///
    /// Responses:
    /// - 201: Returns the Role object after successful custom role creation.
    /// - 400: Invalid request.
    /// - 404: Merchant not found.
    pub async fn create(
        &self,
        merchant_code: impl Into<String>,
        body: CreateRequest,
    ) -> crate::error::SdkResult<Role, CreateErrorBody> {
        let path = format!("/v0.1/merchants/{}/roles", merchant_code.into());
        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: Role = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::BAD_REQUEST => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(CreateErrorBody::BadRequest(
                    body,
                )))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(CreateErrorBody::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))
            }
        }
    }
    /// Delete a role
    ///
    /// Delete a custom role.
    ///
    /// Responses:
    /// - 200: Returns an empty response if the role deletion succeeded.
    /// - 400: Invalid request.
    /// - 404: Merchant not found.
    pub async fn delete(
        &self,
        merchant_code: impl Into<String>,
        role_id: impl Into<String>,
    ) -> crate::error::SdkResult<(), DeleteErrorBody> {
        let path = format!(
            "/v0.1/merchants/{}/roles/{}",
            merchant_code.into(),
            role_id.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::OK => Ok(()),
            reqwest::StatusCode::BAD_REQUEST => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(DeleteErrorBody::BadRequest(
                    body,
                )))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(DeleteErrorBody::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))
            }
        }
    }
    /// Retrieve a role
    ///
    /// Retrieve a custom role by ID.
    ///
    /// Responses:
    /// - 200: Returns the Role object for a valid identifier.
    /// - 404: Merchant or role not found.
    pub async fn get(
        &self,
        merchant_code: impl Into<String>,
        role_id: impl Into<String>,
    ) -> crate::error::SdkResult<Role, GetErrorBody> {
        let path = format!(
            "/v0.1/merchants/{}/roles/{}",
            merchant_code.into(),
            role_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: Role = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Problem = 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 role
    ///
    /// Updates a custom role's name, description, or permissions and returns the updated role.
    ///
    /// Providing `permissions` replaces the role's permission list and changes the access granted to members assigned to that role. Omitted fields remain unchanged.
    ///
    /// Responses:
    /// - 200: Returns the updated Role object if the update succeeded.
    /// - 400: Invalid request.
    /// - 404: Merchant not found.
    pub async fn update(
        &self,
        merchant_code: impl Into<String>,
        role_id: impl Into<String>,
        body: UpdateRequest,
    ) -> crate::error::SdkResult<Role, UpdateErrorBody> {
        let path = format!(
            "/v0.1/merchants/{}/roles/{}",
            merchant_code.into(),
            role_id.into()
        );
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .patch(&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: Role = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::BAD_REQUEST => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(UpdateErrorBody::BadRequest(
                    body,
                )))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Problem = 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))
            }
        }
    }
}