chore: configurable base billing url
This commit is contained in:
parent
f8d24e6ad5
commit
a41344fbae
|
|
@ -1886,6 +1886,7 @@ dependencies = [
|
||||||
"getrandom 0.2.12",
|
"getrandom 0.2.12",
|
||||||
"gotrue",
|
"gotrue",
|
||||||
"infra",
|
"infra",
|
||||||
|
"lazy_static",
|
||||||
"mime",
|
"mime",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ serde_urlencoded = "0.7.1"
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
pin-project = "1.1.5"
|
pin-project = "1.1.5"
|
||||||
percent-encoding = "2.3.1"
|
percent-encoding = "2.3.1"
|
||||||
|
lazy_static = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
tokio-retry = "0.3"
|
tokio-retry = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,23 @@ use shared_entity::{
|
||||||
response::{AppResponse, AppResponseError},
|
response::{AppResponse, AppResponseError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref BASE_BILLING_URL: Option<String> = match std::env::var("APPFLOWY_CLOUD_BASE_BILLING_URL") {
|
||||||
|
Ok(url) => Some(url),
|
||||||
|
Err(err) => {
|
||||||
|
tracing::warn!("std::env::var(APPFLOWY_CLOUD_BASE_BILLING_URL): {}", err);
|
||||||
|
None
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
|
pub fn base_billing_url(&self) -> &str {
|
||||||
|
BASE_BILLING_URL.as_deref().unwrap_or(&self.base_url)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn customer_id(&self) -> Result<String, AppResponseError> {
|
pub async fn customer_id(&self) -> Result<String, AppResponseError> {
|
||||||
let url = format!("{}/billing/api/v1/customer-id", &self.base_url);
|
let url = format!("{}/billing/api/v1/customer-id", self.base_billing_url());
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::GET, &url)
|
.http_client_with_auth(Method::GET, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -30,7 +44,10 @@ impl Client {
|
||||||
workspace_subscription_plan: SubscriptionPlan,
|
workspace_subscription_plan: SubscriptionPlan,
|
||||||
success_url: &str,
|
success_url: &str,
|
||||||
) -> Result<String, AppResponseError> {
|
) -> Result<String, AppResponseError> {
|
||||||
let url = format!("{}/billing/api/v1/subscription-link", &self.base_url,);
|
let url = format!(
|
||||||
|
"{}/billing/api/v1/subscription-link",
|
||||||
|
self.base_billing_url()
|
||||||
|
);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::GET, &url)
|
.http_client_with_auth(Method::GET, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -52,7 +69,10 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cancel_subscription(&self, workspace_id: &str) -> Result<(), AppResponseError> {
|
pub async fn cancel_subscription(&self, workspace_id: &str) -> Result<(), AppResponseError> {
|
||||||
let url = format!("{}/billing/api/v1/cancel-subscription", &self.base_url);
|
let url = format!(
|
||||||
|
"{}/billing/api/v1/cancel-subscription",
|
||||||
|
self.base_billing_url()
|
||||||
|
);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::POST, &url)
|
.http_client_with_auth(Method::POST, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -65,7 +85,10 @@ impl Client {
|
||||||
pub async fn list_subscription(
|
pub async fn list_subscription(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Vec<WorkspaceSubscriptionStatus>, AppResponseError> {
|
) -> Result<Vec<WorkspaceSubscriptionStatus>, AppResponseError> {
|
||||||
let url = format!("{}/billing/api/v1/subscription-status", &self.base_url,);
|
let url = format!(
|
||||||
|
"{}/billing/api/v1/subscription-status",
|
||||||
|
self.base_billing_url(),
|
||||||
|
);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::GET, &url)
|
.http_client_with_auth(Method::GET, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -95,7 +118,10 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_portal_session_link(&self) -> Result<String, AppResponseError> {
|
pub async fn get_portal_session_link(&self) -> Result<String, AppResponseError> {
|
||||||
let url = format!("{}/billing/api/v1/portal-session-link", &self.base_url,);
|
let url = format!(
|
||||||
|
"{}/billing/api/v1/portal-session-link",
|
||||||
|
self.base_billing_url()
|
||||||
|
);
|
||||||
let portal_url = self
|
let portal_url = self
|
||||||
.http_client_with_auth(Method::GET, &url)
|
.http_client_with_auth(Method::GET, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -112,7 +138,11 @@ impl Client {
|
||||||
&self,
|
&self,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<WorkspaceUsageLimit, AppResponseError> {
|
) -> Result<WorkspaceUsageLimit, AppResponseError> {
|
||||||
let url = format!("{}/api/workspace/{}/limit", &self.base_url, workspace_id);
|
let url = format!(
|
||||||
|
"{}/api/workspace/{}/limit",
|
||||||
|
self.base_billing_url(),
|
||||||
|
workspace_id
|
||||||
|
);
|
||||||
self
|
self
|
||||||
.http_client_with_auth(Method::GET, &url)
|
.http_client_with_auth(Method::GET, &url)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue