1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AlipayCreateOrderError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AlipayCreateOrderPagePayError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AlipayCreateOrderWapPayError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum AlipayOrderDetailError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AlipayOrderRefundError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum AlipayReturnPageNotifyError {
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn alipay_create_order(configuration: &configuration::Configuration, app_key: &str, alipay_create_order_request: Option<models::AlipayCreateOrderRequest>) -> Result<models::StringApiResponse, Error<AlipayCreateOrderError>> {
63 let p_app_key = app_key;
65 let p_alipay_create_order_request = alipay_create_order_request;
66
67 let uri_str = format!("{}/Alipay/{appKey}/CreateOrder", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
68 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
69
70 if let Some(ref user_agent) = configuration.user_agent {
71 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
72 }
73 if let Some(ref token) = configuration.bearer_access_token {
74 req_builder = req_builder.bearer_auth(token.to_owned());
75 };
76 req_builder = req_builder.json(&p_alipay_create_order_request);
77
78 let req = req_builder.build()?;
79 let resp = configuration.client.execute(req).await?;
80
81 let status = resp.status();
82 let content_type = resp
83 .headers()
84 .get("content-type")
85 .and_then(|v| v.to_str().ok())
86 .unwrap_or("application/octet-stream");
87 let content_type = super::ContentType::from(content_type);
88
89 if !status.is_client_error() && !status.is_server_error() {
90 let content = resp.text().await?;
91 match content_type {
92 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
93 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StringApiResponse`"))),
94 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StringApiResponse`")))),
95 }
96 } else {
97 let content = resp.text().await?;
98 let entity: Option<AlipayCreateOrderError> = serde_json::from_str(&content).ok();
99 Err(Error::ResponseError(ResponseContent { status, content, entity }))
100 }
101}
102
103pub async fn alipay_create_order_page_pay(configuration: &configuration::Configuration, app_key: &str, alipay_create_order_page_pay_request: Option<models::AlipayCreateOrderPagePayRequest>) -> Result<models::StringApiResponse, Error<AlipayCreateOrderPagePayError>> {
105 let p_app_key = app_key;
107 let p_alipay_create_order_page_pay_request = alipay_create_order_page_pay_request;
108
109 let uri_str = format!("{}/Alipay/{appKey}/CreateOrderPagePay", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
110 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
111
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref token) = configuration.bearer_access_token {
116 req_builder = req_builder.bearer_auth(token.to_owned());
117 };
118 req_builder = req_builder.json(&p_alipay_create_order_page_pay_request);
119
120 let req = req_builder.build()?;
121 let resp = configuration.client.execute(req).await?;
122
123 let status = resp.status();
124 let content_type = resp
125 .headers()
126 .get("content-type")
127 .and_then(|v| v.to_str().ok())
128 .unwrap_or("application/octet-stream");
129 let content_type = super::ContentType::from(content_type);
130
131 if !status.is_client_error() && !status.is_server_error() {
132 let content = resp.text().await?;
133 match content_type {
134 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
135 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StringApiResponse`"))),
136 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StringApiResponse`")))),
137 }
138 } else {
139 let content = resp.text().await?;
140 let entity: Option<AlipayCreateOrderPagePayError> = serde_json::from_str(&content).ok();
141 Err(Error::ResponseError(ResponseContent { status, content, entity }))
142 }
143}
144
145pub async fn alipay_create_order_wap_pay(configuration: &configuration::Configuration, app_key: &str, alipay_create_order_wap_pay_request: Option<models::AlipayCreateOrderWapPayRequest>) -> Result<models::StringApiResponse, Error<AlipayCreateOrderWapPayError>> {
147 let p_app_key = app_key;
149 let p_alipay_create_order_wap_pay_request = alipay_create_order_wap_pay_request;
150
151 let uri_str = format!("{}/Alipay/{appKey}/CreateOrderWapPay", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
152 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
153
154 if let Some(ref user_agent) = configuration.user_agent {
155 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
156 }
157 if let Some(ref token) = configuration.bearer_access_token {
158 req_builder = req_builder.bearer_auth(token.to_owned());
159 };
160 req_builder = req_builder.json(&p_alipay_create_order_wap_pay_request);
161
162 let req = req_builder.build()?;
163 let resp = configuration.client.execute(req).await?;
164
165 let status = resp.status();
166 let content_type = resp
167 .headers()
168 .get("content-type")
169 .and_then(|v| v.to_str().ok())
170 .unwrap_or("application/octet-stream");
171 let content_type = super::ContentType::from(content_type);
172
173 if !status.is_client_error() && !status.is_server_error() {
174 let content = resp.text().await?;
175 match content_type {
176 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
177 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StringApiResponse`"))),
178 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StringApiResponse`")))),
179 }
180 } else {
181 let content = resp.text().await?;
182 let entity: Option<AlipayCreateOrderWapPayError> = serde_json::from_str(&content).ok();
183 Err(Error::ResponseError(ResponseContent { status, content, entity }))
184 }
185}
186
187pub async fn alipay_order_detail(configuration: &configuration::Configuration, app_key: &str, order_no: Option<&str>) -> Result<models::AlipayTradeQueryResponseApiResponse, Error<AlipayOrderDetailError>> {
189 let p_app_key = app_key;
191 let p_order_no = order_no;
192
193 let uri_str = format!("{}/Alipay/{appKey}/OrderDetail", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
194 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
195
196 if let Some(ref param_value) = p_order_no {
197 req_builder = req_builder.query(&[("orderNo", ¶m_value.to_string())]);
198 }
199 if let Some(ref user_agent) = configuration.user_agent {
200 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201 }
202 if let Some(ref token) = configuration.bearer_access_token {
203 req_builder = req_builder.bearer_auth(token.to_owned());
204 };
205
206 let req = req_builder.build()?;
207 let resp = configuration.client.execute(req).await?;
208
209 let status = resp.status();
210 let content_type = resp
211 .headers()
212 .get("content-type")
213 .and_then(|v| v.to_str().ok())
214 .unwrap_or("application/octet-stream");
215 let content_type = super::ContentType::from(content_type);
216
217 if !status.is_client_error() && !status.is_server_error() {
218 let content = resp.text().await?;
219 match content_type {
220 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
221 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AlipayTradeQueryResponseApiResponse`"))),
222 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AlipayTradeQueryResponseApiResponse`")))),
223 }
224 } else {
225 let content = resp.text().await?;
226 let entity: Option<AlipayOrderDetailError> = serde_json::from_str(&content).ok();
227 Err(Error::ResponseError(ResponseContent { status, content, entity }))
228 }
229}
230
231pub async fn alipay_order_refund(configuration: &configuration::Configuration, app_key: &str, amount: Option<&str>, order_no: Option<&str>) -> Result<models::AlipayTradeRefundResponseApiResponse, Error<AlipayOrderRefundError>> {
233 let p_app_key = app_key;
235 let p_amount = amount;
236 let p_order_no = order_no;
237
238 let uri_str = format!("{}/Alipay/{appKey}/OrderRefund", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
239 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
240
241 if let Some(ref param_value) = p_amount {
242 req_builder = req_builder.query(&[("amount", ¶m_value.to_string())]);
243 }
244 if let Some(ref param_value) = p_order_no {
245 req_builder = req_builder.query(&[("orderNo", ¶m_value.to_string())]);
246 }
247 if let Some(ref user_agent) = configuration.user_agent {
248 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
249 }
250 if let Some(ref token) = configuration.bearer_access_token {
251 req_builder = req_builder.bearer_auth(token.to_owned());
252 };
253
254 let req = req_builder.build()?;
255 let resp = configuration.client.execute(req).await?;
256
257 let status = resp.status();
258 let content_type = resp
259 .headers()
260 .get("content-type")
261 .and_then(|v| v.to_str().ok())
262 .unwrap_or("application/octet-stream");
263 let content_type = super::ContentType::from(content_type);
264
265 if !status.is_client_error() && !status.is_server_error() {
266 let content = resp.text().await?;
267 match content_type {
268 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
269 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AlipayTradeRefundResponseApiResponse`"))),
270 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AlipayTradeRefundResponseApiResponse`")))),
271 }
272 } else {
273 let content = resp.text().await?;
274 let entity: Option<AlipayOrderRefundError> = serde_json::from_str(&content).ok();
275 Err(Error::ResponseError(ResponseContent { status, content, entity }))
276 }
277}
278
279pub async fn alipay_return_page_notify(configuration: &configuration::Configuration, app_key: &str, return_page_notify_request: Option<models::ReturnPageNotifyRequest>) -> Result<models::BooleanApiResponse, Error<AlipayReturnPageNotifyError>> {
281 let p_app_key = app_key;
283 let p_return_page_notify_request = return_page_notify_request;
284
285 let uri_str = format!("{}/Alipay/{appKey}/ReturnPageNotify", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
286 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
287
288 if let Some(ref user_agent) = configuration.user_agent {
289 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
290 }
291 if let Some(ref token) = configuration.bearer_access_token {
292 req_builder = req_builder.bearer_auth(token.to_owned());
293 };
294 req_builder = req_builder.json(&p_return_page_notify_request);
295
296 let req = req_builder.build()?;
297 let resp = configuration.client.execute(req).await?;
298
299 let status = resp.status();
300 let content_type = resp
301 .headers()
302 .get("content-type")
303 .and_then(|v| v.to_str().ok())
304 .unwrap_or("application/octet-stream");
305 let content_type = super::ContentType::from(content_type);
306
307 if !status.is_client_error() && !status.is_server_error() {
308 let content = resp.text().await?;
309 match content_type {
310 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
311 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
312 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BooleanApiResponse`")))),
313 }
314 } else {
315 let content = resp.text().await?;
316 let entity: Option<AlipayReturnPageNotifyError> = serde_json::from_str(&content).ok();
317 Err(Error::ResponseError(ResponseContent { status, content, entity }))
318 }
319}
320