mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: user billing portal
This commit is contained in:
parent
2f9bc267e2
commit
281e61d45c
@ -541,6 +541,15 @@ where
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn get_billing_portal_url(&self) -> FutureResult<String, FlowyError> {
|
||||
let try_get_client = self.server.try_get_client();
|
||||
FutureResult::new(async move {
|
||||
let client = try_get_client?;
|
||||
let url = client.get_portal_session_link().await?;
|
||||
Ok(url)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_admin_client(client: &Arc<AFCloudClient>) -> FlowyResult<Client> {
|
||||
|
@ -289,6 +289,10 @@ pub trait UserCloudService: Send + Sync + 'static {
|
||||
fn get_workspace_usage(&self, workspace_id: String) -> FutureResult<WorkspaceUsage, FlowyError> {
|
||||
FutureResult::new(async { Err(FlowyError::not_support()) })
|
||||
}
|
||||
|
||||
fn get_billing_portal_url(&self) -> FutureResult<String, FlowyError> {
|
||||
FutureResult::new(async { Err(FlowyError::not_support()) })
|
||||
}
|
||||
}
|
||||
|
||||
pub type UserUpdateReceiver = tokio::sync::mpsc::Receiver<UserUpdate>;
|
||||
|
@ -318,3 +318,9 @@ pub struct WorkspaceUsagePB {
|
||||
#[pb(index = 4)]
|
||||
pub total_blob_bytes_limit: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, ProtoBuf, Default, Clone)]
|
||||
pub struct BillingPortalPB {
|
||||
#[pb(index = 1)]
|
||||
pub url: String,
|
||||
}
|
||||
|
@ -826,3 +826,12 @@ pub async fn get_workspace_usage_handler(
|
||||
total_blob_bytes_limit: workspace_usage.total_blob_bytes_limit as u64,
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn get_billing_portal_handler(
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> DataResult<BillingPortalPB, FlowyError> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let url = manager.get_billing_portal_url().await?;
|
||||
data_result_ok(BillingPortalPB { url })
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
|
||||
.event(UserEvent::GetWorkspaceSubscriptions, get_workspace_subscriptions_handler)
|
||||
.event(UserEvent::CancelWorkspaceSubscription, cancel_workspace_subscription_handler)
|
||||
.event(UserEvent::GetWorkspaceUsage, get_workspace_usage_handler)
|
||||
.event(UserEvent::GetBillingPortal, get_billing_portal_handler)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
||||
@ -247,6 +248,9 @@ pub enum UserEvent {
|
||||
|
||||
#[event(input = "UserWorkspaceIdPB", output = "WorkspaceUsagePB")]
|
||||
GetWorkspaceUsage = 54,
|
||||
|
||||
#[event(output = "BillingPortalPB")]
|
||||
GetBillingPortal = 55,
|
||||
}
|
||||
|
||||
pub trait UserStatusCallback: Send + Sync + 'static {
|
||||
|
@ -460,6 +460,16 @@ impl UserManager {
|
||||
.await?;
|
||||
Ok(workspace_usage)
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip(self), err)]
|
||||
pub async fn get_billing_portal_url(&self) -> FlowyResult<String> {
|
||||
let url = self
|
||||
.cloud_services
|
||||
.get_user_service()?
|
||||
.get_billing_portal_url()
|
||||
.await?;
|
||||
Ok(url)
|
||||
}
|
||||
}
|
||||
|
||||
/// This method is used to save one user workspace to the SQLite database
|
||||
|
Loading…
Reference in New Issue
Block a user