Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQueryClient } from '../clerk-rq/use-clerk-query-client';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useOrganizationContext, useUserContext } from '../contexts';
import { useBillingHookEnabled } from '../hooks/useBillingHookEnabled';
import { useBillingIsEnabled } from '../hooks/useBillingIsEnabled';
import { useClearQueriesOnSignOut } from '../hooks/useClearQueriesOnSignOut';

type InitializePaymentMethodOptions = {
Expand All @@ -27,7 +27,7 @@ function useInitializePaymentMethod(options?: InitializePaymentMethodOptions): U

const resource = forType === 'organization' ? organization : user;

const billingEnabled = useBillingHookEnabled(options);
const billingEnabled = useBillingIsEnabled(options);

const stableKey = 'billing-payment-method-initialize';
const authenticated = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/billing/useStripeLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo } from 'react';

import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useBillingHookEnabled } from '../hooks/useBillingHookEnabled';
import { useBillingIsEnabled } from '../hooks/useBillingIsEnabled';
import type { UseStripeClerkLibsResult } from './useStripeClerkLibs';

type StripeLoaderOptions = {
Expand All @@ -24,7 +24,7 @@ function useStripeLoader(options: StripeLoaderOptions): UseStripeLoaderResult {
return ['stripe-sdk', { externalGatewayId, stripePublishableKey }] as const;
}, [externalGatewayId, stripePublishableKey]);

const billingEnabled = useBillingHookEnabled({ authenticated: true });
const billingEnabled = useBillingIsEnabled({ authenticated: true });

const isEnabled = Boolean(stripeClerkLibs && externalGatewayId && stripePublishableKey) && billingEnabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import type { ResourceCacheStableKey } from '../stable-keys';
import type { PagesOrInfiniteOptions, PaginatedHookConfig, PaginatedResources } from '../types';
import { createCacheKeys } from './createCacheKeys';
import { useBillingHookEnabled } from './useBillingHookEnabled';
import { useBillingIsEnabled } from './useBillingIsEnabled';
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ export function createBillingPaginatedHook<TResource extends ClerkResource, TPar

const isForOrganization = safeFor === 'organization';

const billingEnabled = useBillingHookEnabled({
const billingEnabled = useBillingIsEnabled({
for: safeFor,
enabled: externalEnabled,
authenticated: !options?.unauthenticated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useClerkInstanceContext, useOrganizationContext, useUserContext } from
/**
* @internal
*/
export function useBillingHookEnabled(params?: { for?: ForPayerType; enabled?: boolean; authenticated?: boolean }) {
export function useBillingIsEnabled(params?: { for?: ForPayerType; enabled?: boolean; authenticated?: boolean }) {
const clerk = useClerkInstanceContext();

const enabledFromParam = params?.enabled ?? true;
Expand All @@ -15,11 +15,17 @@ export function useBillingHookEnabled(params?: { for?: ForPayerType; enabled?: b
const user = useUserContext();
const { organization } = useOrganizationContext();

const isOrganization = params?.for === 'organization';
const billingEnabled = isOrganization
? environment?.commerceSettings.billing.organization.enabled
: environment?.commerceSettings.billing.user.enabled;
const userBillingEnabled = environment?.commerceSettings.billing.user.enabled;
const orgBillingEnabled = environment?.commerceSettings.billing.organization.enabled;

const billingEnabled =
params?.for === 'organization'
? orgBillingEnabled
: params?.for === 'user'
? userBillingEnabled
: userBillingEnabled || orgBillingEnabled;

const isOrganization = params?.for === 'organization';
const requireUserAndOrganizationWhenAuthenticated =
(params?.authenticated ?? true) ? (isOrganization ? Boolean(organization?.id) : true) && Boolean(user?.id) : true;

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext, useOrganizationContext, useUserContext } from '../contexts';
import { useBillingHookEnabled } from './useBillingHookEnabled';
import { useBillingIsEnabled } from './useBillingIsEnabled';
import { useClearQueriesOnSignOut } from './useClearQueriesOnSignOut';
import { usePaymentAttemptQueryCacheKeys } from './usePaymentAttemptQuery.shared';
import type { PaymentAttemptQueryResult, UsePaymentAttemptQueryParams } from './usePaymentAttemptQuery.types';
Expand All @@ -25,7 +25,7 @@ function usePaymentAttemptQuery(params: UsePaymentAttemptQueryParams): PaymentAt
for: forType,
});

const billingEnabled = useBillingHookEnabled(params);
const billingEnabled = useBillingIsEnabled(params);

const queryEnabled = Boolean(paymentAttemptId) && billingEnabled;

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
import { useBillingHookEnabled } from './useBillingHookEnabled';
import { useBillingIsEnabled } from './useBillingIsEnabled';
import { usePlanDetailsQueryCacheKeys } from './usePlanDetailsQuery.shared';
import type { PlanDetailsQueryResult, UsePlanDetailsQueryParams } from './usePlanDetailsQuery.types';

Expand All @@ -16,7 +16,7 @@ export function __internal_usePlanDetailsQuery(params: UsePlanDetailsQueryParams

const { queryKey } = usePlanDetailsQueryCacheKeys({ planId: targetPlanId });

const billingEnabled = useBillingHookEnabled({
const billingEnabled = useBillingIsEnabled({
authenticated: false,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/useStatementQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext, useOrganizationContext, useUserContext } from '../contexts';
import { useBillingHookEnabled } from './useBillingHookEnabled';
import { useBillingIsEnabled } from './useBillingIsEnabled';
import { useClearQueriesOnSignOut } from './useClearQueriesOnSignOut';
import { useStatementQueryCacheKeys } from './useStatementQuery.shared';
import type { StatementQueryResult, UseStatementQueryParams } from './useStatementQuery.types';
Expand All @@ -25,7 +25,7 @@ function useStatementQuery(params: UseStatementQueryParams = {}): StatementQuery
for: forType,
});

const billingEnabled = useBillingHookEnabled(params);
const billingEnabled = useBillingIsEnabled(params);

const queryEnabled = Boolean(statementId) && billingEnabled;

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/useSubscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useOrganizationContext,
useUserContext,
} from '../contexts';
import { useBillingHookEnabled } from './useBillingHookEnabled';
import { useBillingIsEnabled } from './useBillingIsEnabled';
import { useClearQueriesOnSignOut } from './useClearQueriesOnSignOut';
import { useSubscriptionCacheKeys } from './useSubscription.shared';
import type { SubscriptionResult, UseSubscriptionParams } from './useSubscription.types';
Expand All @@ -27,7 +27,7 @@ export function useSubscription(params?: UseSubscriptionParams): SubscriptionRes
const user = useUserContext();
const { organization } = useOrganizationContext();

const billingEnabled = useBillingHookEnabled(params);
const billingEnabled = useBillingIsEnabled(params);

const recordedRef = useRef(false);
useEffect(() => {
Expand Down
Loading