square_api_client/api/
gift_cards_api.rs1use crate::{
11 config::Configuration,
12 http::client::HttpClient,
13 models::{
14 errors::ApiError, CreateGiftCardRequest, CreateGiftCardResponse,
15 LinkCustomerToGiftCardRequest, LinkCustomerToGiftCardResponse, ListGiftCardsParameters,
16 ListGiftCardsResponse, RetrieveGiftCardFromGANRequest, RetrieveGiftCardFromGANResponse,
17 RetrieveGiftCardFromNonceRequest, RetrieveGiftCardFromNonceResponse,
18 RetrieveGiftCardResponse, UnlinkCustomerFromGiftCardRequest,
19 UnlinkCustomerFromGiftCardResponse,
20 },
21};
22
23const DEFAULT_URI: &str = "/gift-cards";
24
25pub struct GiftCardsApi {
26 config: Configuration,
28 client: HttpClient,
30}
31
32impl GiftCardsApi {
33 pub fn new(config: Configuration, client: HttpClient) -> Self {
35 Self { config, client }
36 }
37
38 pub async fn list_gift_cards(
43 &self,
44 params: &ListGiftCardsParameters,
45 ) -> Result<ListGiftCardsResponse, ApiError> {
46 let url = format!("{}{}", &self.url(), params.to_query_string());
47 let response = self.client.get(&url).await?;
48
49 response.deserialize().await
50 }
51
52 pub async fn create_gift_card(
58 &self,
59 body: &CreateGiftCardRequest,
60 ) -> Result<CreateGiftCardResponse, ApiError> {
61 let response = self.client.post(&self.url(), body).await?;
62
63 response.deserialize().await
64 }
65
66 pub async fn retrieve_gift_card_from_gan(
68 &self,
69 body: &RetrieveGiftCardFromGANRequest,
70 ) -> Result<RetrieveGiftCardFromGANResponse, ApiError> {
71 let url = format!("{}/from-gan", &self.url());
72 let response = self.client.post(&url, body).await?;
73
74 response.deserialize().await
75 }
76
77 pub async fn retrieve_gift_card_from_nonce(
79 &self,
80 body: &RetrieveGiftCardFromNonceRequest,
81 ) -> Result<RetrieveGiftCardFromNonceResponse, ApiError> {
82 let url = format!("{}/from-nonce", &self.url());
83 let response = self.client.post(&url, body).await?;
84
85 response.deserialize().await
86 }
87
88 pub async fn link_customer_to_gift_card(
92 &self,
93 gift_card_id: &str,
94 body: &LinkCustomerToGiftCardRequest,
95 ) -> Result<LinkCustomerToGiftCardResponse, ApiError> {
96 let url = format!("{}/{}/link-customer", &self.url(), gift_card_id);
97 let response = self.client.post(&url, body).await?;
98
99 response.deserialize().await
100 }
101
102 pub async fn unlink_customer_from_gift_card(
106 &self,
107 gift_card_id: &str,
108 body: &UnlinkCustomerFromGiftCardRequest,
109 ) -> Result<UnlinkCustomerFromGiftCardResponse, ApiError> {
110 let url = format!("{}/{}/unlink-customer", &self.url(), gift_card_id);
111 let response = self.client.post(&url, body).await?;
112
113 response.deserialize().await
114 }
115
116 pub async fn retrieve_gift_card(&self, id: &str) -> Result<RetrieveGiftCardResponse, ApiError> {
120 let url = format!("{}/{}", &self.url(), id);
121 let response = self.client.get(&url).await?;
122
123 response.deserialize().await
124 }
125
126 fn url(&self) -> String {
129 format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
130 }
131}