From 8a2ba59ce80f915c282c94fd26ee148fbbd93a3a Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Mon, 8 Jul 2024 01:27:41 +0800 Subject: [PATCH] chore: add more param for plan cancellation --- libs/client-api/src/http_billing.rs | 13 ++++++-- libs/shared-entity/src/dto/billing_dto.rs | 36 +++++++++++------------ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/libs/client-api/src/http_billing.rs b/libs/client-api/src/http_billing.rs index f767214c..cb74b132 100644 --- a/libs/client-api/src/http_billing.rs +++ b/libs/client-api/src/http_billing.rs @@ -54,7 +54,7 @@ impl Client { ("recurring_interval", recurring_interval.as_str()), ( "workspace_subscription_plan", - workspace_subscription_plan.as_str(), + workspace_subscription_plan.as_ref(), ), ("success_url", success_url), ]) @@ -66,7 +66,11 @@ impl Client { .into_data() } - pub async fn cancel_subscription(&self, workspace_id: &str) -> Result<(), AppResponseError> { + pub async fn cancel_subscription( + &self, + workspace_id: &str, + plan: &SubscriptionPlan, + ) -> Result<(), AppResponseError> { let url = format!( "{}/billing/api/v1/cancel-subscription", self.base_billing_url() @@ -74,7 +78,10 @@ impl Client { let resp = self .http_client_with_auth(Method::POST, &url) .await? - .json(&json!({ "workspace_id": workspace_id })) + .json(&json!({ + "workspace_id": workspace_id, + "plan": plan.as_ref(), + })) .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 27ae5f03..a406fb81 100644 --- a/libs/shared-entity/src/dto/billing_dto.rs +++ b/libs/shared-entity/src/dto/billing_dto.rs @@ -16,31 +16,31 @@ impl RecurringInterval { } } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] -#[serde(rename_all = "snake_case")] -pub enum SubscriptionPlan { - Pro, - Team, -} - -impl SubscriptionPlan { - pub fn as_str(&self) -> &str { - match self { - SubscriptionPlan::Pro => "pro", - SubscriptionPlan::Team => "team", - } - } -} - #[derive(Deserialize, Debug)] #[serde(rename_all = "snake_case")] #[repr(i16)] -pub enum WorkspaceSubscriptionPlan { +pub enum SubscriptionPlan { Unknown = -1, Free = 0, Pro = 1, Team = 2, + + AIMax = 3, + AILocal = 4, +} + +impl AsRef for SubscriptionPlan { + fn as_ref(&self) -> &str { + match self { + SubscriptionPlan::Free => "free", + SubscriptionPlan::Pro => "pro", + SubscriptionPlan::Team => "team", + SubscriptionPlan::AIMax => "ai_max", + SubscriptionPlan::AILocal => "ai_local", + SubscriptionPlan::Unknown => "unknown", + } + } } #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] @@ -59,7 +59,7 @@ pub enum SubscriptionStatus { #[derive(Deserialize, Debug)] pub struct WorkspaceSubscriptionStatus { pub workspace_id: String, - pub workspace_plan: WorkspaceSubscriptionPlan, + pub workspace_plan: SubscriptionPlan, pub recurring_interval: RecurringInterval, pub subscription_status: SubscriptionStatus, pub subscription_quantity: u64,