Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .changeset/tall-dryers-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/types': minor
---

[Billing Beta] Replace `redirectUrl` with `navigate` in `checkout.finalize()`
7 changes: 4 additions & 3 deletions packages/clerk-js/src/core/modules/checkout/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
__experimental_CheckoutCacheState,
__experimental_CheckoutInstance,
__experimental_CheckoutOptions,
SetActiveNavigate,
} from '@clerk/types';

import type { Clerk } from '../../clerk';
Expand Down Expand Up @@ -62,9 +63,9 @@ function createCheckoutInstance(
});
};

const finalize = (params?: { redirectUrl: string }) => {
const { redirectUrl } = params || {};
return clerk.setActive({ session: clerk.session?.id, redirectUrl });
const finalize = (params?: { navigate?: SetActiveNavigate }) => {
const { navigate } = params || {};
return clerk.setActive({ session: clerk.session?.id, navigate });
};

const clear = () => manager.clearCheckout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
CommerceCheckoutResource,
CommerceSubscriptionPlanPeriod,
ConfirmCheckoutParams,
SetActiveNavigate,
} from '@clerk/types';
import { describe, expectTypeOf, it } from 'vitest';

Expand Down Expand Up @@ -89,7 +90,7 @@ describe('useCheckout type tests', () => {
expectTypeOf<ConfirmMethod>().returns.resolves.toEqualTypeOf<CheckoutResult>();
expectTypeOf<StartMethod>().returns.resolves.toEqualTypeOf<CheckoutResult>();
expectTypeOf<ClearMethod>().returns.toBeVoid();
expectTypeOf<FinalizeMethod>().parameter(0).toEqualTypeOf<{ redirectUrl: string } | undefined>();
expectTypeOf<FinalizeMethod>().parameter(0).toEqualTypeOf<{ navigate?: SetActiveNavigate } | undefined>();
expectTypeOf<GetStateMethod>().returns.toEqualTypeOf<__experimental_CheckoutCacheState>();
});

Expand Down Expand Up @@ -245,7 +246,9 @@ describe('useCheckout type tests', () => {
expectTypeOf<CheckoutObject['confirm']>().toEqualTypeOf<__experimental_CheckoutInstance['confirm']>();
expectTypeOf<CheckoutObject['start']>().toEqualTypeOf<__experimental_CheckoutInstance['start']>();
expectTypeOf<CheckoutObject['clear']>().toEqualTypeOf<() => void>();
expectTypeOf<CheckoutObject['finalize']>().toEqualTypeOf<(params?: { redirectUrl: string }) => void>();
expectTypeOf<CheckoutObject['finalize']>().toEqualTypeOf<
(params?: { navigate?: SetActiveNavigate }) => void
>();
expectTypeOf<CheckoutObject['getState']>().toEqualTypeOf<() => __experimental_CheckoutCacheState>();
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/react/hooks/useCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
__experimental_CheckoutCacheState,
__experimental_CheckoutInstance,
CommerceCheckoutResource,
SetActiveNavigate,
} from '@clerk/types';
import { useMemo, useSyncExternalStore } from 'react';

Expand Down Expand Up @@ -57,7 +58,7 @@ type __experimental_UseCheckoutReturn = {
confirm: __experimental_CheckoutInstance['confirm'];
start: __experimental_CheckoutInstance['start'];
clear: () => void;
finalize: (params?: { redirectUrl: string }) => void;
finalize: (params?: { navigate?: SetActiveNavigate }) => void;
getState: () => __experimental_CheckoutCacheState;
isStarting: boolean;
isConfirming: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export type __experimental_CheckoutInstance = {
confirm: (params: ConfirmCheckoutParams) => Promise<CheckoutResult>;
start: () => Promise<CheckoutResult>;
clear: () => void;
finalize: (params?: { redirectUrl: string }) => Promise<void>;
finalize: (params?: { navigate?: SetActiveNavigate }) => Promise<void>;
subscribe: (listener: (state: __experimental_CheckoutCacheState) => void) => () => void;
getState: () => __experimental_CheckoutCacheState;
};
Expand Down
Loading