Skip to content

Commit ba572ee

Browse files
committed
fix: remove the need for the payerid from the client side
1 parent bb4f24b commit ba572ee

5 files changed

Lines changed: 10 additions & 33 deletions

File tree

packages/clerk-js/src/core/modules/billing/namespace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class Billing implements BillingNamespace {
151151

152152
getCreditBalance = async (params: GetCreditBalanceParams): Promise<BillingCreditBalanceResource> => {
153153
return await BaseResource._fetch({
154-
path: Billing.path(`/payers/${params.payerId}/credits`, { orgId: params.orgId }),
154+
path: Billing.path('/credits', { orgId: params.orgId }),
155155
method: 'GET',
156156
}).then(res => new BillingCreditBalance(res?.response as unknown as BillingCreditBalanceJSON));
157157
};
@@ -160,7 +160,7 @@ export class Billing implements BillingNamespace {
160160
params: GetCreditHistoryParams,
161161
): Promise<ClerkPaginatedResponse<BillingCreditLedgerResource>> => {
162162
return await BaseResource._fetch({
163-
path: Billing.path(`/payers/${params.payerId}/credits/history`, { orgId: params.orgId }),
163+
path: Billing.path('/credits/history', { orgId: params.orgId }),
164164
method: 'GET',
165165
}).then(res => {
166166
const { data, total_count } = res?.response as unknown as {

packages/shared/src/react/hooks/useCreditBalance.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const HOOK_NAME = 'useCreditBalance';
1717

1818
export type UseCreditBalanceParams = {
1919
for?: ForPayerType;
20-
payerId?: string;
2120
keepPreviousData?: boolean;
2221
enabled?: boolean;
2322
};
@@ -51,7 +50,6 @@ export function useCreditBalance(params?: UseCreditBalanceParams): CreditBalance
5150
}, [clerk]);
5251

5352
const keepPreviousData = params?.keepPreviousData ?? false;
54-
const payerId = params?.payerId;
5553

5654
const [queryClient] = useClerkQueryClient();
5755

@@ -65,15 +63,14 @@ export function useCreditBalance(params?: UseCreditBalanceParams): CreditBalance
6563
tracked: {
6664
userId: user?.id,
6765
orgId: safeOrgId,
68-
payerId,
6966
},
7067
untracked: {
71-
args: { payerId: payerId as string, orgId: safeOrgId },
68+
args: { orgId: safeOrgId },
7269
},
7370
});
74-
}, [user?.id, organization?.id, params?.for, payerId]);
71+
}, [user?.id, organization?.id, params?.for]);
7572

76-
const queriesEnabled = Boolean(user?.id && billingEnabled && payerId);
73+
const queriesEnabled = Boolean(user?.id && billingEnabled);
7774
useClearQueriesOnSignOut({
7875
isSignedOut: user === null,
7976
authenticated,

packages/shared/src/react/hooks/useCreditHistory.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const HOOK_NAME = 'useCreditHistory';
1616

1717
export type UseCreditHistoryParams = {
1818
for?: ForPayerType;
19-
payerId?: string;
2019
enabled?: boolean;
2120
};
2221

@@ -48,8 +47,6 @@ export function __internal_useCreditHistoryQuery(params?: UseCreditHistoryParams
4847
}
4948
}, [clerk]);
5049

51-
const payerId = params?.payerId;
52-
5350
const [queryClient] = useClerkQueryClient();
5451

5552
const { queryKey, invalidationKey, stableKey, authenticated } = useMemo(() => {
@@ -62,15 +59,14 @@ export function __internal_useCreditHistoryQuery(params?: UseCreditHistoryParams
6259
tracked: {
6360
userId: user?.id,
6461
orgId: safeOrgId,
65-
payerId,
6662
},
6763
untracked: {
68-
args: { payerId: payerId as string, orgId: safeOrgId },
64+
args: { orgId: safeOrgId },
6965
},
7066
});
71-
}, [user?.id, organization?.id, params?.for, payerId]);
67+
}, [user?.id, organization?.id, params?.for]);
7268

73-
const queriesEnabled = Boolean(user?.id && billingEnabled && payerId && (params?.enabled ?? true));
69+
const queriesEnabled = Boolean(user?.id && billingEnabled && (params?.enabled ?? true));
7470
useClearQueriesOnSignOut({
7571
isSignedOut: user === null,
7672
authenticated,

packages/shared/src/types/billing.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,6 @@ export type GetCreditBalanceParams = {
962962
* The ID of the Organization to get the credit balance for.
963963
*/
964964
orgId?: string;
965-
/**
966-
* The ID of the payer to get the credit balance for.
967-
*/
968-
payerId: string;
969965
};
970966

971967
/**
@@ -976,10 +972,6 @@ export type GetCreditHistoryParams = {
976972
* The ID of the Organization to get the credit history for.
977973
*/
978974
orgId?: string;
979-
/**
980-
* The ID of the payer to get the credit history for.
981-
*/
982-
payerId: string;
983975
};
984976

985977
/**

packages/ui/src/contexts/components/Plans.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,12 @@ export const usePlans = (params?: { mode: 'cache' }) => {
9797

9898
export const useCreditBalance = () => {
9999
const params = useBillingHookParams();
100-
const { data: subscription } = useSubscription();
101-
return __experimental_useCreditBalance({
102-
...params,
103-
payerId: subscription?.payerId,
104-
});
100+
return __experimental_useCreditBalance(params);
105101
};
106102

107103
export const useCreditHistory = () => {
108104
const params = useBillingHookParams();
109-
const { data: subscription } = useSubscription();
110-
return __internal_useCreditHistoryQuery({
111-
...params,
112-
payerId: subscription?.payerId,
113-
});
105+
return __internal_useCreditHistoryQuery(params);
114106
};
115107

116108
type HandleSelectPlanProps = {

0 commit comments

Comments
 (0)