Merge pull request #684 from AppFlowy-IO/billing-support
Billing support
This commit is contained in:
commit
ebaf395092
|
|
@ -161,4 +161,25 @@ impl Client {
|
||||||
.await?
|
.await?
|
||||||
.into_data()
|
.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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)]
|
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum SubscriptionStatus {
|
pub enum SubscriptionStatus {
|
||||||
|
|
@ -80,17 +95,18 @@ pub enum SubscriptionStatus {
|
||||||
Unpaid,
|
Unpaid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct WorkspaceSubscriptionStatus {
|
pub struct WorkspaceSubscriptionStatus {
|
||||||
pub workspace_id: String,
|
pub workspace_id: String,
|
||||||
pub workspace_plan: SubscriptionPlan,
|
pub workspace_plan: SubscriptionPlan,
|
||||||
pub recurring_interval: RecurringInterval,
|
pub recurring_interval: RecurringInterval,
|
||||||
pub subscription_status: SubscriptionStatus,
|
pub subscription_status: SubscriptionStatus,
|
||||||
pub subscription_quantity: u64,
|
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 struct WorkspaceUsageAndLimit {
|
||||||
pub member_count: i64,
|
pub member_count: i64,
|
||||||
pub member_count_limit: i64,
|
pub member_count_limit: i64,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue