chore: update api for billing (#5735)

This commit is contained in:
Zack 2024-07-15 22:00:19 +08:00 committed by GitHub
parent 9668ab20f9
commit 00312f6309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 102 additions and 17 deletions

View File

@ -163,7 +163,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]] [[package]]
name = "app-error" name = "app-error"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -183,7 +183,7 @@ dependencies = [
[[package]] [[package]]
name = "appflowy-ai-client" name = "appflowy-ai-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -698,7 +698,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api" name = "client-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"again", "again",
"anyhow", "anyhow",
@ -748,7 +748,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api-entity" name = "client-api-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"collab-entity", "collab-entity",
"collab-rt-entity", "collab-rt-entity",
@ -760,7 +760,7 @@ dependencies = [
[[package]] [[package]]
name = "client-websocket" name = "client-websocket"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
@ -969,7 +969,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-entity" name = "collab-rt-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -994,7 +994,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-protocol" name = "collab-rt-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1311,7 +1311,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]] [[package]]
name = "database-entity" name = "database-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -2618,7 +2618,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue" name = "gotrue"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures-util", "futures-util",
@ -2635,7 +2635,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue-entity" name = "gotrue-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3000,7 +3000,7 @@ dependencies = [
[[package]] [[package]]
name = "infra" name = "infra"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -5101,7 +5101,7 @@ dependencies = [
[[package]] [[package]]
name = "shared-entity" name = "shared-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e0e7950ae1a3129928120505337c37988bf2235e#e0e7950ae1a3129928120505337c37988bf2235e" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=2a145c2f8c6293bc2da12b8322386ee2731a7c2d#2a145c2f8c6293bc2da12b8322386ee2731a7c2d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",

View File

@ -97,8 +97,8 @@ validator = { version = "0.16.1", features = ["derive"] }
# Run the script.add_workspace_members: # Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id # scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️ # ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e0e7950ae1a3129928120505337c37988bf2235e" } client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "2a145c2f8c6293bc2da12b8322386ee2731a7c2d" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e0e7950ae1a3129928120505337c37988bf2235e" } client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "2a145c2f8c6293bc2da12b8322386ee2731a7c2d" }
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1

View File

@ -3,7 +3,8 @@ use std::sync::Arc;
use anyhow::anyhow; use anyhow::anyhow;
use client_api::entity::billing_dto::{ use client_api::entity::billing_dto::{
RecurringInterval, SubscriptionPlan, WorkspaceSubscriptionStatus, WorkspaceUsageAndLimit, RecurringInterval, SetSubscriptionRecurringInterval, SubscriptionCancelRequest, SubscriptionPlan,
WorkspaceSubscriptionStatus, WorkspaceUsageAndLimit,
}; };
use client_api::entity::workspace_dto::{ use client_api::entity::workspace_dto::{
CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset, WorkspaceMemberInvitation, CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset, WorkspaceMemberInvitation,
@ -554,7 +555,13 @@ where
let try_get_client = self.server.try_get_client(); let try_get_client = self.server.try_get_client();
FutureResult::new(async move { FutureResult::new(async move {
let client = try_get_client?; let client = try_get_client?;
client.cancel_subscription(&workspace_id, &plan).await?; client
.cancel_subscription(&SubscriptionCancelRequest {
workspace_id,
plan,
sync: true,
})
.await?;
Ok(()) Ok(())
}) })
} }
@ -580,6 +587,26 @@ where
}) })
} }
fn update_workspace_subscription_payment_period(
&self,
workspace_id: String,
plan: SubscriptionPlan,
recurring_interval: RecurringInterval,
) -> FutureResult<(), FlowyError> {
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
client
.set_subscription_recurring_interval(&SetSubscriptionRecurringInterval {
workspace_id,
plan,
recurring_interval,
})
.await?;
Ok(())
})
}
fn get_workspace_setting( fn get_workspace_setting(
&self, &self,
workspace_id: &str, workspace_id: &str,

View File

@ -318,6 +318,15 @@ pub trait UserCloudService: Send + Sync + 'static {
FutureResult::new(async { Err(FlowyError::not_support()) }) FutureResult::new(async { Err(FlowyError::not_support()) })
} }
fn update_workspace_subscription_payment_period(
&self,
workspace_id: String,
plan: SubscriptionPlan,
recurring_interval: RecurringInterval,
) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Err(FlowyError::not_support()) })
}
fn get_workspace_setting( fn get_workspace_setting(
&self, &self,
workspace_id: &str, workspace_id: &str,

View File

@ -662,3 +662,16 @@ impl From<i64> for WorkspaceSubscriptionStatusPB {
} }
} }
} }
#[derive(ProtoBuf, Default, Clone, Validate)]
pub struct UpdateWorkspaceSubscriptionPaymentPeriodPB {
#[pb(index = 1)]
#[validate(custom = "required_not_empty_str")]
pub workspace_id: String,
#[pb(index = 2)]
pub plan: SubscriptionPlanPB,
#[pb(index = 3)]
pub recurring_interval: RecurringIntervalPB,
}

