1use crate::{Receipt, ReceiptListResponse, Result, SumUpClient};
2use serde::Serialize;
3
4#[derive(Debug, Clone, Serialize)]
5pub struct ReceiptListQuery {
6 pub mid: String, #[serde(skip_serializing_if = "Option::is_none")]
8 pub limit: Option<i32>,
9 #[serde(skip_serializing_if = "Option::is_none")]
10 pub offset: Option<i32>,
11}
12
13#[derive(Debug, Clone, Serialize)]
14pub struct ReceiptRetrieveQuery {
15 pub mid: String, }
17
18impl SumUpClient {
19 #[deprecated(
27 since = "0.2.0",
28 note = "The /v1.1/receipts list endpoint does not exist. Use retrieve_receipt for individual receipts."
29 )]
30 pub async fn list_receipts(&self, _query: &ReceiptListQuery) -> Result<ReceiptListResponse> {
31 Err(crate::Error::ApiError {
32 status: 404,
33 body: crate::ApiErrorBody {
34 error_type: None,
35 title: Some("Endpoint not implemented".to_string()),
36 status: Some(404),
37 detail: Some("The /v1.1/receipts list endpoint does not exist in the SumUp API. Only individual receipt retrieval is supported.".to_string()),
38 error_code: None,
39 message: None,
40 param: None,
41 additional_fields: std::collections::HashMap::new(),
42 }
43 })
44 }
45
46 #[deprecated(
55 since = "0.2.0",
56 note = "The merchant receipts list endpoint does not exist. Use retrieve_merchant_receipt for individual receipts."
57 )]
58 pub async fn list_merchant_receipts(
59 &self,
60 _merchant_code: &str,
61 _query: &ReceiptListQuery,
62 ) -> Result<ReceiptListResponse> {
63 Err(crate::Error::ApiError {
64 status: 404,
65 body: crate::ApiErrorBody {
66 error_type: None,
67 title: Some("Endpoint not implemented".to_string()),
68 status: Some(404),
69 detail: Some("The /v1.1/merchants/{merchant_code}/receipts list endpoint does not exist in the SumUp API. Only individual receipt retrieval is supported.".to_string()),
70 error_code: None,
71 message: None,
72 param: None,
73 additional_fields: std::collections::HashMap::new(),
74 }
75 })
76 }
77
78 pub async fn retrieve_receipt(
84 &self,
85 receipt_id: &str,
86 query: &ReceiptRetrieveQuery,
87 ) -> Result<Receipt> {
88 let url = self.build_url(&format!("/v1.1/receipts/{}", receipt_id))?;
89
90 let response = self
91 .http_client
92 .get(url)
93 .bearer_auth(&self.api_key)
94 .query(query)
95 .send()
96 .await?;
97
98 if response.status().is_success() {
99 let receipt = response.json::<Receipt>().await?;
100 Ok(receipt)
101 } else {
102 self.handle_error(response).await
103 }
104 }
105
106 pub async fn retrieve_merchant_receipt(
113 &self,
114 merchant_code: &str,
115 receipt_id: &str,
116 query: &ReceiptRetrieveQuery,
117 ) -> Result<Receipt> {
118 let url = self.build_url(&format!(
119 "/v1.1/merchants/{}/receipts/{}",
120 merchant_code, receipt_id
121 ))?;
122
123 let response = self
124 .http_client
125 .get(url)
126 .bearer_auth(&self.api_key)
127 .query(query)
128 .send()
129 .await?;
130
131 if response.status().is_success() {
132 let receipt = response.json::<Receipt>().await?;
133 Ok(receipt)
134 } else {
135 self.handle_error(response).await
136 }
137 }
138}