From 5a8c1daf31228187097fe02b820ad0e36f7648a6 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 19 Jul 2024 21:58:40 +0800 Subject: [PATCH 1/4] chore: add shared entitity subscription plan detail --- libs/shared-entity/src/dto/billing_dto.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/shared-entity/src/dto/billing_dto.rs b/libs/shared-entity/src/dto/billing_dto.rs index 8be28fe0..4aebc401 100644 --- a/libs/shared-entity/src/dto/billing_dto.rs +++ b/libs/shared-entity/src/dto/billing_dto.rs @@ -134,3 +134,16 @@ pub struct SetSubscriptionRecurringInterval { pub plan: SubscriptionPlan, pub recurring_interval: RecurringInterval, } + +#[derive(Serialize, Deserialize, Debug)] +pub struct SubscriptionPlanDetail { + pub currency: Currency, + pub price_cents: i64, + pub plan: SubscriptionPlan, +} + +#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Hash, Default)] +pub enum Currency { + #[default] + USD, +} From 37a8b9bfc76801e450ebd46f5a8888adb49c59a3 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 19 Jul 2024 22:43:21 +0800 Subject: [PATCH 2/4] chore: add recurring interval --- libs/shared-entity/src/dto/billing_dto.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/shared-entity/src/dto/billing_dto.rs b/libs/shared-entity/src/dto/billing_dto.rs index 4aebc401..827ca1c0 100644 --- a/libs/shared-entity/src/dto/billing_dto.rs +++ b/libs/shared-entity/src/dto/billing_dto.rs @@ -139,6 +139,7 @@ pub struct SetSubscriptionRecurringInterval { pub struct SubscriptionPlanDetail { pub currency: Currency, pub price_cents: i64, + pub recurring_interval: RecurringInterval, pub plan: SubscriptionPlan, } From bacb7c4ae6cd799d8060aa2cc467b6eb14d0ac14 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 19 Jul 2024 23:10:06 +0800 Subject: [PATCH 3/4] chore: add get subscription plan details --- libs/client-api/src/http_billing.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/client-api/src/http_billing.rs b/libs/client-api/src/http_billing.rs index 0b286ad7..05ec6329 100644 --- a/libs/client-api/src/http_billing.rs +++ b/libs/client-api/src/http_billing.rs @@ -1,6 +1,7 @@ use crate::Client; use client_api_entity::billing_dto::{ - SetSubscriptionRecurringInterval, SubscriptionCancelRequest, WorkspaceUsageAndLimit, + SetSubscriptionRecurringInterval, SubscriptionCancelRequest, SubscriptionPlanDetail, + WorkspaceUsageAndLimit, }; use reqwest::Method; use shared_entity::{ @@ -198,4 +199,20 @@ impl Client { AppResponse::<()>::from_response(resp).await?.into_error() } + + /// get all subscription plan details + pub async fn get_subscription_plan_details( + &self, + ) -> Result, AppResponseError> { + let url = format!("{}/billing/api/v1/subscriptions", self.base_billing_url(),); + let resp = self + .http_client_with_auth(Method::POST, &url) + .await? + .send() + .await?; + + AppResponse::>::from_response(resp) + .await? + .into_data() + } } From 61be7fd46ca3b4463c03f64663b02d8fd626a71a Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 19 Jul 2024 23:19:00 +0800 Subject: [PATCH 4/4] chore: fix method --- libs/client-api/src/http_billing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/client-api/src/http_billing.rs b/libs/client-api/src/http_billing.rs index 05ec6329..2f3fc307 100644 --- a/libs/client-api/src/http_billing.rs +++ b/libs/client-api/src/http_billing.rs @@ -206,7 +206,7 @@ impl Client { ) -> Result, AppResponseError> { let url = format!("{}/billing/api/v1/subscriptions", self.base_billing_url(),); let resp = self - .http_client_with_auth(Method::POST, &url) + .http_client_with_auth(Method::GET, &url) .await? .send() .await?;