use crate::models::{
ListPaymentLinkResponse, ListPaymentLinksParameters, RetrieveLocationSettingsResponse,
RetrieveMerchantSettingsResponse, RetrievePaymentLinkResponse, UpdateLocationSettingsRequest,
UpdateLocationSettingsResponse, UpdateMerchantSettingsRequest, UpdateMerchantSettingsResponse,
UpdatePaymentLinkRequest, UpdatePaymentLinkResponse,
};
use crate::{
SquareClient,
config::Configuration,
http::client::HttpClient,
models::{
CreatePaymentLinkRequest, CreatePaymentLinkResponse, DeletePaymentLinkResponse,
errors::SquareApiError,
},
};
const DEFAULT_URI: &str = "/online-checkout";
pub struct CheckoutApi {
config: Configuration,
client: HttpClient,
}
impl CheckoutApi {
pub fn new(square_client: SquareClient) -> Self {
Self {
config: square_client.config,
client: square_client.http_client,
}
}
pub async fn retrieve_location_settings(
&self,
location_id: impl AsRef<str>,
) -> Result<RetrieveLocationSettingsResponse, SquareApiError> {
let url = format!("{}/location-settings/{}", &self.url(), location_id.as_ref());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn update_location_settings(
&self,
location_id: impl AsRef<str>,
body: &UpdateLocationSettingsRequest,
) -> Result<UpdateLocationSettingsResponse, SquareApiError> {
let url = format!("{}/location-settings/{}", &self.url(), location_id.as_ref());
let response = self.client.put(&url, body).await?;
response.deserialize().await
}
pub async fn retrieve_merchant_settings(
&self,
) -> Result<RetrieveMerchantSettingsResponse, SquareApiError> {
let url = format!("{}/merchant-settings", &self.url());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn update_merchant_settings(
&self,
body: &UpdateMerchantSettingsRequest,
) -> Result<UpdateMerchantSettingsResponse, SquareApiError> {
let url = format!("{}/merchant-settings", &self.url());
let response = self.client.put(&url, body).await?;
response.deserialize().await
}
pub async fn list_payment_links(
&self,
params: &ListPaymentLinksParameters,
) -> Result<ListPaymentLinkResponse, SquareApiError> {
let url = format!("{}/payment-links{}", &self.url(), params.to_query_string());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn create_payment_link(
&self,
body: &CreatePaymentLinkRequest,
) -> Result<CreatePaymentLinkResponse, SquareApiError> {
let url = format!("{}/payment-links", &self.url());
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn delete_payment_link(
&self,
id: impl AsRef<str>,
) -> Result<DeletePaymentLinkResponse, SquareApiError> {
let url = format!("{}/payment-links/{}", &self.url(), id.as_ref());
let response = self.client.delete(&url).await?;
response.deserialize().await
}
pub async fn retrieve_payment_link(
&self,
id: impl AsRef<str>,
) -> Result<RetrievePaymentLinkResponse, SquareApiError> {
let url = format!("{}/payment-links/{}", &self.url(), id.as_ref());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn update_payment_link(
&self,
id: impl AsRef<str>,
body: &UpdatePaymentLinkRequest,
) -> Result<UpdatePaymentLinkResponse, SquareApiError> {
let url = format!("{}/payment-links/{}", &self.url(), id.as_ref());
let response = self.client.put(&url, body).await?;
response.deserialize().await
}
fn url(&self) -> String {
format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
}
}