mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: added create subscription
This commit is contained in:
2
frontend/rust-lib/Cargo.lock
generated
2
frontend/rust-lib/Cargo.lock
generated
@ -183,7 +183,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "appflowy-cloud-billing-client"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud-Billing-Client?rev=b95d520d5c570c85cb5e0fd2980220deea41df2b#b95d520d5c570c85cb5e0fd2980220deea41df2b"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud-Billing-Client?rev=b141b6eefa0e46d80d5d0f59a8c9c51c0dfdbb78#b141b6eefa0e46d80d5d0f59a8c9c51c0dfdbb78"
|
||||
dependencies = [
|
||||
"client-api",
|
||||
"reqwest",
|
||||
|
@ -129,4 +129,4 @@ rocksdb = { git = "https://github.com/LucasXu0/rust-rocksdb", rev = "21cf4a23ec1
|
||||
# scripts/tool/update_client_api_rev.sh new_rev_id
|
||||
# ⚠️⚠️⚠️️
|
||||
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" }
|
||||
appflowy-cloud-billing-client = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud-Billing-Client", rev = "b141b6eefa0e46d80d5d0f59a8c9c51c0dfdbb78" }
|
||||
|
@ -1,7 +1,9 @@
|
||||
use appflowy_cloud_billing_client::entities::{RecurringInterval, SubscriptionPlan};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use appflowy_cloud_billing_client::WorkspaceSubscriptionClient;
|
||||
use client_api::entity::workspace_dto::{
|
||||
CreateWorkspaceMember, CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset,
|
||||
WorkspaceMemberInvitation,
|
||||
@ -474,6 +476,30 @@ where
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn subscribe_workspace(
|
||||
&self,
|
||||
workspace_id: String,
|
||||
recurring_interval: flowy_user_pub::entities::RecurringInterval,
|
||||
workspace_subscription_plan: flowy_user_pub::entities::SubscriptionPlan,
|
||||
success_url: String,
|
||||
) -> FutureResult<String, FlowyError> {
|
||||
let try_get_client = self.server.try_get_client();
|
||||
let workspace_id = workspace_id.to_string();
|
||||
FutureResult::new(async move {
|
||||
let client = try_get_client?;
|
||||
let payment_link = client
|
||||
.create_subscription(
|
||||
&workspace_id,
|
||||
to_recurring_interval(recurring_interval),
|
||||
to_workspace_subscription_plan(workspace_subscription_plan),
|
||||
&success_url,
|
||||
)
|
||||
.await?;
|
||||
Ok(payment_link)
|
||||
// Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_admin_client(client: &Arc<AFCloudClient>) -> FlowyResult<Client> {
|
||||
@ -570,3 +596,19 @@ fn oauth_params_from_box_any(any: BoxAny) -> Result<AFCloudOAuthParams, FlowyErr
|
||||
sign_in_url: sign_in_url.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn to_recurring_interval(r: flowy_user_pub::entities::RecurringInterval) -> RecurringInterval {
|
||||
match r {
|
||||
flowy_user_pub::entities::RecurringInterval::Month => RecurringInterval::Month,
|
||||
flowy_user_pub::entities::RecurringInterval::Year => RecurringInterval::Year,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_workspace_subscription_plan(
|
||||
s: flowy_user_pub::entities::SubscriptionPlan,
|
||||
) -> SubscriptionPlan {
|
||||
match s {
|
||||
flowy_user_pub::entities::SubscriptionPlan::Pro => SubscriptionPlan::Pro,
|
||||
flowy_user_pub::entities::SubscriptionPlan::Team => SubscriptionPlan::Team,
|
||||
}
|
||||
}
|
||||
|
@ -423,15 +423,11 @@ pub struct WorkspaceInvitation {
|
||||
}
|
||||
|
||||
pub enum RecurringInterval {
|
||||
UndefinedRecurringInterval,
|
||||
|
||||
Month,
|
||||
Year,
|
||||
}
|
||||
|
||||
pub enum SubscriptionPlan {
|
||||
UndefinedSubscriptionPlan,
|
||||
|
||||
Pro,
|
||||
Team,
|
||||
}
|
||||
|
@ -208,7 +208,6 @@ pub struct SubscribeWorkspacePB {
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub recurring_interval: RecurringIntervalPB,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub workspace_subscription_plan: SubscriptionPlanPB,
|
||||
|
||||
@ -219,10 +218,8 @@ pub struct SubscribeWorkspacePB {
|
||||
#[derive(ProtoBuf_Enum, Clone, Default, Debug)]
|
||||
pub enum RecurringIntervalPB {
|
||||
#[default]
|
||||
UndefinedRecurringInterval = 0,
|
||||
|
||||
Month = 1,
|
||||
Year = 2,
|
||||
Month = 0,
|
||||
Year = 1,
|
||||
}
|
||||
|
||||
impl From<RecurringIntervalPB> for RecurringInterval {
|
||||
@ -230,9 +227,6 @@ impl From<RecurringIntervalPB> for RecurringInterval {
|
||||
match value {
|
||||
RecurringIntervalPB::Month => RecurringInterval::Month,
|
||||
RecurringIntervalPB::Year => RecurringInterval::Year,
|
||||
RecurringIntervalPB::UndefinedRecurringInterval => {
|
||||
RecurringInterval::UndefinedRecurringInterval
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,10 +234,8 @@ impl From<RecurringIntervalPB> for RecurringInterval {
|
||||
#[derive(ProtoBuf_Enum, Clone, Default, Debug)]
|
||||
pub enum SubscriptionPlanPB {
|
||||
#[default]
|
||||
UndefinedSubscriptionPlan = 0,
|
||||
|
||||
Pro = 1,
|
||||
Team = 2,
|
||||
Pro = 0,
|
||||
Team = 1,
|
||||
}
|
||||
|
||||
impl From<SubscriptionPlanPB> for SubscriptionPlan {
|
||||
@ -251,7 +243,6 @@ impl From<SubscriptionPlanPB> for SubscriptionPlan {
|
||||
match value {
|
||||
SubscriptionPlanPB::Pro => SubscriptionPlan::Pro,
|
||||
SubscriptionPlanPB::Team => SubscriptionPlan::Team,
|
||||
SubscriptionPlanPB::UndefinedSubscriptionPlan => SubscriptionPlan::UndefinedSubscriptionPlan,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user