Skip to main content

autogen_squareup/apis/
loyalty_api.rs

1/*
2 * Square
3 *
4 * Use Square APIs to manage and run business including payment, customer, product, inventory, and employee management.
5 *
6 * The version of the OpenAPI document: 2.0
7 * Contact: developers@squareup.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`accumulate_loyalty_points`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccumulateLoyaltyPointsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`adjust_loyalty_points`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AdjustLoyaltyPointsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`calculate_loyalty_points`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CalculateLoyaltyPointsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`cancel_loyalty_promotion`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum CancelLoyaltyPromotionError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`create_loyalty_account`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateLoyaltyAccountError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`create_loyalty_promotion`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum CreateLoyaltyPromotionError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`create_loyalty_reward`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum CreateLoyaltyRewardError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`delete_loyalty_reward`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DeleteLoyaltyRewardError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`list_loyalty_programs`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ListLoyaltyProgramsError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`list_loyalty_promotions`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ListLoyaltyPromotionsError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`redeem_loyalty_reward`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum RedeemLoyaltyRewardError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`retrieve_loyalty_account`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum RetrieveLoyaltyAccountError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`retrieve_loyalty_program`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum RetrieveLoyaltyProgramError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`retrieve_loyalty_promotion`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum RetrieveLoyaltyPromotionError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`retrieve_loyalty_reward`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum RetrieveLoyaltyRewardError {
120    UnknownValue(serde_json::Value),
121}
122
123/// struct for typed errors of method [`search_loyalty_accounts`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum SearchLoyaltyAccountsError {
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`search_loyalty_events`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum SearchLoyaltyEventsError {
134    UnknownValue(serde_json::Value),
135}
136
137/// struct for typed errors of method [`search_loyalty_rewards`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum SearchLoyaltyRewardsError {
141    UnknownValue(serde_json::Value),
142}
143
144
145/// Adds points earned from a purchase to a [loyalty account](entity:LoyaltyAccount).  - If you are using the Orders API to manage orders, provide the `order_id`. Square reads the order to compute the points earned from both the base loyalty program and an associated [loyalty promotion](entity:LoyaltyPromotion). For purchases that qualify for multiple accrual rules, Square computes points based on the accrual rule that grants the most points. For purchases that qualify for multiple promotions, Square computes points based on the most recently created promotion. A purchase must first qualify for program points to be eligible for promotion points.  - If you are not using the Orders API to manage orders, provide `points` with the number of points to add. You must first perform a client-side computation of the points earned from the loyalty program and loyalty promotion. For spend-based and visit-based programs, you can call [CalculateLoyaltyPoints](api-endpoint:Loyalty-CalculateLoyaltyPoints) to compute the points earned from the base loyalty program. For information about computing points earned from a loyalty promotion, see [Calculating promotion points](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions#calculate-promotion-points).
146pub async fn accumulate_loyalty_points(configuration: &configuration::Configuration, account_id: &str, accumulate_loyalty_points_request: models::AccumulateLoyaltyPointsRequest) -> Result<models::AccumulateLoyaltyPointsResponse, Error<AccumulateLoyaltyPointsError>> {
147    // add a prefix to parameters to efficiently prevent name collisions
148    let p_account_id = account_id;
149    let p_accumulate_loyalty_points_request = accumulate_loyalty_points_request;
150
151    let uri_str = format!("{}/v2/loyalty/accounts/{account_id}/accumulate", configuration.base_path, account_id=crate::apis::urlencode(p_account_id));
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.oauth_access_token {
158        req_builder = req_builder.bearer_auth(token.to_owned());
159    };
160    req_builder = req_builder.json(&p_accumulate_loyalty_points_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::AccumulateLoyaltyPointsResponse`"))),
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::AccumulateLoyaltyPointsResponse`")))),
179        }
180    } else {
181        let content = resp.text().await?;
182        let entity: Option<AccumulateLoyaltyPointsError> = serde_json::from_str(&content).ok();
183        Err(Error::ResponseError(ResponseContent { status, content, entity }))
184    }
185}
186
187/// Adds points to or subtracts points from a buyer's account.  Use this endpoint only when you need to manually adjust points. Otherwise, in your application flow, you call [AccumulateLoyaltyPoints](api-endpoint:Loyalty-AccumulateLoyaltyPoints) to add points when a buyer pays for the purchase.
188pub async fn adjust_loyalty_points(configuration: &configuration::Configuration, account_id: &str, adjust_loyalty_points_request: models::AdjustLoyaltyPointsRequest) -> Result<models::AdjustLoyaltyPointsResponse, Error<AdjustLoyaltyPointsError>> {
189    // add a prefix to parameters to efficiently prevent name collisions
190    let p_account_id = account_id;
191    let p_adjust_loyalty_points_request = adjust_loyalty_points_request;
192
193    let uri_str = format!("{}/v2/loyalty/accounts/{account_id}/adjust", configuration.base_path, account_id=crate::apis::urlencode(p_account_id));
194    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
195
196    if let Some(ref user_agent) = configuration.user_agent {
197        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198    }
199    if let Some(ref token) = configuration.oauth_access_token {
200        req_builder = req_builder.bearer_auth(token.to_owned());
201    };
202    req_builder = req_builder.json(&p_adjust_loyalty_points_request);
203
204    let req = req_builder.build()?;
205    let resp = configuration.client.execute(req).await?;
206
207    let status = resp.status();
208    let content_type = resp
209        .headers()
210        .get("content-type")
211        .and_then(|v| v.to_str().ok())
212        .unwrap_or("application/octet-stream");
213    let content_type = super::ContentType::from(content_type);
214
215    if !status.is_client_error() && !status.is_server_error() {
216        let content = resp.text().await?;
217        match content_type {
218            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
219            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdjustLoyaltyPointsResponse`"))),
220            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::AdjustLoyaltyPointsResponse`")))),
221        }
222    } else {
223        let content = resp.text().await?;
224        let entity: Option<AdjustLoyaltyPointsError> = serde_json::from_str(&content).ok();
225        Err(Error::ResponseError(ResponseContent { status, content, entity }))
226    }
227}
228
229/// Calculates the number of points a buyer can earn from a purchase. Applications might call this endpoint to display the points to the buyer.  - If you are using the Orders API to manage orders, provide the `order_id` and (optional) `loyalty_account_id`. Square reads the order to compute the points earned from the base loyalty program and an associated [loyalty promotion](entity:LoyaltyPromotion).  - If you are not using the Orders API to manage orders, provide `transaction_amount_money` with the purchase amount. Square uses this amount to calculate the points earned from the base loyalty program, but not points earned from a loyalty promotion. For spend-based and visit-based programs, the `tax_mode` setting of the accrual rule indicates how taxes should be treated for loyalty points accrual. If the purchase qualifies for program points, call [ListLoyaltyPromotions](api-endpoint:Loyalty-ListLoyaltyPromotions) and perform a client-side computation to calculate whether the purchase also qualifies for promotion points. For more information, see [Calculating promotion points](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions#calculate-promotion-points).
230pub async fn calculate_loyalty_points(configuration: &configuration::Configuration, program_id: &str, calculate_loyalty_points_request: models::CalculateLoyaltyPointsRequest) -> Result<models::CalculateLoyaltyPointsResponse, Error<CalculateLoyaltyPointsError>> {
231    // add a prefix to parameters to efficiently prevent name collisions
232    let p_program_id = program_id;
233    let p_calculate_loyalty_points_request = calculate_loyalty_points_request;
234
235    let uri_str = format!("{}/v2/loyalty/programs/{program_id}/calculate", configuration.base_path, program_id=crate::apis::urlencode(p_program_id));
236    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
237
238    if let Some(ref user_agent) = configuration.user_agent {
239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240    }
241    if let Some(ref token) = configuration.oauth_access_token {
242        req_builder = req_builder.bearer_auth(token.to_owned());
243    };
244    req_builder = req_builder.json(&p_calculate_loyalty_points_request);
245
246    let req = req_builder.build()?;
247    let resp = configuration.client.execute(req).await?;
248
249    let status = resp.status();
250    let content_type = resp
251        .headers()
252        .get("content-type")
253        .and_then(|v| v.to_str().ok())
254        .unwrap_or("application/octet-stream");
255    let content_type = super::ContentType::from(content_type);
256
257    if !status.is_client_error() && !status.is_server_error() {
258        let content = resp.text().await?;
259        match content_type {
260            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
261            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CalculateLoyaltyPointsResponse`"))),
262            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::CalculateLoyaltyPointsResponse`")))),
263        }
264    } else {
265        let content = resp.text().await?;
266        let entity: Option<CalculateLoyaltyPointsError> = serde_json::from_str(&content).ok();
267        Err(Error::ResponseError(ResponseContent { status, content, entity }))
268    }
269}
270
271/// Cancels a loyalty promotion. Use this endpoint to cancel an `ACTIVE` promotion earlier than the end date, cancel an `ACTIVE` promotion when an end date is not specified, or cancel a `SCHEDULED` promotion. Because updating a promotion is not supported, you can also use this endpoint to cancel a promotion before you create a new one.  This endpoint sets the loyalty promotion to the `CANCELED` state
272pub async fn cancel_loyalty_promotion(configuration: &configuration::Configuration, promotion_id: &str, program_id: &str) -> Result<models::CancelLoyaltyPromotionResponse, Error<CancelLoyaltyPromotionError>> {
273    // add a prefix to parameters to efficiently prevent name collisions
274    let p_promotion_id = promotion_id;
275    let p_program_id = program_id;
276
277    let uri_str = format!("{}/v2/loyalty/programs/{program_id}/promotions/{promotion_id}/cancel", configuration.base_path, promotion_id=crate::apis::urlencode(p_promotion_id), program_id=crate::apis::urlencode(p_program_id));
278    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
279
280    if let Some(ref user_agent) = configuration.user_agent {
281        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
282    }
283    if let Some(ref token) = configuration.oauth_access_token {
284        req_builder = req_builder.bearer_auth(token.to_owned());
285    };
286
287    let req = req_builder.build()?;
288    let resp = configuration.client.execute(req).await?;
289
290    let status = resp.status();
291    let content_type = resp
292        .headers()
293        .get("content-type")
294        .and_then(|v| v.to_str().ok())
295        .unwrap_or("application/octet-stream");
296    let content_type = super::ContentType::from(content_type);
297
298    if !status.is_client_error() && !status.is_server_error() {
299        let content = resp.text().await?;
300        match content_type {
301            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
302            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CancelLoyaltyPromotionResponse`"))),
303            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::CancelLoyaltyPromotionResponse`")))),
304        }
305    } else {
306        let content = resp.text().await?;
307        let entity: Option<CancelLoyaltyPromotionError> = serde_json::from_str(&content).ok();
308        Err(Error::ResponseError(ResponseContent { status, content, entity }))
309    }
310}
311
312/// Creates a loyalty account. To create a loyalty account, you must provide the `program_id` and a `mapping` with the `phone_number` of the buyer.
313pub async fn create_loyalty_account(configuration: &configuration::Configuration, create_loyalty_account_request: models::CreateLoyaltyAccountRequest) -> Result<models::CreateLoyaltyAccountResponse, Error<CreateLoyaltyAccountError>> {
314    // add a prefix to parameters to efficiently prevent name collisions
315    let p_create_loyalty_account_request = create_loyalty_account_request;
316
317    let uri_str = format!("{}/v2/loyalty/accounts", configuration.base_path);
318    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
319
320    if let Some(ref user_agent) = configuration.user_agent {
321        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
322    }
323    if let Some(ref token) = configuration.oauth_access_token {
324        req_builder = req_builder.bearer_auth(token.to_owned());
325    };
326    req_builder = req_builder.json(&p_create_loyalty_account_request);
327
328    let req = req_builder.build()?;
329    let resp = configuration.client.execute(req).await?;
330
331    let status = resp.status();
332    let content_type = resp
333        .headers()
334        .get("content-type")
335        .and_then(|v| v.to_str().ok())
336        .unwrap_or("application/octet-stream");
337    let content_type = super::ContentType::from(content_type);
338
339    if !status.is_client_error() && !status.is_server_error() {
340        let content = resp.text().await?;
341        match content_type {
342            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
343            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateLoyaltyAccountResponse`"))),
344            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::CreateLoyaltyAccountResponse`")))),
345        }
346    } else {
347        let content = resp.text().await?;
348        let entity: Option<CreateLoyaltyAccountError> = serde_json::from_str(&content).ok();
349        Err(Error::ResponseError(ResponseContent { status, content, entity }))
350    }
351}
352
353/// Creates a loyalty promotion for a [loyalty program](entity:LoyaltyProgram). A loyalty promotion enables buyers to earn points in addition to those earned from the base loyalty program.  This endpoint sets the loyalty promotion to the `ACTIVE` or `SCHEDULED` status, depending on the `available_time` setting. A loyalty program can have a maximum of 10 loyalty promotions with an `ACTIVE` or `SCHEDULED` status.
354pub async fn create_loyalty_promotion(configuration: &configuration::Configuration, program_id: &str, create_loyalty_promotion_request: models::CreateLoyaltyPromotionRequest) -> Result<models::CreateLoyaltyPromotionResponse, Error<CreateLoyaltyPromotionError>> {
355    // add a prefix to parameters to efficiently prevent name collisions
356    let p_program_id = program_id;
357    let p_create_loyalty_promotion_request = create_loyalty_promotion_request;
358
359    let uri_str = format!("{}/v2/loyalty/programs/{program_id}/promotions", configuration.base_path, program_id=crate::apis::urlencode(p_program_id));
360    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
361
362    if let Some(ref user_agent) = configuration.user_agent {
363        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
364    }
365    if let Some(ref token) = configuration.oauth_access_token {
366        req_builder = req_builder.bearer_auth(token.to_owned());
367    };
368    req_builder = req_builder.json(&p_create_loyalty_promotion_request);
369
370    let req = req_builder.build()?;
371    let resp = configuration.client.execute(req).await?;
372
373    let status = resp.status();
374    let content_type = resp
375        .headers()
376        .get("content-type")
377        .and_then(|v| v.to_str().ok())
378        .unwrap_or("application/octet-stream");
379    let content_type = super::ContentType::from(content_type);
380
381    if !status.is_client_error() && !status.is_server_error() {
382        let content = resp.text().await?;
383        match content_type {
384            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
385            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateLoyaltyPromotionResponse`"))),
386            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::CreateLoyaltyPromotionResponse`")))),
387        }
388    } else {
389        let content = resp.text().await?;
390        let entity: Option<CreateLoyaltyPromotionError> = serde_json::from_str(&content).ok();
391        Err(Error::ResponseError(ResponseContent { status, content, entity }))
392    }
393}
394
395/// Creates a loyalty reward. In the process, the endpoint does following:  - Uses the `reward_tier_id` in the request to determine the number of points to lock for this reward. - If the request includes `order_id`, it adds the reward and related discount to the order.  After a reward is created, the points are locked and not available for the buyer to redeem another reward.
396pub async fn create_loyalty_reward(configuration: &configuration::Configuration, create_loyalty_reward_request: models::CreateLoyaltyRewardRequest) -> Result<models::CreateLoyaltyRewardResponse, Error<CreateLoyaltyRewardError>> {
397    // add a prefix to parameters to efficiently prevent name collisions
398    let p_create_loyalty_reward_request = create_loyalty_reward_request;
399
400    let uri_str = format!("{}/v2/loyalty/rewards", configuration.base_path);
401    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
402
403    if let Some(ref user_agent) = configuration.user_agent {
404        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
405    }
406    if let Some(ref token) = configuration.oauth_access_token {
407        req_builder = req_builder.bearer_auth(token.to_owned());
408    };
409    req_builder = req_builder.json(&p_create_loyalty_reward_request);
410
411    let req = req_builder.build()?;
412    let resp = configuration.client.execute(req).await?;
413
414    let status = resp.status();
415    let content_type = resp
416        .headers()
417        .get("content-type")
418        .and_then(|v| v.to_str().ok())
419        .unwrap_or("application/octet-stream");
420    let content_type = super::ContentType::from(content_type);
421
422    if !status.is_client_error() && !status.is_server_error() {
423        let content = resp.text().await?;
424        match content_type {
425            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
426            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateLoyaltyRewardResponse`"))),
427            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::CreateLoyaltyRewardResponse`")))),
428        }
429    } else {
430        let content = resp.text().await?;
431        let entity: Option<CreateLoyaltyRewardError> = serde_json::from_str(&content).ok();
432        Err(Error::ResponseError(ResponseContent { status, content, entity }))
433    }
434}
435
436/// Deletes a loyalty reward by doing the following:  - Returns the loyalty points back to the loyalty account. - If an order ID was specified when the reward was created (see [CreateLoyaltyReward](api-endpoint:Loyalty-CreateLoyaltyReward)), it updates the order by removing the reward and related discounts.  You cannot delete a reward that has reached the terminal state (REDEEMED).
437pub async fn delete_loyalty_reward(configuration: &configuration::Configuration, reward_id: &str) -> Result<models::DeleteLoyaltyRewardResponse, Error<DeleteLoyaltyRewardError>> {
438    // add a prefix to parameters to efficiently prevent name collisions
439    let p_reward_id = reward_id;
440
441    let uri_str = format!("{}/v2/loyalty/rewards/{reward_id}", configuration.base_path, reward_id=crate::apis::urlencode(p_reward_id));
442    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
443
444    if let Some(ref user_agent) = configuration.user_agent {
445        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
446    }
447    if let Some(ref token) = configuration.oauth_access_token {
448        req_builder = req_builder.bearer_auth(token.to_owned());
449    };
450
451    let req = req_builder.build()?;
452    let resp = configuration.client.execute(req).await?;
453
454    let status = resp.status();
455    let content_type = resp
456        .headers()
457        .get("content-type")
458        .and_then(|v| v.to_str().ok())
459        .unwrap_or("application/octet-stream");
460    let content_type = super::ContentType::from(content_type);
461
462    if !status.is_client_error() && !status.is_server_error() {
463        let content = resp.text().await?;
464        match content_type {
465            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
466            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteLoyaltyRewardResponse`"))),
467            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::DeleteLoyaltyRewardResponse`")))),
468        }
469    } else {
470        let content = resp.text().await?;
471        let entity: Option<DeleteLoyaltyRewardError> = serde_json::from_str(&content).ok();
472        Err(Error::ResponseError(ResponseContent { status, content, entity }))
473    }
474}
475
476/// Returns a list of loyalty programs in the seller's account. Loyalty programs define how buyers can earn points and redeem points for rewards. Square sellers can have only one loyalty program, which is created and managed from the Seller Dashboard. For more information, see [Loyalty Program Overview](https://developer.squareup.com/docs/loyalty/overview).   Replaced with [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram) when used with the keyword `main`.
477pub async fn list_loyalty_programs(configuration: &configuration::Configuration, ) -> Result<models::ListLoyaltyProgramsResponse, Error<ListLoyaltyProgramsError>> {
478
479    let uri_str = format!("{}/v2/loyalty/programs", configuration.base_path);
480    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
481
482    if let Some(ref user_agent) = configuration.user_agent {
483        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
484    }
485    if let Some(ref token) = configuration.oauth_access_token {
486        req_builder = req_builder.bearer_auth(token.to_owned());
487    };
488
489    let req = req_builder.build()?;
490    let resp = configuration.client.execute(req).await?;
491
492    let status = resp.status();
493    let content_type = resp
494        .headers()
495        .get("content-type")
496        .and_then(|v| v.to_str().ok())
497        .unwrap_or("application/octet-stream");
498    let content_type = super::ContentType::from(content_type);
499
500    if !status.is_client_error() && !status.is_server_error() {
501        let content = resp.text().await?;
502        match content_type {
503            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
504            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListLoyaltyProgramsResponse`"))),
505            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::ListLoyaltyProgramsResponse`")))),
506        }
507    } else {
508        let content = resp.text().await?;
509        let entity: Option<ListLoyaltyProgramsError> = serde_json::from_str(&content).ok();
510        Err(Error::ResponseError(ResponseContent { status, content, entity }))
511    }
512}
513
514/// Lists the loyalty promotions associated with a [loyalty program](entity:LoyaltyProgram). Results are sorted by the `created_at` date in descending order (newest to oldest).
515pub async fn list_loyalty_promotions(configuration: &configuration::Configuration, program_id: &str, status: Option<models::LoyaltyPromotionStatus>, cursor: Option<&str>, limit: Option<i32>) -> Result<models::ListLoyaltyPromotionsResponse, Error<ListLoyaltyPromotionsError>> {
516    // add a prefix to parameters to efficiently prevent name collisions
517    let p_program_id = program_id;
518    let p_status = status;
519    let p_cursor = cursor;
520    let p_limit = limit;
521
522    let uri_str = format!("{}/v2/loyalty/programs/{program_id}/promotions", configuration.base_path, program_id=crate::apis::urlencode(p_program_id));
523    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
524
525    if let Some(ref param_value) = p_status {
526        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
527    }
528    if let Some(ref param_value) = p_cursor {
529        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
530    }
531    if let Some(ref param_value) = p_limit {
532        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
533    }
534    if let Some(ref user_agent) = configuration.user_agent {
535        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
536    }
537    if let Some(ref token) = configuration.oauth_access_token {
538        req_builder = req_builder.bearer_auth(token.to_owned());
539    };
540
541    let req = req_builder.build()?;
542    let resp = configuration.client.execute(req).await?;
543
544    let status = resp.status();
545    let content_type = resp
546        .headers()
547        .get("content-type")
548        .and_then(|v| v.to_str().ok())
549        .unwrap_or("application/octet-stream");
550    let content_type = super::ContentType::from(content_type);
551
552    if !status.is_client_error() && !status.is_server_error() {
553        let content = resp.text().await?;
554        match content_type {
555            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
556            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListLoyaltyPromotionsResponse`"))),
557            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::ListLoyaltyPromotionsResponse`")))),
558        }
559    } else {
560        let content = resp.text().await?;
561        let entity: Option<ListLoyaltyPromotionsError> = serde_json::from_str(&content).ok();
562        Err(Error::ResponseError(ResponseContent { status, content, entity }))
563    }
564}
565
566/// Redeems a loyalty reward.  The endpoint sets the reward to the `REDEEMED` terminal state.  If you are using your own order processing system (not using the Orders API), you call this endpoint after the buyer paid for the purchase.  After the reward reaches the terminal state, it cannot be deleted. In other words, points used for the reward cannot be returned to the account.
567pub async fn redeem_loyalty_reward(configuration: &configuration::Configuration, reward_id: &str, redeem_loyalty_reward_request: models::RedeemLoyaltyRewardRequest) -> Result<models::RedeemLoyaltyRewardResponse, Error<RedeemLoyaltyRewardError>> {
568    // add a prefix to parameters to efficiently prevent name collisions
569    let p_reward_id = reward_id;
570    let p_redeem_loyalty_reward_request = redeem_loyalty_reward_request;
571
572    let uri_str = format!("{}/v2/loyalty/rewards/{reward_id}/redeem", configuration.base_path, reward_id=crate::apis::urlencode(p_reward_id));
573    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
574
575    if let Some(ref user_agent) = configuration.user_agent {
576        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
577    }
578    if let Some(ref token) = configuration.oauth_access_token {
579        req_builder = req_builder.bearer_auth(token.to_owned());
580    };
581    req_builder = req_builder.json(&p_redeem_loyalty_reward_request);
582
583    let req = req_builder.build()?;
584    let resp = configuration.client.execute(req).await?;
585
586    let status = resp.status();
587    let content_type = resp
588        .headers()
589        .get("content-type")
590        .and_then(|v| v.to_str().ok())
591        .unwrap_or("application/octet-stream");
592    let content_type = super::ContentType::from(content_type);
593
594    if !status.is_client_error() && !status.is_server_error() {
595        let content = resp.text().await?;
596        match content_type {
597            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
598            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RedeemLoyaltyRewardResponse`"))),
599            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::RedeemLoyaltyRewardResponse`")))),
600        }
601    } else {
602        let content = resp.text().await?;
603        let entity: Option<RedeemLoyaltyRewardError> = serde_json::from_str(&content).ok();
604        Err(Error::ResponseError(ResponseContent { status, content, entity }))
605    }
606}
607
608/// Retrieves a loyalty account.
609pub async fn retrieve_loyalty_account(configuration: &configuration::Configuration, account_id: &str) -> Result<models::RetrieveLoyaltyAccountResponse, Error<RetrieveLoyaltyAccountError>> {
610    // add a prefix to parameters to efficiently prevent name collisions
611    let p_account_id = account_id;
612
613    let uri_str = format!("{}/v2/loyalty/accounts/{account_id}", configuration.base_path, account_id=crate::apis::urlencode(p_account_id));
614    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
615
616    if let Some(ref user_agent) = configuration.user_agent {
617        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
618    }
619    if let Some(ref token) = configuration.oauth_access_token {
620        req_builder = req_builder.bearer_auth(token.to_owned());
621    };
622
623    let req = req_builder.build()?;
624    let resp = configuration.client.execute(req).await?;
625
626    let status = resp.status();
627    let content_type = resp
628        .headers()
629        .get("content-type")
630        .and_then(|v| v.to_str().ok())
631        .unwrap_or("application/octet-stream");
632    let content_type = super::ContentType::from(content_type);
633
634    if !status.is_client_error() && !status.is_server_error() {
635        let content = resp.text().await?;
636        match content_type {
637            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
638            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveLoyaltyAccountResponse`"))),
639            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::RetrieveLoyaltyAccountResponse`")))),
640        }
641    } else {
642        let content = resp.text().await?;
643        let entity: Option<RetrieveLoyaltyAccountError> = serde_json::from_str(&content).ok();
644        Err(Error::ResponseError(ResponseContent { status, content, entity }))
645    }
646}
647
648/// Retrieves the loyalty program in a seller's account, specified by the program ID or the keyword `main`.  Loyalty programs define how buyers can earn points and redeem points for rewards. Square sellers can have only one loyalty program, which is created and managed from the Seller Dashboard. For more information, see [Loyalty Program Overview](https://developer.squareup.com/docs/loyalty/overview).
649pub async fn retrieve_loyalty_program(configuration: &configuration::Configuration, program_id: &str) -> Result<models::RetrieveLoyaltyProgramResponse, Error<RetrieveLoyaltyProgramError>> {
650    // add a prefix to parameters to efficiently prevent name collisions
651    let p_program_id = program_id;
652
653    let uri_str = format!("{}/v2/loyalty/programs/{program_id}", configuration.base_path, program_id=crate::apis::urlencode(p_program_id));
654    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
655
656    if let Some(ref user_agent) = configuration.user_agent {
657        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
658    }
659    if let Some(ref token) = configuration.oauth_access_token {
660        req_builder = req_builder.bearer_auth(token.to_owned());
661    };
662
663    let req = req_builder.build()?;
664    let resp = configuration.client.execute(req).await?;
665
666    let status = resp.status();
667    let content_type = resp
668        .headers()
669        .get("content-type")
670        .and_then(|v| v.to_str().ok())
671        .unwrap_or("application/octet-stream");
672    let content_type = super::ContentType::from(content_type);
673
674    if !status.is_client_error() && !status.is_server_error() {
675        let content = resp.text().await?;
676        match content_type {
677            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
678            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveLoyaltyProgramResponse`"))),
679            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::RetrieveLoyaltyProgramResponse`")))),
680        }
681    } else {
682        let content = resp.text().await?;
683        let entity: Option<RetrieveLoyaltyProgramError> = serde_json::from_str(&content).ok();
684        Err(Error::ResponseError(ResponseContent { status, content, entity }))
685    }
686}
687
688/// Retrieves a loyalty promotion.
689pub async fn retrieve_loyalty_promotion(configuration: &configuration::Configuration, promotion_id: &str, program_id: &str) -> Result<models::RetrieveLoyaltyPromotionResponse, Error<RetrieveLoyaltyPromotionError>> {
690    // add a prefix to parameters to efficiently prevent name collisions
691    let p_promotion_id = promotion_id;
692    let p_program_id = program_id;
693
694    let uri_str = format!("{}/v2/loyalty/programs/{program_id}/promotions/{promotion_id}", configuration.base_path, promotion_id=crate::apis::urlencode(p_promotion_id), program_id=crate::apis::urlencode(p_program_id));
695    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
696
697    if let Some(ref user_agent) = configuration.user_agent {
698        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
699    }
700    if let Some(ref token) = configuration.oauth_access_token {
701        req_builder = req_builder.bearer_auth(token.to_owned());
702    };
703
704    let req = req_builder.build()?;
705    let resp = configuration.client.execute(req).await?;
706
707    let status = resp.status();
708    let content_type = resp
709        .headers()
710        .get("content-type")
711        .and_then(|v| v.to_str().ok())
712        .unwrap_or("application/octet-stream");
713    let content_type = super::ContentType::from(content_type);
714
715    if !status.is_client_error() && !status.is_server_error() {
716        let content = resp.text().await?;
717        match content_type {
718            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
719            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveLoyaltyPromotionResponse`"))),
720            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::RetrieveLoyaltyPromotionResponse`")))),
721        }
722    } else {
723        let content = resp.text().await?;
724        let entity: Option<RetrieveLoyaltyPromotionError> = serde_json::from_str(&content).ok();
725        Err(Error::ResponseError(ResponseContent { status, content, entity }))
726    }
727}
728
729/// Retrieves a loyalty reward.
730pub async fn retrieve_loyalty_reward(configuration: &configuration::Configuration, reward_id: &str) -> Result<models::RetrieveLoyaltyRewardResponse, Error<RetrieveLoyaltyRewardError>> {
731    // add a prefix to parameters to efficiently prevent name collisions
732    let p_reward_id = reward_id;
733
734    let uri_str = format!("{}/v2/loyalty/rewards/{reward_id}", configuration.base_path, reward_id=crate::apis::urlencode(p_reward_id));
735    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
736
737    if let Some(ref user_agent) = configuration.user_agent {
738        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
739    }
740    if let Some(ref token) = configuration.oauth_access_token {
741        req_builder = req_builder.bearer_auth(token.to_owned());
742    };
743
744    let req = req_builder.build()?;
745    let resp = configuration.client.execute(req).await?;
746
747    let status = resp.status();
748    let content_type = resp
749        .headers()
750        .get("content-type")
751        .and_then(|v| v.to_str().ok())
752        .unwrap_or("application/octet-stream");
753    let content_type = super::ContentType::from(content_type);
754
755    if !status.is_client_error() && !status.is_server_error() {
756        let content = resp.text().await?;
757        match content_type {
758            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
759            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveLoyaltyRewardResponse`"))),
760            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::RetrieveLoyaltyRewardResponse`")))),
761        }
762    } else {
763        let content = resp.text().await?;
764        let entity: Option<RetrieveLoyaltyRewardError> = serde_json::from_str(&content).ok();
765        Err(Error::ResponseError(ResponseContent { status, content, entity }))
766    }
767}
768
769/// Searches for loyalty accounts in a loyalty program.  You can search for a loyalty account using the phone number or customer ID associated with the account. To return all loyalty accounts, specify an empty `query` object or omit it entirely.  Search results are sorted by `created_at` in ascending order.
770pub async fn search_loyalty_accounts(configuration: &configuration::Configuration, search_loyalty_accounts_request: models::SearchLoyaltyAccountsRequest) -> Result<models::SearchLoyaltyAccountsResponse, Error<SearchLoyaltyAccountsError>> {
771    // add a prefix to parameters to efficiently prevent name collisions
772    let p_search_loyalty_accounts_request = search_loyalty_accounts_request;
773
774    let uri_str = format!("{}/v2/loyalty/accounts/search", configuration.base_path);
775    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
776
777    if let Some(ref user_agent) = configuration.user_agent {
778        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
779    }
780    if let Some(ref token) = configuration.oauth_access_token {
781        req_builder = req_builder.bearer_auth(token.to_owned());
782    };
783    req_builder = req_builder.json(&p_search_loyalty_accounts_request);
784
785    let req = req_builder.build()?;
786    let resp = configuration.client.execute(req).await?;
787
788    let status = resp.status();
789    let content_type = resp
790        .headers()
791        .get("content-type")
792        .and_then(|v| v.to_str().ok())
793        .unwrap_or("application/octet-stream");
794    let content_type = super::ContentType::from(content_type);
795
796    if !status.is_client_error() && !status.is_server_error() {
797        let content = resp.text().await?;
798        match content_type {
799            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
800            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchLoyaltyAccountsResponse`"))),
801            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::SearchLoyaltyAccountsResponse`")))),
802        }
803    } else {
804        let content = resp.text().await?;
805        let entity: Option<SearchLoyaltyAccountsError> = serde_json::from_str(&content).ok();
806        Err(Error::ResponseError(ResponseContent { status, content, entity }))
807    }
808}
809
810/// Searches for loyalty events.  A Square loyalty program maintains a ledger of events that occur during the lifetime of a buyer's loyalty account. Each change in the point balance (for example, points earned, points redeemed, and points expired) is recorded in the ledger. Using this endpoint, you can search the ledger for events.  Search results are sorted by `created_at` in descending order.
811pub async fn search_loyalty_events(configuration: &configuration::Configuration, search_loyalty_events_request: models::SearchLoyaltyEventsRequest) -> Result<models::SearchLoyaltyEventsResponse, Error<SearchLoyaltyEventsError>> {
812    // add a prefix to parameters to efficiently prevent name collisions
813    let p_search_loyalty_events_request = search_loyalty_events_request;
814
815    let uri_str = format!("{}/v2/loyalty/events/search", configuration.base_path);
816    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
817
818    if let Some(ref user_agent) = configuration.user_agent {
819        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
820    }
821    if let Some(ref token) = configuration.oauth_access_token {
822        req_builder = req_builder.bearer_auth(token.to_owned());
823    };
824    req_builder = req_builder.json(&p_search_loyalty_events_request);
825
826    let req = req_builder.build()?;
827    let resp = configuration.client.execute(req).await?;
828
829    let status = resp.status();
830    let content_type = resp
831        .headers()
832        .get("content-type")
833        .and_then(|v| v.to_str().ok())
834        .unwrap_or("application/octet-stream");
835    let content_type = super::ContentType::from(content_type);
836
837    if !status.is_client_error() && !status.is_server_error() {
838        let content = resp.text().await?;
839        match content_type {
840            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
841            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchLoyaltyEventsResponse`"))),
842            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::SearchLoyaltyEventsResponse`")))),
843        }
844    } else {
845        let content = resp.text().await?;
846        let entity: Option<SearchLoyaltyEventsError> = serde_json::from_str(&content).ok();
847        Err(Error::ResponseError(ResponseContent { status, content, entity }))
848    }
849}
850
851/// Searches for loyalty rewards. This endpoint accepts a request with no query filters and returns results for all loyalty accounts. If you include a `query` object, `loyalty_account_id` is required and `status` is  optional.  If you know a reward ID, use the [RetrieveLoyaltyReward](api-endpoint:Loyalty-RetrieveLoyaltyReward) endpoint.  Search results are sorted by `updated_at` in descending order.
852pub async fn search_loyalty_rewards(configuration: &configuration::Configuration, search_loyalty_rewards_request: models::SearchLoyaltyRewardsRequest) -> Result<models::SearchLoyaltyRewardsResponse, Error<SearchLoyaltyRewardsError>> {
853    // add a prefix to parameters to efficiently prevent name collisions
854    let p_search_loyalty_rewards_request = search_loyalty_rewards_request;
855
856    let uri_str = format!("{}/v2/loyalty/rewards/search", configuration.base_path);
857    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
858
859    if let Some(ref user_agent) = configuration.user_agent {
860        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
861    }
862    if let Some(ref token) = configuration.oauth_access_token {
863        req_builder = req_builder.bearer_auth(token.to_owned());
864    };
865    req_builder = req_builder.json(&p_search_loyalty_rewards_request);
866
867    let req = req_builder.build()?;
868    let resp = configuration.client.execute(req).await?;
869
870    let status = resp.status();
871    let content_type = resp
872        .headers()
873        .get("content-type")
874        .and_then(|v| v.to_str().ok())
875        .unwrap_or("application/octet-stream");
876    let content_type = super::ContentType::from(content_type);
877
878    if !status.is_client_error() && !status.is_server_error() {
879        let content = resp.text().await?;
880        match content_type {
881            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
882            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchLoyaltyRewardsResponse`"))),
883            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::SearchLoyaltyRewardsResponse`")))),
884        }
885    } else {
886        let content = resp.text().await?;
887        let entity: Option<SearchLoyaltyRewardsError> = serde_json::from_str(&content).ok();
888        Err(Error::ResponseError(ResponseContent { status, content, entity }))
889    }
890}
891