#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CheckoutSessionsListOptions {
pub customer_id: Option<CustomerId>,
pub status: Option<CheckoutSessionStatus>,
}
impl CheckoutSessionsListOptions {
#[must_use]
pub fn new() -> Self {
Self {
customer_id: None,
status: None,
}
}
#[must_use]
pub fn customer_id(mut self, customer_id: impl Into<CustomerId>) -> Self {
self.customer_id = Some(customer_id.into());
self
}
#[must_use]
pub fn maybe_customer_id(mut self, customer_id: Option<CustomerId>) -> Self {
self.customer_id = customer_id;
self
}
#[must_use]
pub fn status(mut self, status: impl Into<CheckoutSessionStatus>) -> Self {
self.status = Some(status.into());
self
}
#[must_use]
pub fn maybe_status(mut self, status: Option<CheckoutSessionStatus>) -> Self {
self.status = status;
self
}
}
#[derive(Clone)]
pub struct CheckoutSessions {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for CheckoutSessions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CheckoutSessions")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl CheckoutSessions {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
pub fn list(
&self,
options: impl Into<Option<CheckoutSessionsListOptions>>,
) -> crate::api::Call<crate::models::ListCheckoutSessionsResponse> {
let CheckoutSessionsListOptions {
customer_id,
status,
} = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/checkout-sessions")
.with_optional_query_param("customer_id", customer_id)
.with_optional_query_param("status", status)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn create(
&self,
create_checkout_session_request: crate::models::CreateCheckoutSessionRequest,
) -> crate::api::Call<crate::models::CreateCheckoutSessionResponse> {
crate::request::Request::new(http::Method::POST, "/api/v1/checkout-sessions")
.with_body_param(create_checkout_session_request)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn retrieve(
&self,
id: impl Into<crate::models::CheckoutSessionId>,
) -> crate::api::Call<crate::models::GetCheckoutSessionResponse> {
crate::request::Request::new(http::Method::GET, "/api/v1/checkout-sessions/{id}")
.with_path_param("id", Into::<crate::models::CheckoutSessionId>::into(id))
.with_options(&self.options)
.json(&self.cfg)
}
pub fn cancel(
&self,
id: impl Into<crate::models::CheckoutSessionId>,
) -> crate::api::Call<crate::models::CancelCheckoutSessionResponse> {
crate::request::Request::new(http::Method::POST, "/api/v1/checkout-sessions/{id}/cancel")
.with_path_param("id", Into::<crate::models::CheckoutSessionId>::into(id))
.with_options(&self.options)
.json(&self.cfg)
}
}