From 35d41e38c89fb11fbd9437e3f66256d8237a4fa7 Mon Sep 17 00:00:00 2001 From: martmull Date: Wed, 20 Mar 2024 07:04:07 +0100 Subject: [PATCH] Set optional checkout.session.url (#4569) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set optional checkout.session.url * Lint * Edit .env.example * Vale CI --------- Co-authored-by: Félix Malfait --- packages/twenty-front/src/config/index.ts | 2 +- .../twenty-front/src/generated/graphql.tsx | 6 +++--- .../src/pages/settings/SettingsBilling.tsx | 7 +++++-- packages/twenty-server/.env.example | 1 + .../engine/modules/billing/billing.service.ts | 18 ++++++++++-------- .../modules/billing/dto/session.entity.ts | 2 +- .../src/content/releases/0.3.0.mdx | 2 +- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/twenty-front/src/config/index.ts b/packages/twenty-front/src/config/index.ts index 1220a5b0a..4dbb19625 100644 --- a/packages/twenty-front/src/config/index.ts +++ b/packages/twenty-front/src/config/index.ts @@ -27,4 +27,4 @@ const getDefaultUrl = () => { export const REACT_APP_SERVER_BASE_URL = window._env_?.REACT_APP_SERVER_BASE_URL || process.env.REACT_APP_SERVER_BASE_URL || - getDefaultUrl(); \ No newline at end of file + getDefaultUrl(); diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsx index abf8cb43f..43192e2bc 100644 --- a/packages/twenty-front/src/generated/graphql.tsx +++ b/packages/twenty-front/src/generated/graphql.tsx @@ -552,7 +552,7 @@ export type Sentry = { export type SessionEntity = { __typename?: 'SessionEntity'; - url: Scalars['String']; + url?: Maybe; }; /** Sort Directions */ @@ -1015,7 +1015,7 @@ export type BillingPortalSessionQueryVariables = Exact<{ }>; -export type BillingPortalSessionQuery = { __typename?: 'Query', billingPortalSession: { __typename?: 'SessionEntity', url: string } }; +export type BillingPortalSessionQuery = { __typename?: 'Query', billingPortalSession: { __typename?: 'SessionEntity', url?: string | null } }; export type CheckoutSessionMutationVariables = Exact<{ recurringInterval: Scalars['String']; @@ -1023,7 +1023,7 @@ export type CheckoutSessionMutationVariables = Exact<{ }>; -export type CheckoutSessionMutation = { __typename?: 'Mutation', checkoutSession: { __typename?: 'SessionEntity', url: string } }; +export type CheckoutSessionMutation = { __typename?: 'Mutation', checkoutSession: { __typename?: 'SessionEntity', url?: string | null } }; export type GetProductPricesQueryVariables = Exact<{ product: Scalars['String']; diff --git a/packages/twenty-front/src/pages/settings/SettingsBilling.tsx b/packages/twenty-front/src/pages/settings/SettingsBilling.tsx index b4f332c67..13de2e854 100644 --- a/packages/twenty-front/src/pages/settings/SettingsBilling.tsx +++ b/packages/twenty-front/src/pages/settings/SettingsBilling.tsx @@ -35,6 +35,9 @@ export const SettingsBilling = () => { }, }); + const billingPortalButtonDisabled = + loading || !isDefined(data) || !isDefined(data.billingPortalSession.url); + const displayPaymentFailInfo = onboardingStatus === OnboardingStatus.PastDue || onboardingStatus === OnboardingStatus.Unpaid; @@ -46,7 +49,7 @@ export const SettingsBilling = () => { onboardingStatus === OnboardingStatus.CompletedWithoutSubscription; const openBillingPortal = () => { - if (isDefined(data)) { + if (isDefined(data) && isDefined(data.billingPortalSession.url)) { window.location.replace(data.billingPortalSession.url); } }; @@ -95,7 +98,7 @@ export const SettingsBilling = () => { title="View billing details" variant="secondary" onClick={openBillingPortal} - disabled={loading} + disabled={billingPortalButtonDisabled} /> )} diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.example index 70c186e5d..d8e3f31fb 100644 --- a/packages/twenty-server/.env.example +++ b/packages/twenty-server/.env.example @@ -8,6 +8,7 @@ FRONT_BASE_URL=http://localhost:3001 ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access LOGIN_TOKEN_SECRET=replace_me_with_a_random_string_login REFRESH_TOKEN_SECRET=replace_me_with_a_random_string_refresh +FILE_TOKEN_SECRET=replace_me_with_a_random_string_refresh SIGN_IN_PREFILLED=true # ———————— Optional ———————— diff --git a/packages/twenty-server/src/engine/modules/billing/billing.service.ts b/packages/twenty-server/src/engine/modules/billing/billing.service.ts index 705c6e0aa..b15c0f3d6 100644 --- a/packages/twenty-server/src/engine/modules/billing/billing.service.ts +++ b/packages/twenty-server/src/engine/modules/billing/billing.service.ts @@ -131,10 +131,13 @@ export class BillingService { workspaceId: string, returnUrlPath?: string, ) { - const billingSubscription = - await this.billingSubscriptionRepository.findOneOrFail({ - where: { workspaceId }, - }); + const billingSubscription = await this.getCurrentBillingSubscription({ + workspaceId, + }); + + if (!billingSubscription) { + return; + } const frontBaseUrl = this.environmentService.get('FRONT_BASE_URL'); const returnUrl = returnUrlPath @@ -190,10 +193,9 @@ export class BillingService { } async deleteSubscription(workspaceId: string) { - const subscriptionToCancel = - await this.billingSubscriptionRepository.findOneBy({ - workspaceId, - }); + const subscriptionToCancel = await this.getCurrentBillingSubscription({ + workspaceId, + }); if (subscriptionToCancel) { await this.stripeService.cancelSubscription( diff --git a/packages/twenty-server/src/engine/modules/billing/dto/session.entity.ts b/packages/twenty-server/src/engine/modules/billing/dto/session.entity.ts index 95da4d422..745a7364b 100644 --- a/packages/twenty-server/src/engine/modules/billing/dto/session.entity.ts +++ b/packages/twenty-server/src/engine/modules/billing/dto/session.entity.ts @@ -2,6 +2,6 @@ import { Field, ObjectType } from '@nestjs/graphql'; @ObjectType() export class SessionEntity { - @Field(() => String) + @Field(() => String, { nullable: true }) url: string; } diff --git a/packages/twenty-website/src/content/releases/0.3.0.mdx b/packages/twenty-website/src/content/releases/0.3.0.mdx index 4d03b923a..73102d71f 100644 --- a/packages/twenty-website/src/content/releases/0.3.0.mdx +++ b/packages/twenty-website/src/content/releases/0.3.0.mdx @@ -5,6 +5,6 @@ Date: Feb 3rd 2024 # Rating field -The new Rating field represents a numeric value from 0 to 5, it can be useful for various use-cases such as scoring leads. +The new Rating field represents a numeric value from zero to five, it can be useful for various use-cases such as scoring leads. ![rating](/images/releases/0.3.0_rating.png) \ No newline at end of file