Set optional checkout.session.url (#4569)

* Set optional checkout.session.url

* Lint

* Edit .env.example

* Vale CI

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
martmull 2024-03-20 07:04:07 +01:00 committed by GitHub
parent c90e379fc4
commit 35d41e38c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 22 additions and 16 deletions

View File

@ -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();
getDefaultUrl();

View File

@ -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'];

View File

@ -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>
)}

View File

@ -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 ————————

View File

@ -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(

View File

@ -2,6 +2,6 @@ import { Field, ObjectType } from '@nestjs/graphql';
@ObjectType()
export class SessionEntity {
@Field(() => String)
@Field(() => String, { nullable: true })
url: string;
}

View File

@ -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)