mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-11-30 10:12:50 +03:00
chore: update api for billing (#5735)
This commit is contained in:
parent
9668ab20f9
commit
00312f6309
24
frontend/rust-lib/Cargo.lock
generated
24
frontend/rust-lib/Cargo.lock
generated
@ -163,7 +163,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||
[[package]]
|
||||
name = "app-error"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
@ -183,7 +183,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "appflowy-ai-client"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@ -698,7 +698,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "client-api"
|
||||
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 = [
|
||||
"again",
|
||||
"anyhow",
|
||||
@ -748,7 +748,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "client-api-entity"
|
||||
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 = [
|
||||
"collab-entity",
|
||||
"collab-rt-entity",
|
||||
@ -760,7 +760,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "client-websocket"
|
||||
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 = [
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
@ -969,7 +969,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "collab-rt-entity"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
@ -994,7 +994,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "collab-rt-protocol"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@ -1311,7 +1311,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
|
||||
[[package]]
|
||||
name = "database-entity"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"app-error",
|
||||
@ -2618,7 +2618,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gotrue"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"futures-util",
|
||||
@ -2635,7 +2635,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gotrue-entity"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"app-error",
|
||||
@ -3000,7 +3000,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "infra"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@ -5101,7 +5101,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "shared-entity"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"app-error",
|
||||
|
@ -97,8 +97,8 @@ validator = { version = "0.16.1", features = ["derive"] }
|
||||
# Run the script.add_workspace_members:
|
||||
# scripts/tool/update_client_api_rev.sh new_rev_id
|
||||
# ⚠️⚠️⚠️️
|
||||
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e0e7950ae1a3129928120505337c37988bf2235e" }
|
||||
client-api-entity = { 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 = "2a145c2f8c6293bc2da12b8322386ee2731a7c2d" }
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
@ -3,7 +3,8 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use client_api::entity::billing_dto::{
|
||||
RecurringInterval, SubscriptionPlan, WorkspaceSubscriptionStatus, WorkspaceUsageAndLimit,
|
||||
RecurringInterval, SetSubscriptionRecurringInterval, SubscriptionCancelRequest, SubscriptionPlan,
|
||||
WorkspaceSubscriptionStatus, WorkspaceUsageAndLimit,
|
||||
};
|
||||
use client_api::entity::workspace_dto::{
|
||||
CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset, WorkspaceMemberInvitation,
|
||||
@ -554,7 +555,13 @@ where
|
||||
let try_get_client = self.server.try_get_client();
|
||||
FutureResult::new(async move {
|
||||
let client = try_get_client?;
|
||||
client.cancel_subscription(&workspace_id, &plan).await?;
|
||||
client
|
||||
.cancel_subscription(&SubscriptionCancelRequest {
|
||||
workspace_id,
|
||||
plan,
|
||||
sync: true,
|
||||
})
|
||||
.await?;
|
||||
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(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
|
@ -318,6 +318,15 @@ pub trait UserCloudService: Send + Sync + 'static {
|
||||
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(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -841,6 +841,22 @@ pub async fn invalidate_workspace_subscription_info_cache_handler(
|
||||
.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)]
|
||||
pub async fn get_workspace_member_info(
|
||||
param: AFPluginData<WorkspaceMemberIdPB>,
|
||||
|
@ -70,11 +70,12 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
|
||||
.event(UserEvent::AcceptWorkspaceInvitation, accept_workspace_invitations_handler)
|
||||
// Billing
|
||||
.event(UserEvent::SubscribeWorkspace, subscribe_workspace_handler)
|
||||
.event(UserEvent::GetWorkspaceSubscriptionInfo, get_workspace_subscription_info_handler)
|
||||
.event(UserEvent::GetWorkspaceSubscriptionInfo, get_workspace_subscription_info_handler)
|
||||
.event(UserEvent::CancelWorkspaceSubscription, cancel_workspace_subscription_handler)
|
||||
.event(UserEvent::GetWorkspaceUsage, get_workspace_usage_handler)
|
||||
.event(UserEvent::GetBillingPortal, get_billing_portal_handler)
|
||||
.event(UserEvent::InvalidateWorkspaceSubscriptionInfoCache, invalidate_workspace_subscription_info_cache_handler)
|
||||
.event(UserEvent::UpdateWorkspaceSubscriptionPaymentPeriod, update_workspace_subscription_payment_period_handler)
|
||||
// Workspace Setting
|
||||
.event(UserEvent::UpdateWorkspaceSetting, update_workspace_setting)
|
||||
.event(UserEvent::GetWorkspaceSetting, get_workspace_setting)
|
||||
@ -265,6 +266,9 @@ pub enum UserEvent {
|
||||
|
||||
#[event(input = "UserWorkspaceIdPB")]
|
||||
InvalidateWorkspaceSubscriptionInfoCache = 60,
|
||||
|
||||
#[event(input = "UpdateWorkspaceSubscriptionPaymentPeriodPB")]
|
||||
UpdateWorkspaceSubscriptionPaymentPeriod = 61,
|
||||
}
|
||||
|
||||
pub trait UserStatusCallback: Send + Sync + 'static {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use chrono::{Duration, NaiveDateTime, Utc};
|
||||
use client_api::entity::billing_dto::RecurringInterval;
|
||||
use client_api::entity::billing_dto::{SubscriptionPlan, WorkspaceUsageAndLimit};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
@ -523,6 +524,21 @@ impl UserManager {
|
||||
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)]
|
||||
pub async fn get_workspace_usage(
|
||||
&self,
|
||||
|
Loading…
Reference in New Issue
Block a user