View File

@ -841,6 +841,22 @@ pub async fn invalidate_workspace_subscription_info_cache_handler(
.await .await
} }
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn update_workspace_subscription_payment_period_handler(
params: AFPluginData<UpdateWorkspaceSubscriptionPaymentPeriodPB>,
manager: AFPluginState<Weak<UserManager>>,
) -> FlowyResult<()> {
let params = params.try_into_inner().unwrap();
let manager = upgrade_manager(manager).unwrap();
manager
.update_workspace_subscription_payment_period(
params.workspace_id,
params.plan.into(),
params.recurring_interval.into(),
)
.await
}
#[tracing::instrument(level = "debug", skip_all, err)] #[tracing::instrument(level = "debug", skip_all, err)]
pub async fn get_workspace_member_info( pub async fn get_workspace_member_info(
param: AFPluginData<WorkspaceMemberIdPB>, param: AFPluginData<WorkspaceMemberIdPB>,

View File

@ -75,6 +75,7 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::GetWorkspaceUsage, get_workspace_usage_handler) .event(UserEvent::GetWorkspaceUsage, get_workspace_usage_handler)
.event(UserEvent::GetBillingPortal, get_billing_portal_handler) .event(UserEvent::GetBillingPortal, get_billing_portal_handler)
.event(UserEvent::InvalidateWorkspaceSubscriptionInfoCache, invalidate_workspace_subscription_info_cache_handler) .event(UserEvent::InvalidateWorkspaceSubscriptionInfoCache, invalidate_workspace_subscription_info_cache_handler)
.event(UserEvent::UpdateWorkspaceSubscriptionPaymentPeriod, update_workspace_subscription_payment_period_handler)
// Workspace Setting // Workspace Setting
.event(UserEvent::UpdateWorkspaceSetting, update_workspace_setting) .event(UserEvent::UpdateWorkspaceSetting, update_workspace_setting)
.event(UserEvent::GetWorkspaceSetting, get_workspace_setting) .event(UserEvent::GetWorkspaceSetting, get_workspace_setting)
@ -265,6 +266,9 @@ pub enum UserEvent {
#[event(input = "UserWorkspaceIdPB")] #[event(input = "UserWorkspaceIdPB")]
InvalidateWorkspaceSubscriptionInfoCache = 60, InvalidateWorkspaceSubscriptionInfoCache = 60,
#[event(input = "UpdateWorkspaceSubscriptionPaymentPeriodPB")]
UpdateWorkspaceSubscriptionPaymentPeriod = 61,
} }
pub trait UserStatusCallback: Send + Sync + 'static { pub trait UserStatusCallback: Send + Sync + 'static {

View File

@ -1,4 +1,5 @@
use chrono::{Duration, NaiveDateTime, Utc}; use chrono::{Duration, NaiveDateTime, Utc};
use client_api::entity::billing_dto::RecurringInterval;
use client_api::entity::billing_dto::{SubscriptionPlan, WorkspaceUsageAndLimit}; use client_api::entity::billing_dto::{SubscriptionPlan, WorkspaceUsageAndLimit};
use std::convert::TryFrom; use std::convert::TryFrom;
@ -523,6 +524,21 @@ impl UserManager {
delete_workspace_subscription_from_cache(db, &workspace_id) delete_workspace_subscription_from_cache(db, &workspace_id)
} }
#[instrument(level = "info", skip(self), err)]
pub async fn update_workspace_subscription_payment_period(
&self,
workspace_id: String,
plan: SubscriptionPlan,
recurring_interval: RecurringInterval,
) -> FlowyResult<()> {
self
.cloud_services
.get_user_service()?
.update_workspace_subscription_payment_period(workspace_id, plan, recurring_interval)
.await?;
Ok(())
}
#[instrument(level = "info", skip(self), err)] #[instrument(level = "info", skip(self), err)]
pub async fn get_workspace_usage( pub async fn get_workspace_usage(
&self, &self,