feat: billing client

This commit is contained in:
Zack Fu Zi Xiang 2024-05-07 14:09:57 +08:00
parent dc813d85a8
commit 4b00f9f298
No known key found for this signature in database
6 changed files with 91 additions and 9 deletions

View File

@ -180,6 +180,19 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "appflowy-cloud-billing-client"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud-Billing-Client?rev=b95d520d5c570c85cb5e0fd2980220deea41df2b#b95d520d5c570c85cb5e0fd2980220deea41df2b"
dependencies = [
"client-api",
"reqwest",
"serde",
"serde_json",
"shared-entity",
"tokio",
]
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "1.7.1" version = "1.7.1"
@ -1149,7 +1162,7 @@ dependencies = [
"cssparser-macros", "cssparser-macros",
"dtoa-short", "dtoa-short",
"itoa", "itoa",
"phf 0.8.0", "phf 0.11.2",
"smallvec", "smallvec",
] ]
@ -2005,6 +2018,7 @@ name = "flowy-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"appflowy-cloud-billing-client",
"assert-json-diff", "assert-json-diff",
"bytes", "bytes",
"chrono", "chrono",
@ -3718,7 +3732,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
dependencies = [ dependencies = [
"phf_macros", "phf_macros 0.8.0",
"phf_shared 0.8.0", "phf_shared 0.8.0",
"proc-macro-hack", "proc-macro-hack",
] ]
@ -3738,6 +3752,7 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [ dependencies = [
"phf_macros 0.11.2",
"phf_shared 0.11.2", "phf_shared 0.11.2",
] ]
@ -3805,6 +3820,19 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "phf_macros"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
dependencies = [
"phf_generator 0.11.2",
"phf_shared 0.11.2",
"proc-macro2",
"quote",
"syn 2.0.47",
]
[[package]] [[package]]
name = "phf_shared" name = "phf_shared"
version = "0.8.0" version = "0.8.0"
@ -4008,7 +4036,7 @@ checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2"
dependencies = [ dependencies = [
"bytes", "bytes",
"heck 0.4.1", "heck 0.4.1",
"itertools 0.10.5", "itertools 0.11.0",
"log", "log",
"multimap", "multimap",
"once_cell", "once_cell",
@ -4029,7 +4057,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools 0.10.5", "itertools 0.11.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.47", "syn 2.0.47",
@ -5521,9 +5549,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.36.0" version = "1.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",

View File

@ -128,4 +128,5 @@ rocksdb = { git = "https://github.com/LucasXu0/rust-rocksdb", rev = "21cf4a23ec1
# 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 = "47e6f1e8" } client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "47e6f1e8" }
appflowy-cloud-billing-client = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud-Billing-Client", rev = "b95d520d5c570c85cb5e0fd2980220deea41df2b" }

View File

@ -37,6 +37,7 @@ flowy-user-pub = { workspace = true }
flowy-folder-pub = { workspace = true } flowy-folder-pub = { workspace = true }
flowy-database-pub = { workspace = true } flowy-database-pub = { workspace = true }
flowy-document-pub = { workspace = true } flowy-document-pub = { workspace = true }
appflowy-cloud-billing-client = "0.1.0"
flowy-error = { workspace = true, features = ["impl_from_serde", "impl_from_reqwest", "impl_from_url", "impl_from_appflowy_cloud"] } flowy-error = { workspace = true, features = ["impl_from_serde", "impl_from_reqwest", "impl_from_url", "impl_from_appflowy_cloud"] }
flowy-server-pub = { workspace = true } flowy-server-pub = { workspace = true }
flowy-encrypt = { workspace = true } flowy-encrypt = { workspace = true }
@ -49,7 +50,6 @@ lib-dispatch = { workspace = true }
yrs.workspace = true yrs.workspace = true
rand = "0.8.5" rand = "0.8.5"
[dependencies.client-api] [dependencies.client-api]
version = "0.1.0" version = "0.1.0"
features = [ features = [
@ -68,4 +68,4 @@ assert-json-diff = "2.0.2"
serde_json.workspace = true serde_json.workspace = true
[features] [features]
enable_supabase = ["collab-plugins/postgres_plugin"] enable_supabase = ["collab-plugins/postgres_plugin"]

View File

@ -197,3 +197,43 @@ pub struct ChangeWorkspaceIconPB {
#[pb(index = 2)] #[pb(index = 2)]
pub new_icon: String, pub new_icon: String,
} }
#[derive(ProtoBuf, Default, Clone, Validate)]
pub struct WorkspaceSubscriptionLinkPB {
#[pb(index = 1)]
#[validate(custom = "required_not_empty_str")]
pub workspace_id: String,
#[pb(index = 2)]
pub recurring_interval: RecurringIntervalPB,
#[pb(index = 3)]
pub workspace_subscription_plan: SubscriptionPlanPB,
#[pb(index = 4)]
pub success_url: String,
}
#[derive(ProtoBuf_Enum, Clone, Default)]
pub enum RecurringIntervalPB {
#[default]
UndefinedRecurringInterval = 0,
Month = 1,
Year = 2,
}
#[derive(ProtoBuf_Enum, Clone, Default)]
pub enum SubscriptionPlanPB {
#[default]
UndefinedSubscriptionPlan = 0,
Pro = 1,
Team = 2,
}
#[derive(Debug, ProtoBuf, Default, Clone)]
pub struct PaymentLinkPB {
#[pb(index = 1)]
pub payment_link: String,
}

View File

@ -774,3 +774,11 @@ pub async fn leave_workspace_handler(
manager.leave_workspace(&workspace_id).await?; manager.leave_workspace(&workspace_id).await?;
Ok(()) Ok(())
} }
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn workspace_subscription_link_handler(
data: AFPluginData<WorkspaceSubscriptionLinkPB>,
manager: AFPluginState<Weak<UserManager>>,
) -> DataResult<PaymentLinkPB, FlowyError> {
todo!()
}

View File

@ -71,6 +71,8 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::InviteWorkspaceMember, invite_workspace_member_handler) .event(UserEvent::InviteWorkspaceMember, invite_workspace_member_handler)
.event(UserEvent::ListWorkspaceInvitations, list_workspace_invitations_handler) .event(UserEvent::ListWorkspaceInvitations, list_workspace_invitations_handler)
.event(UserEvent::AcceptWorkspaceInvitation, accept_workspace_invitations_handler) .event(UserEvent::AcceptWorkspaceInvitation, accept_workspace_invitations_handler)
// Billing
.event(UserEvent::WorkspaceSubscriptionLink, workspace_subscription_link_handler)
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
@ -230,6 +232,9 @@ pub enum UserEvent {
#[event(input = "MagicLinkSignInPB", output = "UserProfilePB")] #[event(input = "MagicLinkSignInPB", output = "UserProfilePB")]
MagicLinkSignIn = 50, MagicLinkSignIn = 50,
#[event(input = "WorkspaceSubscriptionLinkPB", output = "PaymentLinkPB")]
WorkspaceSubscriptionLink = 51,
} }
pub trait UserStatusCallback: Send + Sync + 'static { pub trait UserStatusCallback: Send + Sync + 'static {