Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import {
createAllowedRedirectOrigins,
createBeforeUnloadTracker,
createPageLifecycle,
disabledCommerceFeature,
disabledBillingFeature,
disabledOrganizationsFeature,
errorThrower,
generateSignatureWithCoinbaseWallet,
Expand Down Expand Up @@ -955,7 +955,7 @@ export class Clerk implements ClerkInterface {

public __experimental_mountPricingTable = (node: HTMLDivElement, props?: __experimental_PricingTableProps): void => {
this.assertComponentsReady(this.#componentControls);
if (disabledCommerceFeature(this, this.environment)) {
if (disabledBillingFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyCommerceComponent('PricingTable'), {
code: 'cannot_render_commerce_disabled',
Expand Down
20 changes: 13 additions & 7 deletions packages/clerk-js/src/core/resources/CommerceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { BaseResource } from './internal';
* @internal
*/
export class __experimental_CommerceSettings extends BaseResource implements __experimental_CommerceSettingsResource {
stripePublishableKey: string = '';
enabled: boolean = false;
billing = {
stripePublishableKey: '',
enabled: false,
};

public constructor(
data: __experimental_CommerceSettingsJSON | __experimental_CommerceSettingsJSONSnapshot | null = null,
Expand All @@ -23,18 +25,22 @@ export class __experimental_CommerceSettings extends BaseResource implements __e
protected fromJSON(
data: __experimental_CommerceSettingsJSON | __experimental_CommerceSettingsJSONSnapshot | null,
): this {
if (!data) {
if (!data?.billing) {
return this;
}
this.stripePublishableKey = data.stripe_publishable_key;
this.enabled = data.enabled;

this.billing.stripePublishableKey = data.billing.stripe_publishable_key || '';
this.billing.enabled = data.billing.enabled || false;

return this;
}

public __internal_toSnapshot(): __experimental_CommerceSettingsJSONSnapshot {
return {
stripe_publishable_key: this.stripePublishableKey,
enabled: this.enabled,
billing: {
stripe_publishable_key: this.billing.stripePublishableKey,
enabled: this.billing.enabled,
},
} as unknown as __experimental_CommerceSettingsJSONSnapshot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const OrganizationProfileRoutes = () => {
</Route>
</Switch>
</Route>
{experimental?.commerce && __experimental_commerceSettings.enabled && (
{experimental?.commerce && __experimental_commerceSettings.billing.enabled && (
<Route path={isBillingPageRoot ? undefined : 'organization-billing'}>
<Switch>
<Route index>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ export const AddPaymentSource = (props: AddPaymentSourceProps) => {
const externalGatewayId = checkout?.externalGatewayId ?? initializedPaymentSource?.externalGatewayId;
const externalClientSecret = checkout?.externalClientSecret ?? initializedPaymentSource?.externalClientSecret;

const stripePublishableKey = __experimental_commerceSettings.billing.stripePublishableKey;

useEffect(() => {
if (!stripePromiseRef.current && externalGatewayId && __experimental_commerceSettings.stripePublishableKey) {
if (!stripePromiseRef.current && externalGatewayId && stripePublishableKey) {
if (__BUILD_DISABLE_RHC__) {
clerkUnsupportedEnvironmentWarning('Stripe');
return;
}

stripePromiseRef.current = loadStripe(__experimental_commerceSettings.stripePublishableKey, {
stripePromiseRef.current = loadStripe(stripePublishableKey, {
stripeAccount: externalGatewayId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const UserProfileRoutes = () => {
</Route>
</Switch>
</Route>
{experimental?.commerce && __experimental_commerceSettings.enabled && (
{experimental?.commerce && __experimental_commerceSettings.billing.enabled && (
<Route path={isBillingPageRoot ? undefined : 'billing'}>
<Switch>
<Route index>
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/utils/createCustomPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const createCustomPages = (
commerce:
clerk.sdkMetadata?.environment === 'test'
? false
: clerk.__internal_getOption('experimental')?.commerce && environment?.__experimental_commerceSettings.enabled,
: clerk.__internal_getOption('experimental')?.commerce &&
environment?.__experimental_commerceSettings?.billing.enabled,
});

if (isDevelopmentSDK(clerk)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/src/utils/componentGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const disabledOrganizationsFeature: ComponentGuard = (_, environment) =>
return !environment?.organizationSettings.enabled;
};

export const disabledCommerceFeature: ComponentGuard = (_, environment) => {
return !environment?.__experimental_commerceSettings.enabled;
export const disabledBillingFeature: ComponentGuard = (_, environment) => {
return !environment?.__experimental_commerceSettings.billing.enabled;
};
13 changes: 9 additions & 4 deletions packages/types/src/commerceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface __experimental_CommerceSettingsJSON extends ClerkResourceJSON {
enabled: boolean;
stripe_publishable_key: string;
billing: {
enabled: boolean;
stripe_publishable_key: string;
};
}

export interface __experimental_CommerceSettingsResource extends ClerkResource {
enabled: boolean;
stripePublishableKey: string;
billing: {
enabled: boolean;
stripePublishableKey: string;
};

__internal_toSnapshot: () => __experimental_CommerceSettingsJSONSnapshot;
}