use crate::client::{Client, Response};
use crate::ids::CustomerId;
use crate::params::{Expand, Expandable, Object, Timestamp};
use crate::resources::Customer;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CustomerSession {
pub client_secret: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub components: Option<CustomerSessionResourceComponents>,
pub created: Timestamp,
pub customer: Expandable<Customer>,
pub expires_at: Timestamp,
pub livemode: bool,
}
impl CustomerSession {
pub fn create(client: &Client, params: CreateCustomerSession<'_>) -> Response<CustomerSession> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/customer_sessions", ¶ms)
}
}
impl Object for CustomerSession {
type Id = ();
fn id(&self) -> Self::Id {}
fn object(&self) -> &'static str {
"customer_session"
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CustomerSessionResourceComponents {
pub buy_button: CustomerSessionResourceComponentsResourceBuyButton,
pub pricing_table: CustomerSessionResourceComponentsResourcePricingTable,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CustomerSessionResourceComponentsResourceBuyButton {
pub enabled: bool,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CustomerSessionResourceComponentsResourcePricingTable {
pub enabled: bool,
}
#[derive(Clone, Debug, Serialize)]
pub struct CreateCustomerSession<'a> {
pub components: CreateCustomerSessionComponents,
pub customer: CustomerId,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
}
impl<'a> CreateCustomerSession<'a> {
pub fn new(components: CreateCustomerSessionComponents, customer: CustomerId) -> Self {
CreateCustomerSession { components, customer, expand: Default::default() }
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreateCustomerSessionComponents {
#[serde(skip_serializing_if = "Option::is_none")]
pub buy_button: Option<CreateCustomerSessionComponentsBuyButton>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pricing_table: Option<CreateCustomerSessionComponentsPricingTable>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreateCustomerSessionComponentsBuyButton {
pub enabled: bool,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreateCustomerSessionComponentsPricingTable {
pub enabled: bool,
}