1use crate::{
2 CreateReaderCheckoutRequest, CreateReaderRequest, Reader, ReaderCheckoutResponse,
3 ReaderListResponse, Result, SumUpClient, UpdateReaderRequest,
4};
5
6impl SumUpClient {
7 #[deprecated(
12 since = "0.2.0",
13 note = "The /me/readers endpoint does not exist. Use list_merchant_readers instead."
14 )]
15 pub async fn list_readers(&self) -> Result<ReaderListResponse> {
16 Err(crate::Error::ApiError {
17 status: 404,
18 body: crate::ApiErrorBody {
19 error_type: None,
20 title: Some("Endpoint not implemented".to_string()),
21 status: Some(404),
22 detail: Some("The /v0.1/me/readers endpoint does not exist in the SumUp API. Use list_merchant_readers with a merchant_code instead.".to_string()),
23 error_code: None,
24 message: None,
25 param: None,
26 additional_fields: std::collections::HashMap::new(),
27 }
28 })
29 }
30
31 pub async fn list_merchant_readers(&self, merchant_code: &str) -> Result<ReaderListResponse> {
36 let url = self.build_url(&format!("/v0.1/merchants/{}/readers", merchant_code))?;
37
38 let response = self
39 .http_client
40 .get(url)
41 .bearer_auth(&self.api_key)
42 .send()
43 .await?;
44
45 if response.status().is_success() {
46 let readers = response.json::<ReaderListResponse>().await?;
47 Ok(readers)
48 } else {
49 self.handle_error(response).await
50 }
51 }
52
53 #[deprecated(
61 since = "0.2.0",
62 note = "The /me/readers endpoint does not exist. Use create_merchant_reader instead."
63 )]
64 pub async fn create_reader(&self, _body: &CreateReaderRequest) -> Result<Reader> {
65 Err(crate::Error::ApiError {
66 status: 404,
67 body: crate::ApiErrorBody {
68 error_type: None,
69 title: Some("Endpoint not implemented".to_string()),
70 status: Some(404),
71 detail: Some("The /v0.1/me/readers endpoint does not exist in the SumUp API. Use create_merchant_reader with a merchant_code instead.".to_string()),
72 error_code: None,
73 message: None,
74 param: None,
75 additional_fields: std::collections::HashMap::new(),
76 }
77 })
78 }
79
80 pub async fn create_merchant_reader(
86 &self,
87 merchant_code: &str,
88 body: &CreateReaderRequest,
89 ) -> Result<Reader> {
90 let url = self.build_url(&format!("/v0.1/merchants/{}/readers", merchant_code))?;
91
92 let response = self
93 .http_client
94 .post(url)
95 .bearer_auth(&self.api_key)
96 .json(body)
97 .send()
98 .await?;
99
100 if response.status().is_success() {
101 let reader = response.json::<Reader>().await?;
102 Ok(reader)
103 } else {
104 self.handle_error(response).await
105 }
106 }
107
108 #[deprecated(
116 since = "0.2.0",
117 note = "The /me/readers/{reader_id} endpoint does not exist. Use retrieve_merchant_reader instead."
118 )]
119 pub async fn retrieve_reader(&self, _reader_id: &str) -> Result<Reader> {
120 Err(crate::Error::ApiError {
121 status: 404,
122 body: crate::ApiErrorBody {
123 error_type: None,
124 title: Some("Endpoint not implemented".to_string()),
125 status: Some(404),
126 detail: Some("The /v0.1/me/readers/{reader_id} endpoint does not exist in the SumUp API. Use retrieve_merchant_reader with a merchant_code instead.".to_string()),
127 error_code: None,
128 message: None,
129 param: None,
130 additional_fields: std::collections::HashMap::new(),
131 }
132 })
133 }
134
135 pub async fn retrieve_merchant_reader(
141 &self,
142 merchant_code: &str,
143 reader_id: &str,
144 ) -> Result<Reader> {
145 let url = self.build_url(&format!(
146 "/v0.1/merchants/{}/readers/{}",
147 merchant_code, reader_id
148 ))?;
149
150 let response = self
151 .http_client
152 .get(url)
153 .bearer_auth(&self.api_key)
154 .send()
155 .await?;
156
157 if response.status().is_success() {
158 let reader = response.json::<Reader>().await?;
159 Ok(reader)
160 } else {
161 self.handle_error(response).await
162 }
163 }
164
165 #[deprecated(
174 since = "0.2.0",
175 note = "The /me/readers/{reader_id} endpoint does not exist. Use update_merchant_reader instead."
176 )]
177 pub async fn update_reader(
178 &self,
179 _reader_id: &str,
180 _body: &UpdateReaderRequest,
181 ) -> Result<Reader> {
182 Err(crate::Error::ApiError {
183 status: 404,
184 body: crate::ApiErrorBody {
185 error_type: None,
186 title: Some("Endpoint not implemented".to_string()),
187 status: Some(404),
188 detail: Some("The /v0.1/me/readers/{reader_id} endpoint does not exist in the SumUp API. Use update_merchant_reader with a merchant_code instead.".to_string()),
189 error_code: None,
190 message: None,
191 param: None,
192 additional_fields: std::collections::HashMap::new(),
193 }
194 })
195 }
196
197 pub async fn update_merchant_reader(
204 &self,
205 merchant_code: &str,
206 reader_id: &str,
207 body: &UpdateReaderRequest,
208 ) -> Result<Reader> {
209 let url = self.build_url(&format!(
210 "/v0.1/merchants/{}/readers/{}",
211 merchant_code, reader_id
212 ))?;
213
214 let response = self
215 .http_client
216 .put(url)
217 .bearer_auth(&self.api_key)
218 .json(body)
219 .send()
220 .await?;
221
222 if response.status().is_success() {
223 let reader = response.json::<Reader>().await?;
224 Ok(reader)
225 } else {
226 self.handle_error(response).await
227 }
228 }
229
230 #[deprecated(
238 since = "0.2.0",
239 note = "The /me/readers/{reader_id} endpoint does not exist. Use delete_merchant_reader instead."
240 )]
241 pub async fn delete_reader(&self, _reader_id: &str) -> Result<()> {
242 Err(crate::Error::ApiError {
243 status: 404,
244 body: crate::ApiErrorBody {
245 error_type: None,
246 title: Some("Endpoint not implemented".to_string()),
247 status: Some(404),
248 detail: Some("The /v0.1/me/readers/{reader_id} endpoint does not exist in the SumUp API. Use delete_merchant_reader with a merchant_code instead.".to_string()),
249 error_code: None,
250 message: None,
251 param: None,
252 additional_fields: std::collections::HashMap::new(),
253 }
254 })
255 }
256
257 pub async fn delete_merchant_reader(&self, merchant_code: &str, reader_id: &str) -> Result<()> {
263 let url = self.build_url(&format!(
264 "/v0.1/merchants/{}/readers/{}",
265 merchant_code, reader_id
266 ))?;
267
268 let response = self
269 .http_client
270 .delete(url)
271 .bearer_auth(&self.api_key)
272 .send()
273 .await?;
274
275 if response.status().is_success() {
276 Ok(())
277 } else {
278 self.handle_error(response).await
279 }
280 }
281
282 #[deprecated(
291 since = "0.2.0",
292 note = "The /me/readers/{reader_id}/checkout endpoint does not exist. Use create_merchant_reader_checkout instead."
293 )]
294 pub async fn create_reader_checkout(
295 &self,
296 _reader_id: &str,
297 _body: &CreateReaderCheckoutRequest,
298 ) -> Result<ReaderCheckoutResponse> {
299 Err(crate::Error::ApiError {
300 status: 404,
301 body: crate::ApiErrorBody {
302 error_type: None,
303 title: Some("Endpoint not implemented".to_string()),
304 status: Some(404),
305 detail: Some("The /v0.1/me/readers/{reader_id}/checkout endpoint does not exist in the SumUp API. Use create_merchant_reader_checkout with a merchant_code instead.".to_string()),
306 error_code: None,
307 message: None,
308 param: None,
309 additional_fields: std::collections::HashMap::new(),
310 }
311 })
312 }
313
314 pub async fn create_merchant_reader_checkout(
321 &self,
322 merchant_code: &str,
323 reader_id: &str,
324 body: &CreateReaderCheckoutRequest,
325 ) -> Result<ReaderCheckoutResponse> {
326 let url = self.build_url(&format!(
327 "/v0.1/merchants/{}/readers/{}/checkout",
328 merchant_code, reader_id
329 ))?;
330
331 let response = self
332 .http_client
333 .post(url)
334 .bearer_auth(&self.api_key)
335 .json(body)
336 .send()
337 .await?;
338
339 if response.status().is_success() {
340 let checkout = response.json::<ReaderCheckoutResponse>().await?;
341 Ok(checkout)
342 } else {
343 self.handle_error(response).await
344 }
345 }
346
347 #[deprecated(
356 since = "0.2.0",
357 note = "The /me/readers/{reader_id}/checkout/{checkout_id} endpoint does not exist. Use terminate_merchant_reader_checkout instead."
358 )]
359 pub async fn terminate_reader_checkout(
360 &self,
361 _reader_id: &str,
362 _checkout_id: &str,
363 ) -> Result<()> {
364 Err(crate::Error::ApiError {
365 status: 404,
366 body: crate::ApiErrorBody {
367 error_type: None,
368 title: Some("Endpoint not implemented".to_string()),
369 status: Some(404),
370 detail: Some("The /v0.1/me/readers/{reader_id}/checkout/{checkout_id} endpoint does not exist in the SumUp API. Use terminate_merchant_reader_checkout with a merchant_code instead.".to_string()),
371 error_code: None,
372 message: None,
373 param: None,
374 additional_fields: std::collections::HashMap::new(),
375 }
376 })
377 }
378
379 pub async fn terminate_merchant_reader_checkout(
386 &self,
387 merchant_code: &str,
388 reader_id: &str,
389 checkout_id: &str,
390 ) -> Result<()> {
391 let url = self.build_url(&format!(
392 "/v0.1/merchants/{}/readers/{}/checkout/{}",
393 merchant_code, reader_id, checkout_id
394 ))?;
395
396 let response = self
397 .http_client
398 .delete(url)
399 .bearer_auth(&self.api_key)
400 .send()
401 .await?;
402
403 if response.status().is_success() {
404 Ok(())
405 } else {
406 self.handle_error(response).await
407 }
408 }
409}