diff --git a/libs/client-api/src/http_billing.rs b/libs/client-api/src/http_billing.rs index 3b36fad0..0b286ad7 100644 --- a/libs/client-api/src/http_billing.rs +++ b/libs/client-api/src/http_billing.rs @@ -1,7 +1,8 @@ use crate::Client; -use client_api_entity::billing_dto::WorkspaceUsageAndLimit; +use client_api_entity::billing_dto::{ + SetSubscriptionRecurringInterval, SubscriptionCancelRequest, WorkspaceUsageAndLimit, +}; use reqwest::Method; -use serde_json::json; use shared_entity::{ dto::billing_dto::{RecurringInterval, SubscriptionPlan, WorkspaceSubscriptionStatus}, response::{AppResponse, AppResponseError}, @@ -68,8 +69,7 @@ impl Client { pub async fn cancel_subscription( &self, - workspace_id: &str, - plan: &SubscriptionPlan, + req: &SubscriptionCancelRequest, ) -> Result<(), AppResponseError> { let url = format!( "{}/billing/api/v1/cancel-subscription", @@ -78,10 +78,7 @@ impl Client { let resp = self .http_client_with_auth(Method::POST, &url) .await? - .json(&json!({ - "workspace_id": workspace_id, - "plan": plan.as_ref(), - })) + .json(req) .send() .await?; AppResponse::<()>::from_response(resp).await?.into_error() @@ -182,4 +179,23 @@ impl Client { .await? .into_data() } + + /// Set subscription recurring interval + pub async fn set_subscription_recurring_interval( + &self, + set_sub_recur: &SetSubscriptionRecurringInterval, + ) -> Result<(), AppResponseError> { + let url = format!( + "{}/billing/api/v1/subscription-recurring-interval", + self.base_billing_url(), + ); + let resp = self + .http_client_with_auth(Method::POST, &url) + .await? + .json(set_sub_recur) + .send() + .await?; + + AppResponse::<()>::from_response(resp).await?.into_error() + } } diff --git a/libs/shared-entity/src/dto/billing_dto.rs b/libs/shared-entity/src/dto/billing_dto.rs index 1ce62c49..5eb65198 100644 --- a/libs/shared-entity/src/dto/billing_dto.rs +++ b/libs/shared-entity/src/dto/billing_dto.rs @@ -106,7 +106,7 @@ pub struct WorkspaceSubscriptionStatus { pub current_period_end: i64, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct WorkspaceUsageAndLimit { pub member_count: i64, pub member_count_limit: i64, @@ -119,3 +119,17 @@ pub struct WorkspaceUsageAndLimit { pub local_ai: bool, pub ai_responses_unlimited: bool, } + +#[derive(Serialize, Deserialize, Debug)] +pub struct SubscriptionCancelRequest { + pub workspace_id: String, + pub plan: SubscriptionPlan, + pub sync: bool, // if true, this request will block until stripe has sent the cancelation webhook +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct SetSubscriptionRecurringInterval { + pub workspace_id: String, + pub plan: SubscriptionPlan, + pub recurring_interval: RecurringInterval, +}