Merge pull request #684 from AppFlowy-IO/billing-support

Billing support
This commit is contained in:
Zack 2024-07-11 10:18:59 +08:00 committed by GitHub
commit ebaf395092
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 3 deletions

View File

@ -161,4 +161,25 @@ impl Client {
.await?
.into_data()
}
/// Query all active subscription, minimal information but faster
pub async fn get_active_workspace_subscriptions(
&self,
workspace_id: &str,
) -> Result<Vec<SubscriptionPlan>, AppResponseError> {
let url = format!(
"{}/billing/api/v1/active-subscription/{}",
self.base_billing_url(),
workspace_id
);
let resp = self
.http_client_with_auth(Method::GET, &url)
.await?
.send()
.await?;
AppResponse::<Vec<SubscriptionPlan>>::from_response(resp)
.await?
.into_data()
}
}

View File

@ -67,6 +67,21 @@ impl AsRef<str> for SubscriptionPlan {
}
}
impl TryFrom<&str> for SubscriptionPlan {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"free" => Ok(SubscriptionPlan::Free),
"pro" => Ok(SubscriptionPlan::Pro),
"team" => Ok(SubscriptionPlan::Team),
"ai_max" => Ok(SubscriptionPlan::AiMax),
"ai_local" => Ok(SubscriptionPlan::AiLocal),
_ => Err(format!("Invalid SubscriptionPlan value: {}", value)),
}
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SubscriptionStatus {
@ -80,17 +95,18 @@ pub enum SubscriptionStatus {
Unpaid,
}
#[derive(Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WorkspaceSubscriptionStatus {
pub workspace_id: String,
pub workspace_plan: SubscriptionPlan,
pub recurring_interval: RecurringInterval,
pub subscription_status: SubscriptionStatus,
pub subscription_quantity: u64,
pub canceled_at: Option<i64>,
pub cancel_at: Option<i64>,
pub current_period_end: i64,
}
#[derive(Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct WorkspaceUsageAndLimit {
pub member_count: i64,
pub member_count_limit: i64,