diff --git a/.changeset/fiery-carrots-call.md b/.changeset/fiery-carrots-call.md new file mode 100644 index 00000000000..30bdce97121 --- /dev/null +++ b/.changeset/fiery-carrots-call.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': major +--- + +Rename internal `useBillingHookEnabled` to `useBillingIsEnabled` with improved semantics for authentication and organization context checks. diff --git a/packages/shared/src/react/billing/__tests__/useInitializePaymentMethod.spec.tsx b/packages/shared/src/react/billing/__tests__/useInitializePaymentMethod.spec.tsx index fa4dde7b99b..14e6a23cbab 100644 --- a/packages/shared/src/react/billing/__tests__/useInitializePaymentMethod.spec.tsx +++ b/packages/shared/src/react/billing/__tests__/useInitializePaymentMethod.spec.tsx @@ -66,8 +66,9 @@ describe('useInitializePaymentMethod', () => { expect(result.current.initializePaymentMethod).toBeInstanceOf(Function); }); - it('does not fetch when billing disabled for user', () => { + it('does not fetch when billing disabled', () => { mockClerk.__internal_environment.commerceSettings.billing.user.enabled = false; + mockClerk.__internal_environment.commerceSettings.billing.organization.enabled = false; const { result } = renderHook(() => useInitializePaymentMethod(), { wrapper }); diff --git a/packages/shared/src/react/billing/useInitializePaymentMethod.tsx b/packages/shared/src/react/billing/useInitializePaymentMethod.tsx index 1bf0f2164e2..8e1f08aa343 100644 --- a/packages/shared/src/react/billing/useInitializePaymentMethod.tsx +++ b/packages/shared/src/react/billing/useInitializePaymentMethod.tsx @@ -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 = { @@ -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; diff --git a/packages/shared/src/react/billing/useStripeLoader.tsx b/packages/shared/src/react/billing/useStripeLoader.tsx index 59dee615f6b..7b6d9e097c7 100644 --- a/packages/shared/src/react/billing/useStripeLoader.tsx +++ b/packages/shared/src/react/billing/useStripeLoader.tsx @@ -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 = { @@ -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; diff --git a/packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx b/packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx index 06bdf71cc85..ed3d5738e20 100644 --- a/packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx +++ b/packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx @@ -57,8 +57,9 @@ describe('useSubscription', () => { defaultQueryClient.client.clear(); }); - it('does not fetch when billing disabled for user', () => { + it('does not fetch when billing disabled', () => { mockClerk.__internal_environment.commerceSettings.billing.user.enabled = false; + mockClerk.__internal_environment.commerceSettings.billing.organization.enabled = false; const { result } = renderHook(() => useSubscription(), { wrapper }); diff --git a/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx b/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx index 9d658db2969..fa5d9f37ae5 100644 --- a/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx +++ b/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx @@ -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'; /** @@ -106,7 +106,7 @@ export function createBillingPaginatedHook {