Skip to content

The open alternative to Salesforce, designed for AI.

Set optional checkout.session.url (#4569)

martmull35d41e38c89f
diff --git a/packages/twenty-front/src/config/index.ts b/packages/twenty-front/src/config/index.ts
index 1220a5b0a43..4dbb196252f 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 abf8cb43f0d..43192e2bc9a 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<Scalars['String']>;
};
/** 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 b4f332c6743..13de2e85477 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}
/>
</Section>
)}
diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.example
index 70c186e5d5f..d8e3f31fb00 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 705c6e0aadc..b15c0f3d6cf 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 95da4d4224a..745a7364b74 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 4d03b923a87..73102d71f41 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