From 0f9cb41a85904bb9520a93edba63440865ab56ad Mon Sep 17 00:00:00 2001 From: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:09:14 +0530 Subject: [PATCH] fix: license sync endpoint (#866) * dev: update licence subscription sync * fix: refresh interval on workspace license * chore: display trial end date on billing page. --------- Co-authored-by: Prateek Shourya --- .../utils/workspace_license_request.py | 2 +- apiserver/plane/payment/views/product.py | 2 ++ .../license/plane-cloud-billing.tsx | 30 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apiserver/plane/payment/utils/workspace_license_request.py b/apiserver/plane/payment/utils/workspace_license_request.py index e0967f91da..06a9fe2e5c 100644 --- a/apiserver/plane/payment/utils/workspace_license_request.py +++ b/apiserver/plane/payment/utils/workspace_license_request.py @@ -45,7 +45,7 @@ def resync_workspace_license(workspace_slug, force=False): # If the last sync is more than 1 hour, then sync the license if ( workspace_license.last_synced_at - timezone.now() - ).seconds > 3600 or force: + ).total_seconds() > 3600 or force: # Fetch the workspace license response = fetch_workspace_license( diff --git a/apiserver/plane/payment/views/product.py b/apiserver/plane/payment/views/product.py index ad100a3192..0b89a7c8f9 100644 --- a/apiserver/plane/payment/views/product.py +++ b/apiserver/plane/payment/views/product.py @@ -230,6 +230,7 @@ class WorkspaceLicenseSyncEndpoint(BaseAPIView): workspace_license.has_added_payment_method = request.data.get( "has_added_payment_method", False ) + workspace_license.subscription = request.data.get("subscription") workspace_license.save() # If the workspace license is not present, then fetch the license from the payment server and create it else: @@ -252,6 +253,7 @@ class WorkspaceLicenseSyncEndpoint(BaseAPIView): has_added_payment_method=request.data.get( "has_added_payment_method", False ), + subscription=request.data.get("subscription"), ) # Return the response diff --git a/web/ee/components/license/plane-cloud-billing.tsx b/web/ee/components/license/plane-cloud-billing.tsx index b1ea1c6740..fe895e2c19 100644 --- a/web/ee/components/license/plane-cloud-billing.tsx +++ b/web/ee/components/license/plane-cloud-billing.tsx @@ -26,6 +26,9 @@ export const PlaneCloudBilling: React.FC = observer(() => { // derived values const endDate = currentWorkspaceSubscribedPlanDetail?.current_period_end_date; const isSubscriptionCancelled = currentWorkspaceSubscribedPlanDetail?.is_canceled; + const isInTrialPeriod = + !currentWorkspaceSubscribedPlanDetail?.has_added_payment_method && + !!currentWorkspaceSubscribedPlanDetail?.trial_end_date; const handleSubscriptionPageRedirection = () => { setIsLoading(true); @@ -102,15 +105,26 @@ export const PlaneCloudBilling: React.FC = observer(() => {
Plane pro

Plane Pro

- {isSubscriptionCancelled ? ( -
- (Expires on: {renderFormattedDate(endDate)}) -
- ) : ( -
- (Renew on: {renderFormattedDate(endDate)}) -
+ {isInTrialPeriod && ( + <> +
+ Free Trial +
+
+ (Free trial ends on: {renderFormattedDate(currentWorkspaceSubscribedPlanDetail?.trial_end_date)}) +
+ )} + {!isInTrialPeriod && + (isSubscriptionCancelled ? ( +
+ (Expires on: {renderFormattedDate(endDate)}) +
+ ) : ( +
+ (Renew on: {renderFormattedDate(endDate)}) +
+ ))}
{!currentWorkspaceSubscribedPlanDetail.is_offline_payment && (